Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Method init(botkit) in FacebookAdapter class and option disable_webserver #1916

Closed
@rfpaula

Description

@rfpaula

The init method from class FacebookAdapter on package botbuilder-adapter-facebook (version 1.0.8) of botkit package receives a Botkit object as parameter and this object can have a property called disable_webserver used for informe the Botkit constructor that the webserver do not be created during the instantiation process.

const adapter = new FacebookAdapter({
verify_token: process.env.FACEBOOK_VERIFY_TOKEN,
app_secret: process.env.FACEBOOK_APP_SECRET,
access_token: process.env.FACEBOOK_ACCESS_TOKEN
});
const controller = new Botkit({
    adapter: adapter,
    disable_webserver: true,
// other options
});

But when this object (Botkit) is sended to the init method from FacebookAdapter class this option is not considered and the init method try create a new get route to the default webhook. This action causes a error because is not possible call the get method from botkit.webserver, that is undefined.

public async init(botkit): Promise<any> {
    debug('Add GET webhook endpoint for verification at: ', botkit.getConfig('webhook_uri'));
    botkit.webserver.get(botkit.getConfig('webhook_uri'), (req, res) => {
        if (req.query['hub.mode'] === 'subscribe') {
            if (req.query['hub.verify_token'] === this.options.verify_token) {
                res.send(req.query['hub.challenge']);
            } else {
                res.send('OK');
            }
        }
    });
}

I am using this approach because I have an external web server used with Botkit in my project.

I beliave that this behavior may be modified if on the init method the disable_webserver config option was considered like the code bellow for example

    init(botkit) {
        return __awaiter(this, void 0, void 0, function* () {
            // This condition is the modification
            debug('disable_webserver: ', (botkit._config) ? botkit._config.disable_webserver: false);
            if (botkit._config && !botkit._config.disable_webserver) {
                debug('Add GET webhook endpoint for verification at: ', botkit.getConfig('webhook_uri'));
                botkit.webserver.get(botkit.getConfig('webhook_uri'), (req, res) => {
                    if (req.query['hub.mode'] === 'subscribe') {
                        if (req.query['hub.verify_token'] === this.options.verify_token) {
                            res.send(req.query['hub.challenge']);
                        }
                        else {
                            res.send('OK');
                        }
                    }
                });
            }
        });
    }

This code may be modified on facebook_adapter.js on lib directory and on facebook_adapter.ts on *src directory.

What was the result you received?

I received a error on init method from facebookAdapter class because the code try access the get method form botkit.webserver and this parameter is undefined

What did you expect?

I expected that the botkit constructor was well initialized with the parameters adapter: facebookAdapter and disable_webserver: true, but i received a error when the init method of the facebookAdapter class was excecuted because the webserver associated with the botkit instances was undefined, as requested by disable_webserver parameter

Context:

  • botbuilder-adapter-facebook version: 1.0.8
  • Botkit version: 4.5.0
  • Messaging Platform: Facebook
  • Node version: 10.15.2
  • Os: Ubuntu Linux 18.04
  • Any other relevant information:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions