当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript UniversalBot.on方法代码示例

本文整理汇总了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)
开发者ID:duncanmak,项目名称:mr-robot,代码行数:31,代码来源:app.ts

示例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)) {
开发者ID:LucasChies,项目名称:Medication-Helper-idtpoa,代码行数:30,代码来源:app.ts


注:本文中的botbuilder.UniversalBot.on方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。