一个机器人支持数千个Facebook页面

我喜欢bot框架,但是我想要扩展以支持数百个Facebook页面(如果没有的话)都指向我的单个bot实例。 我的机器人实例通过传入的页面ID来区分function,或者我猜是通过MSFT App / Secret ID。

框架似乎要求MSFT托pipe的逻辑bot与FB页面之间的1:1对应关系,但是我的单个bot实例可以处理数千个这样的页面和应用程序。

看起来我可能需要为每个逻辑bot页面创build一个独特的ChatConnector和相关的UniversalBot实例。 这在我所build议的范围内是非常低效的。

解决这个问题的方法之一可能是扩展UniversalBot来接受我创build的所有MSFT App和Secret ID的列表,但是我还没有尝试过。 在审查了API之后,看起来像使用一个UniversalBot实例注册更多的连接器是可能的。

UniversalBot: /** * Registers or returns a connector for a specific channel. * @param channelId Unique ID of the channel. Use a channelId of '*' to reference the default connector. * @param connector (Optional) connector to register. If ommited the connector for __channelId__ will be returned. */ connector(channelId: string, connector?: IConnector): IConnector; 

但不知道我通过channelId,除非这是一个任意的唯一本地值。

我在这里回顾了其他/类似的post,但没有find任何我相信解决我的问题。 如果我错了,我表示歉意,并希望参考。

我希望有人可以有一个更好的主意。 我使用节点btw。 谢谢。

采取从这里:

创build一个单一的Bot服务来支持多个Bot应用程序

 var express = require('express'); var builder = require('botbuilder'); var port = process.env.PORT || 3978; var app = express(); // a list of client ids, with their corresponding // appids and passwords from the bot developer portal. // get this from the configuration, a remote API, etc. 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()); }); // this is where you implement all of your dialogs // and add them on the bot instance function bindDialogsToBot (bot, cid) { bot.dialog('/', [ session => { session.send(`Hello... I'm a bot for customer id: '${cid}'`); } ]); } // start listening for incoming requests app.listen(port, () => { console.log(`listening on port ${port}`); }); 

我们正在创build不同的僵尸工具和连接器实例,为每个客户捕获App ID和密码,并将其绑定到由Bot Framework用作Messaging Endpoint的相应REST API。

当我们创buildbot实例时,我们调用bindDialogsToBot方法,传递bot实例和客户ID。 通过这样做,我们在封闭中捕获客户ID,使其可以访问内部对话框。

当调用其中一个REST API时,将使用相关的bot实例,对话框的内部逻辑可以利用正确的客户ID来处理请求(例如,检索客户的configuration/规则并采取行动他们)。