本文整理汇总了TypeScript中botbuilder.UniversalBot.on方法的典型用法代码示例。如果您正苦于以下问题:TypeScript UniversalBot.on方法的具体用法?TypeScript UniversalBot.on怎么用?TypeScript UniversalBot.on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类botbuilder.UniversalBot
的用法示例。
在下文中一共展示了UniversalBot.on方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createServer
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')
]);
intents.onDefault([
(session, args, next) => {
if (!session.userData.address)
示例2:
// <<< --- ADD YOUR LIBRARIES HERE --- >>>
bot.library(locationDialog.createLibrary(process.env.BING_MAPS_API_KEY));
bot.library(greetings.createLibrary());
bot.library(medication.createLibrary());
bot.library(medicationprompt.createLibrary());
bot.library(countryprompt.createLibrary());
bot.library(places.createLibrary());
bot.library(imagedetection.createLibrary());
// Conversation Update - Send greetings to user when joining the conversation
bot.on('conversationUpdate', (message: IConversationUpdate) => {
if (message.membersAdded) {
message.membersAdded.forEach((identity: IIdentity) => {
if (identity.id !== message.address.bot.id) {
bot.beginDialog(message.address, "greetings:start");
}
});
}
});
// Adding natural language support (Language Understanding)
const luis = process.env.COGNITIVE_LUIS_URL || '';
let luisRecognizer = new builder.LuisRecognizer(luis);
bot.recognizer(luisRecognizer);
bot.recognizer({
recognize: (context: builder.IRecognizeContext, done: (err: any, result: builder.IIntentRecognizerResult) => void) => {
let intent: builder.IIntentRecognizerResult = { score: 0.0, intent: 'None' };
if (attachment.hasImageAttachment(context.message)) {