【发布时间】:2016-09-13 15:22:23
【问题描述】:
我想用 http 请求触发我的机器人(例如输入http://localhost:3978/api/messages/http),所以在触发它之后,它会向每个连接到这个机器人的用户发送一些消息。 我看过这个话题:How to send message later in bot framework? 这就是我目前所拥有的:
var restify = require('restify');
var builder = require('botbuilder');
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
server.post('/api/messages', connector.listen());
var bot = new builder.UniversalBot(connector);
bot.dialog('/',function (session) {
var reply = session.message; // address: reply.address
reply.text = 'Wake up!'
console.log(reply.text);
bot.send(reply);
});
// Create response function
function respond(req, res, next) {
res.send('hello ' + req.params.name);
bot.send(reply);
next();
}
server.get('/api/messages/:name', respond);
不幸的是,当我访问我的http://localhost:3978/api/messages/http 时,它没有发送任何消息。我也试过用
connector.send('message');
但它总是通过我“错误:ChatConnector:发送 - 消息缺少地址或 serviceUrl。”
更新: 我已经宣布了一个全局变量用于回复
var globalreply;
bot.dialog('/',function (session) {
globalreply = session.message; // address: reply.address
globalreply.text = 'Wake up!'
console.log(globalreply.text);
bot.send(globalreply);
});
// Create response function
function respond(req, res, next) {
res.send('hello ' + req.params.name);
bot.beginDialog;
bot.send(globalreply);
next();
}
但现在它通过我一个错误: TypeError:无法读取未定义的属性“对话”。 在我的 bot.send(globalreply); 行。 期待您的帮助。
最好的问候。
【问题讨论】:
标签: javascript node.js botframework