Botkit: [Facebook Adapter] Error in Url Verification for BotFramework bots

Created on 7 Jan 2020  路  2Comments  路  Source: howdyai/botkit

Describe the bug

BotFramework TestBot with Facebook Adapter is not validating the Callback Url. We are experiencing an [ERR_INVALID_ARG_TYPE] exception.

_Note: Same that #1817 automatically closed due to lack of activity._

To Reproduce

Steps to reproduce the behavior:

  1. Go to packages -> TestBot.
  2. In botframework.js uncomment the lines to connect the bot with Facebook and provide a verify_token, an app_secret, and an access_token.
    image
  3. Add a get method to handle the request for URL validation:
    image
  4. Install and build the project. Run the bot.
  5. In a Facebook Developer Account create a new app and add a Messenger product.
    image
  6. Expose the bot's endpoint using ngrok
  7. Go back to the Facebook App and in the Webhook Section of the Messenger Product, click on _Subscribe to Events_ button
    image
  8. Complete the Callback URL with the ngrok URL adding '_/api/messages_', fill in the Verify Token and click _Verify and Save_ button.
    image

Expected behavior

The URL should get verified.

Proposed Solution

In facebook_adapter.ts, in processActivity method, add the following code:

        var url = req.url;
        var params = url.split('?');
        var urlParams =  new URLSearchParams(params[1]);

        if (urlParams.get('hub.mode') === 'subscribe') {
            var verify_token = urlParams.get('hub.verify_token');
            if (verify_token === this.options.verify_token) {
                var challenge = urlParams.get('hub.challenge');
                res.status = 200;
                res.sendRaw(challenge);      
            } else {
                res.status = 401;
                throw new Error('Webhook not validated');      
            }
        } else {    
            if (await this.verifySignature(req, res) === true) {
                         ...

[bug]

Most helpful comment

This has been added to the sample code in the README, but I do not plan on adding it directly to the adapter.

All 2 comments

I'd like to help with this

This has been added to the sample code in the README, but I do not plan on adding it directly to the adapter.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abinashmohanty picture abinashmohanty  路  4Comments

dfischer picture dfischer  路  4Comments

fieldcorbett picture fieldcorbett  路  4Comments

TheJimFactor picture TheJimFactor  路  4Comments

HannanShaik picture HannanShaik  路  3Comments