首页 文章

bot框架按用户地址发送主动消息

提问于
浏览
5

我正在使用Microsoft Bot Framework,Webchat Channels ,NodeJS

还使用Bot-Trees来管理我的对话 .

如何主动向用户发送消息?我在我的数据库中保存了用户地址,其中包括用户ID,机器人ID,会话ID等 .

我已经尝试了this solution,将最后一个用户's address I saved, the request went well without any errors but the messages didn' t发送到客户端(网络聊天) .

有什么建议?

谢谢

主动消息路由,bot-trees项目:

var connector = new builder.ChatConnector({
  appId: client.id,
  appPassword: client.password,
  });

  var bot = new builder.UniversalBot(connector);

  app.post(`/proactiveTest`, (req, res, next) => {
if (!req.query.addressId ||!req.query.userId || !req.query.convId || !req.query.botId){
  res.send("Missing params")
}

let channelId = 'webchat';
let id = req.query.addressId;
var user = {id : req.query.userId, name : req.query.userName};
let conversation = {id : req.query.convId};
let botDetails = {id : req.query.botId , name : req.query.botName};
let serviceUrl = "https://directline.botframework.com/";
let address = {id, channelId, user, conversation, botDetails, serviceUrl};

var msg = new builder.Message().address(address);
msg.text("This is a test");
msg.textLocale('en-US');
bot.send(msg);

res.send("Message sent");
 });

2 回答

  • -1

    请尝试更改此行:

    let address = {id, channelId, user, conversation, botDetails, serviceUrl};
    

    对此:

    let address = {id, channelId, user, conversation, bot: botDetails, serviceUrl};
    

    此外,您将 Channels 设置为网络聊天,但使用https://directline.botframework.com/作为服务网址 .

  • 0

    请转到您的机器人服务并查找 Channels 选项卡,在那里您将看到您的聊天机器人打开 Channels ,检查靠近网络聊天行的“问题”链接 .

相关问题