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

What is the right syntax for calling async functions? #81

Open
master0v opened this issue Aug 28, 2021 · 1 comment
Open

What is the right syntax for calling async functions? #81

master0v opened this issue Aug 28, 2021 · 1 comment

Comments

@master0v
Copy link

Would you like assistance or advice?
assistance

Issue description
in the example below, trying to call an async function from within "def message(self, message):"

Steps to reproduce
insert "await inside the "def message(self, message):" where is a function defined as async

Traceback or other info

  • fbmessenger version: latest
  • python version: 3.7.3
  • Facebook Messenger API version: 11.0
@master0v
Copy link
Author

master0v commented Aug 28, 2021

I followed the advice given here: https://stackoverflow.com/questions/31866796/making-an-asynchronous-task-in-flask

Basically I had to change the Flask harness like so:

@app.route('/webhook', methods=['GET', 'POST'])
**async** def webhook():
  if request.method == 'GET':
    logger.debug(f"checking that {request.args.get('hub.verify_token')} == {configuration.cfg['FB_VERIFY_TOKEN']}")
    if (request.args.get('hub.verify_token') == configuration.cfg['FB_VERIFY_TOKEN']):
      return request.args.get('hub.challenge')
    raise ValueError('FB_VERIFY_TOKEN does not match.')
  elif request.method == 'POST':
    **await** messenger.handle(request.get_json(force=True))
  return ''

as well as install pip3 install asgiref

is this correct?

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

No branches or pull requests

1 participant