使用Microsoft Bot Framework制作机器人。我无法发送和介绍消息

时间:2016-05-06 20:22:27

标签: emulation bots

目前大部分代码都来自这里的介绍性教程:http://docs.botframework.com/builder/node/guides/core-concepts/#navtitle。我正在使用Microsoft Bot框架模拟器来运行我的机器人。

将机器人添加到模拟器后,我必须输入" hi"启动机器人。理想情况下,我想要的是弹出欢迎信息,提示用户打个招呼。这是我的代码:

var restify = require('restify');
var builder = require('botbuilder');

//create a bot
var bot = new builder.BotConnectorBot({appId: "YourAppID", appSecret: "YourAppSecret", groupWelcomeMessage: "Welcome! Say hi!", userWelcomeMessage: "welcome new user! Say hi"});

bot.add('/', new builder.CommandDialog()

    .matches("^set name", builder.DialogAction.beginDialog("/setname"))
    .matches("^quit", builder.DialogAction.endDialog())
    .onDefault(function (session) {

        if (!session.userData.name) {

            session.beginDialog("/profile");
        } else {

            session.send("Hello %s!", session.userData.name);
        }
    }
));

bot.add("/profile", [

    function (session) {

        builder.Prompts.text(session, "Hi! What is your name?");
    },

    function (session, results) {

        session.userData.name = results.response;
        session.beginDialog("/");
    }
]);

bot.add("/setname", [

    function (session) {

        builder.Prompts.text(session, "What would you like your name changed to?");
    },

    function (session, results) {

        session.userData.name = results.response;
        session.send("your name has been changed to %s", session.userData.name);
        session.endDialog()
    }
]);


//setup the restify server
var server = restify.createServer();
server.post('api/messages', bot.verifyBotFramework(), bot.listen());
server.listen(process.env.port || 3978, function () {

    console.log('%s listening to %s', server.name, server.url);
})

正如您在创建机器人时所看到的,我设置了groupWelcomeMessage和userWelcomeMessage参数。不幸的是,这些消息都没有显示出来。谢谢你的帮助。

0 个答案:

没有答案