not good but great

プログラミング、アート、映画・本の感想について書きます。

ChaliceでMessenger Botを作るときWebhookの設定

chaliceawsを簡単に扱うためのフレームワーク

Webhookの設定

post

@app.route('/webhook', methods=['GET'])
def validate():
    query_params = app.current_request.query_params
    if query_params['hub.mode'] == 'subscribe' and query_params['hub.verify_token'] == verify_token:

        print("Validating webhook")

        return query_params['hub.challenge']
    else:
        return 'Failed validation. Make sure the validation tokens match.'

get

@app.route('/webhook', methods=['POST'])
def webhook():
    payload = app.current_request.raw_body
    page.handle_webhook(payload)

    return "ok"

facebookアプリの管理ページに「Messengerユーザーから送信されたメッセージやその他のイベントを受信するには、アプリでWebhooks統合を有効にしてください。」と書いてあるのだけど、この「Webhooks統合」というのがpostにあたるのかな。