本文整理汇总了TypeScript中botbuilder.ChatConnector类的典型用法代码示例。如果您正苦于以下问题:TypeScript ChatConnector类的具体用法?TypeScript ChatConnector怎么用?TypeScript ChatConnector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChatConnector类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createServer
import { createServer } from 'restify';
import { ChatConnector, IEvent, IntentDialog, Message, Prompts, UniversalBot } from 'botbuilder';
const server = createServer();
server.listen(process.env.PORT || 3978, () => console.log('%s listening to %s', server.name, server.url));
let connector = new ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
let bot = new UniversalBot(connector);
server.post('/api/messages', connector.listen());
bot.on('installationUpdate', (activity: IEvent) => {
let token = activity.sourceEvent.token;
let message = new Message()
.address(activity.address)
.text(token);
bot.send(message);
});
let intents = new IntentDialog();
bot.dialog('/', intents);
intents.matches(/^hello/, [
(session) => session.beginDialog('/hello')
]);
示例2: function
bot.setup().then(() => {
// Listen to activities sent to the bot
const server = restify.createServer();
server.use(restify.plugins.queryParser());
server.listen(process.env.port || process.env.PORT || 3977, function () {
console.log('%s listening to %s', server.name, server.url);
});
server.post('/api/messages', connector.listen());
});
示例3: switch
connector.onInvoke((invoke, callback) => {
let storageCtx = {
address: invoke.relatesTo,
persistConversationData: true,
conversationId: invoke.relatesTo.conversation.id
};
connector.getData(storageCtx, (err, data) => {
switch (invoke.name) {
case 'payments/update/shippingAddress':
case 'payments/update/shippingOption':
console.log("updatedshipping info");
callback(null, {}, 200);
break;
case 'payments/complete':
console.log("completed payment request");
callback(null, {result: "success"}, 200);
bot.beginDialog(invoke.relatesTo, 'checkout_receipt');
break;
}
});
});