本文整理汇总了TypeScript中botbuilder.UniversalBot类的典型用法代码示例。如果您正苦于以下问题:TypeScript UniversalBot类的具体用法?TypeScript UniversalBot怎么用?TypeScript UniversalBot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UniversalBot类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: require
var restify = require('restify');
var builder = require('botbuilder');
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function() {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
//
// Main methods
//
function getCounter(session): string {
if (!session.dialogData.hasOwnProperty('counter')) {
session.dialogData.counter = 0;
}
session.dialogData.counter++;
return `Message #${session.dialogData.counter}`;
}
//
// Bots Dialogs
示例3: Message
bot.on('installationUpdate', (activity: IEvent) => {
let token = activity.sourceEvent.token;
let message = new Message()
.address(activity.address)
.text(token);
bot.send(message);
});
示例4: switch
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;
}
});
示例5:
message.membersAdded.forEach((identity: IIdentity) => {
if (identity.id !== message.address.bot.id) {
bot.beginDialog(message.address, "greetings:start");
}
});