Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rfpaula opened this issue Feb 18, 2020 · 2 comments
Closed
Assignees
Milestone

Comments

@rfpaula
Copy link

rfpaula commented Feb 18, 2020

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:
@benbrown
Copy link
Contributor

This is a bug, thank you for reporting it.

@benbrown benbrown added this to the 4.6.+ milestone Mar 11, 2020
@benbrown
Copy link
Contributor

this will be in the next release -> #1929

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants