我们可以在Microsoft bot框架中拥有多个控制器吗?

时间:2017-07-02 09:53:45

标签: bots botframework

如果是,我们将如何管理端点? 如果不是,如何使用同一个控制器处理多个对话?

2 个答案:

答案 0 :(得分:0)

如果您想使用多个对话框,建议您查看this postthis repo中还有一个示例。完全可以使用多个对话框。

答案 1 :(得分:0)

是的,您可以使用单个Web服务实例控制多个具有多个流的机器人。

但是,您需要为每个帐户创建不同的Bot Framework帐户,并在您的webhook中使用动态网址。

webhook示例:

https://my-bot-controller-service.com/api/CUSTOMER_ID/messages

来自不同僵尸程序连接器的所有请求都会遇到同一个实例,您可以使用此CUSTOMER_ID参数区分它来自哪个僵尸程序。

要将不同的对话框绑定到不同的机器人,您可以创建多个builder.ChatConnector实例:

var customersBots = [
  { cid: 'cid1', appid: '', passwd: '' }, 
  { cid: 'cid2', appid: '', passwd: '' }, 
  { cid: 'cid3', appid: '', passwd: '' }, 
];

// expose a designated Messaging Endpoint for each of the customers
customersBots.forEach(cust => {

  // create a connector and bot instances for 
  // this customer using its appId and password
  var connector = new builder.ChatConnector({
    appId: cust.appid,
    appPassword: cust.passwd
  });
  var bot = new builder.UniversalBot(connector);

  // bing bot dialogs for each customer bot instance
  bindDialogsToBot(bot, cust.cid);

  // bind connector for each customer on it's dedicated Messaging Endpoint.
  // bot framework entry should use the customer id as part of the
  // endpoint url to map to the right bot instance
  app.post(`/api/${cust.cid}/messages`, connector.listen());

});

此代码块取自官方开发者博客,您应该阅读它以获取更多详细信息:

https://www.microsoft.com/developerblog/2017/01/10/creating-a-single-bot-service-to-support-multiple-bot-applications/

作为最后一点,我应该告诉您,如果您的目标是在不重新启动实例的情况下配置机器人(例如,基于Web的平台来配置聊天机器人流程),您应该实施刷新机制。

有关这种机制的信息可以在这里找到:

https://www.microsoft.com/developerblog/2016/12/12/integrating-an-existing-bot-platform-with-microsofts-bot-framework/