bot.beginDialog到特定用户和频道

时间:2016-06-22 18:34:43

标签: node.js botframework botbuilder

我希望我的机器人在将来的某个时刻与其他用户发起新的对话。我试图从对话本身开始,而不是像Bot Connector Node.js文档中那样由传入的POST消息启动。

不太清楚Node的推荐方法是哪一个: 使用require('botconnector')ConnectorClient()或Bot Connector REST API。

但是,根据run-asyncLUIS示例,我注意到beginDialog实际上允许您指定预期地址:bot.beginDialog(address, '/run-async/runner', { name: name });cortanaBot.beginDialog({ from: alarm.from, to: alarm.to }, '/notify', alarm);

我认为这是非常直接和更清晰的方法,然而,当我包含这样的参数时,机器人只是停止响应(如果我只使用session.beginDialog('/myalarm', { alarm: "some alarm" });,它就可以工作)。我错过了什么吗?

require('dotenv').config();
var restify = require('restify');
var builder = require('botbuilder');

// Get secrets from server environment
var botConnectorOptions = {
    appId: process.env.BOTFRAMEWORK_APPID,
    appSecret: process.env.BOTFRAMEWORK_APPSECRET
};

// Create bot
var bot = new builder.BotConnectorBot(botConnectorOptions);


function addressConverter(message) {
    return {
        to: message.from,
        from: message.to//,
        // conversationId: message.conversationId,
        // channelConversationId: message.channelConversationId,
        // channelMessageId: message.channelMessageId
    };
}


bot.add('/myalarm', function(session) {
    session.send('My Automatic Message');
    session.endDialog();
});


bot.add('/', function(session) {
    session.send('Hi');
    // Delay sending the reply for 5 seconds
    setTimeout(function() {
        session.send({ text: '5s Time out!' })
        var address = addressConverter(session.message);
        console.log("Message Address:")
        console.log(address)
        session.beginDialog(address, '/myalarm', { alarm: "some alarm" });
    }, 5000);
    session.send({ text: 'I will automatically message you in 5 seconds.' })
});

// Setup Restify Server
var server = restify.createServer();
//server.pre(restify.pre.pause());

// Handle Bot Framework messages
server.post('/api/messages', bot.verifyBotFramework(), bot.listen());

// Serve a static web page
server.get(/.*/, restify.serveStatic({
    'directory': '.',
    'default': 'index.html'
}));

server.listen(process.env.port || 3978, function() {
    console.log('%s listening to %s', server.name, server.url);
})

0 个答案:

没有答案