In Bot Framework Portal left menu (How-To guides -> Connect to channels), there is a specific section related to the connection of a bot to a channel and, after Microsoft ones (e.g. Bing, Cortana, Skype for Business, Direct Line, Microsoft Teams, Skype, We Chat, Email, GroupMe) there are even third party channels (e.g. Facebook, Kik, Slack, Telegram, Twilio).
In the following I will give some details on the my experience in connecting an example bot of mine (i.e. testEnzoA) to the Facebook Messenger channel. The Connect a bot to Facebook Messenger page, available in the Bot Framework portal, explains the main steps how to do most of the work but in the following I’ll add some screenshots and personal considerations that could be useful when following those instructions!
In particular, the example bot that I will connect to Facebook Messenger, is called testEnzoA and simply reply to any message with “Hai detto: the same phrase”:
In the following there are the main steps to make the things work … 😉
Create a new Page in your Facebook and get that Page ID from its About section. Possibly it is the first time (as it was for me) that you create a new Page attached to your Facebook account, so in the following you can find some screenshots I took for your convenience 😉
After you create your new Facebook Page, you can always easily navigate to it from the left menu that have a specific Pages section (e.g. where the new just created Test1 page can be found).
Create a new Facebook App on that Page and generate an App ID and App Secret for it. To create a Facebook App you must navigate into the Facebook developer site: you can click on the Skip and Create App ID button (in the upper right of that page) and set the proper Display Name and Contact Email.
Also in the See your app page, it is shown the App ID, but only clicking on the proper app icon you can access the Dashboard, related to that app, where you can manage it and set further options.
Clicking on the newly created Facebook app (i.e. Test1App), you can get not only its App ID but also its App Secret (visible only clicking on the Show button and providing your Facebook password).
Going into the Settings -> Advanced section, set the “Allow API Access to App Settings” to Yes.
Then enable Facebook Messenger in the new Facebook App going into the Products section and then clicking the Set Up button related to the Messenger product.
Generate a Page Access Token for the Facebook Page previously generated (i.e. Test1 Page)
Note that, as written in the Token Generation box:”Page token is required to start using the APIs. This page token will have all messenger permissions even if your app is not approved to use them yet, though in this case you will be able to message only app admins. You can also generate page tokens for the pages you don’t own using Facebook Login“.
I found quite strange that after the token generation you have to suddenly copy it to paste in the bot framework page related to the bot you want to connect with Facebook Messenger, because this token value will then not be available any more once you exit that Facebook page … and if you select again the same page, a new token is generated with a different value (???) …
Click on the Setup Webhooks button to forward messaging events from Facebook Messenger to the bot. Note that after that setup , that Setup Webhooks button (available in the Webhooks section) will change to Edit Event and it will allow you only to change the Page Subscription Fields.
Going to the Bot Framework Portal, in the section related to the bot you want to connect (e.g. testEnzoA), click on the CHANNELS section (top right menu) to connect that bot to the Facebook Messenger channel.
Now, going to the Facebook developer site, set those Callback URL and Verify Token values from the Bot Framework portal (always available in the CHANNELS section of that bot): note that after clicking the Verify and Save button you will be allowed only to change the Subscription Fields and it are not available anymore the Callback URL and Verify Token sections (???).
Get the Page ID, App ID / App Secret and Page Access Token values copied from Facebook sites previously and past them in the Bot Framework Portal page for configuring Facebook Messenger.
The Configure Facebook Messenger page can be reached from the CHANNELS section of the bot, clicking on the Edit link in the line related to the Facebook Messenger channel.
In the Facebook App you can also set the more appropriate category (i.e. App for Messenger).
It is written that, until an app is published, it is in Development Mode and Plugin and API functionality will only work for admins, developers, and testers.
As you can see in the following screenshot, writing to Test1 (that is the name of the Facebook Page I created for the test) from the Messenger site, the bot testEnzoA automatically answers “Hai detto: same string” as expected 😉
Obviously the bot works even using the Messenger app, even from your smartphone:
Before doing this review, I supposed that when I should write a post in my Test1 Facebook Page I should have had an automatic answer from the bot … but it is not what it happens … Only writing with the Messenger chat to a virtual user called as that Facebook Page (i.e. Test1) you have the bot give the proper answer following it proper logic.
Therefore, the bot is attached only to Messenger and it answers only when someone writes to a virtual contact, that has the same name of the Facebook Page, using the Messenger chat available from the Messenger web site or an app on PC/smartphone (Microsoft Store; Google Store; Apple Store).
More or less the procedure is the same for the other third party possible Channels (e.g. Slack) even though you have to register a “page” in a different environment and set the proper tokens and URL on the appropriate site (i.e. third party developer site and Bot Framework site configure the proper channel for that bot).
For connecting your Bot to Microsoft’s specific channels is even easier because you do not need to create/add specific tokens. For example, to add the Cortana Channel see this following post.