问题
I am learning how to make messenger bots. I have code to listen for 'what is the meaning of life' and then give 2 quick response's '42' and 'chocolate' the payload for 42 is 'the real one' the payload for chocolate is 'the fake one' in where I check postbacks I check for that payload, it does not work. I understand that I am missing something because the button does not operate as a postback so how do I make it do something on that button. The code is here: https://gomix.com/#!/project/fb-messenger-bot
In the chatbot sending 'generic' sends a message back to you with a website and two buttons when you say what is the meaning of life it has the 2 quick responses anything else is echoed at you.
回答1:
When a quick reply button is tapped, it will not trigger a postback. Instead a callback will be received with a different response format than that of postback. The event will have a message attribute which will be similar to your quick reply button type with a quick_reply key which contains the payload of the button.
{
"sender": {
"id": "USER_ID"
},
"recipient": {
"id": "PAGE_ID"
},
"timestamp": 1464990849275,
"message": {
"mid": "mid.1464990849238:b9a22a2bcb1de31773",
"seq": 69,
"text": "Red",
"quick_reply": {
"payload": "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_RED"
}
}
}
So, you can access the quick reply payload using
event.message.quick_reply.payload
来源:https://stackoverflow.com/questions/42672531/messenger-quick-response-does-not-trigger-postbak