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

How To handle postback request in chatbot #121

Closed
sajalkatare opened this issue Jan 4, 2019 · 0 comments
Closed

How To handle postback request in chatbot #121

sajalkatare opened this issue Jan 4, 2019 · 0 comments

Comments

@sajalkatare
Copy link

Hi I have created a chatbot with pymessenger, flask, wit.ai. I have added some button but I dont know how to reply back once user press/select the option from my menu. Below is my code.

`@app.route('/', methods=['GET'])

def verify():
    if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
        if not request.args.get("hub.verify_token") == "hello":
            return "Verification token mismatch", 403
        return request.args["hub.challenge"], 200
    return "Hello World", 200

@app.route('/', methods=['POST'])
def webhook():
    data = request.get_json()
    log(data)

    if data['object'] == 'page':
        for entry in data['entry']:
            for messaging_event in entry['messaging']:

                sender_id = messaging_event['sender']['id']
                recipient_id = messaging_event['recipient']['id']

                if messaging_event.get('message'):
                    if 'text' in messaging_event['message']:
                        messaging_text = messaging_event['message']['text']
                    else:
                        messaging_text = 'no text'

                    response = None

                    entity, value = wit_response(messaging_text)


						if entity == 'cust_id':
                        test = cust(str(value))
                        buttons = []
                        button = Button(title='1. Pizza', type='postback', payload='Pizza')
                        buttons.append(button)
                        button = Button(title='2. Burger', type='postback', payload='Burger')
                        buttons.append(button)
                        button = Button(title='3. Pasta', type='postback', payload='Pasta')
                        buttons.append(button)
                        text = 'Hey '+test[0] +'👋.'+"\n"+'Select Option:'
                        bot.send_button_message(sender_id, text, buttons)`

I Dont know after user chhoose one option how to handle request. For example if user select Pizza, I want to give pizza menu in text or button format.

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