One bot to support thousands of Facebook pages

I like the bot frame, but I want to scale it to support hundreds, not thousands of Facebook pages, all pointing to my only bot instance. My bot instance differentiates functionality with an inbound page identifier, or I think MSFT App / Secret IDs.

The structure seems to require a 1: 1 correspondence between the logical bot hosted by MSFT and the FB page, but my only bot instance can handle thousands of such pages and applications.

It looks like I might need to create a unique ChatConnector and a corresponding UniversalBot instance for each logical bot page. This is terribly inefficient on the scale that I propose.

One way to solve this problem is to extend UniversalBot to accept a list of all the MSTP applications and secret identifiers that I create, but I have not tried this yet. Looking at the API, it seems that it is possible to register more connectors with one instance of 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; 

But not sure what I pass for channelId if this is not an arbitrary unique local value.

I looked at other / similar posts here, but did not find anything that, in my opinion, concerns my problem. If I am wrong, I apologize and appreciate the link.

I hope someone might have a better idea. I am using Node btw. Thanks.

+7
botframework
source share
1 answer

Taken from here:

Create a single bot service to support multiple bot applications

 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 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}`); }); 

We create different instances of the bot and connector that capture the identifier and password for each client and bind it to the corresponding REST API, which is used by the Bot platform as the messaging endpoint.

When we create the bot instance, we call the bindDialogsToBot method, passing the bot instance and client ID. By doing this, we fix the client identifier in its closure, making it available for internal dialogs.

When calling one of the REST-API, the corresponding bot instance is used, and the correct client identifier can be used by the internal logic of the dialog boxes to process the request (for example, to obtain the clientโ€™s configuration / rules and act on them).

+1
source share

All Articles