I have 3 postbacks that should execute the same set of instruction with a slight difference which is the question to ask the user. So I created a function to respond to those postback, here is the function :
//Params : question to ask the user, bot, message from the postback event.
function respondMessage(question,bot,message) {
bot.startConversation(message, function (error, convo) {
convo.ask(question, function (response, convo) {
//Checking if the user type something
if (response.text == "") {
console.log("its working");
convo.repeat();
convo.next();
}
else {
//My function
newsCreator("WHAT", response.user, response.text);
convo.say(
{
"attachment":{
"type": "template",
"payload": {
"template_type": "button",
"text": "Should I send to you :",
"buttons":
[
{
"type": "postback",
"title": "Football News",
"payload": "FOOTBALL"
},
{
"type": "postback",
"title": "Basket Ball News",
"payload": "BASKET"
},
{
"type": "postback",
"title": "Volley Ball News",
"payload": "VOLLEY"
}]
}
}
});
convo.next();
//End of the conversation
}
});
convo.next();
});
}
Here is the postback hanlder:
controller.on('facebook_postback', function (bot, message) {
switch (message.payload) {
case "COACH":
respondMessage("Which Coach?",bot,message);
case "TEAM":
respondMessage("How many Team?",bot,message);
case "PLAYER":
respondMessage("Players of which country?",bot,message);
default:
}
});
The question are being asked, but not even a message_received or postback event is being trigger in the bot when the user has typed and send his response to the question. The convo ask call back function is not being executed.
Hi,
I'm having a similar issue using patterns, and noticed that while the buttons are not firing the callback, manually typing in the payload works just fine.
Here is my code, I hope this helps to debug the issue :smile: .
// Start Onboarding
convo.addQuestion({
attachment: {
'type': 'template',
'payload': {
'template_type': 'button',
'text': 'my question',
'buttons': [
{
'type': 'postback',
'title': '1',
'payload': '1'
},
{
'type': 'postback',
'title': '2',
'payload': '2'
}
]
}
}
}, [
{
pattern: 'onboard_user',
callback: (res, convo) => {
console.log(res)
convo.next()
}
},
{
pattern: 'explain_features',
callback: (res, convo) => {
console.log(res)
convo.next()
}
},
{
default: true,
callback: (res, convo) => {
convo.repeat()
convo.next()
}
}
])
Maybe this could help you, are you enable messages_postback permissions on fb?
https://github.com/hyperoslo/facebook-messenger/issues/15#issuecomment-216933326
Hey @azanoni, thanks for the info. Yeah, the postback hook is enabled.
This is the response the webhook is getting back from those buttons.
{ object: 'page',
entry:
[ { id: '115975565622062',
time: 1493878495832,
messaging:
[ { recipient: { id: '115975565622062' },
timestamp: 1493878495832,
sender: { id: '1310044285740325' },
postback: { payload: 'test_payload' } } ] } ] }
127.0.0.1 - - [04/May/2017:06:14:56 +0000] "POST /facebook/receive HTTP/1.1" 200 2 "-" "-"
```
while this is what happen if I send back the payload as a simple message
{ object: 'page',
entry:
[ { id: '115975565622062',
time: 1493878652552,
messaging:
[ { sender: { id: '1310044285740325' },
recipient: { id: '115975565622062' },
timestamp: 1493878652181,
message:
{ mid: 'mid.$cAABpeoGieZ5iA2CFFVb0hs8Zj1sG',
seq: 33257,
text: 'test_payload' } } ] } ] }
debug: RECEIVED MESSAGE
debug: CUSTOM FIND CONVO 1310044285740325 1310044285740325
debug: FOUND EXISTING CONVO!
debug: HANDLING MESSAGE IN CONVO { text: 'test_payload',
user: '1310044285740325',
channel: '1310044285740325',
page: '115975565622062',
timestamp: 1493878652181,
seq: 33257,
is_echo: undefined,
mid: 'mid.$cAABpeoGieZ5iA2CFFVb0hs8Zj1sG',
sticker_id: undefined,
attachments: undefined,
quick_reply: undefined,
type: 'user_message' }
127.0.0.1 - - [04/May/2017:06:17:33 +0000] "POST /facebook/receive HTTP/1.1" 200 2 "-" "-"
debug: Conversation is over with status completed
info: > [End] 0 Conversation with 1310044285740325 in 1310044285740325
info: [End] 0 Task for 1310044285740325 in 1310044285740325
```
I have an hunch that Botkit is not using the postback to continue the conversation.
Oh ok, I figured this out to enable postback in the convo all that is needed is to pass in {receive_via_postback: true} in the configurations.
Reading the documentation I thought that was recommended for custom matches, but it looks like it's leveraged to use postback in conversations as well.
@MagSag I hope this can help on your case as well :smile:.
Glad you found a resolution!
On Thu, May 4, 2017 at 2:40 AM federicoweber notifications@github.com
wrote:
Oh ok, I figured this out to enable postback in the convo all that is
needed is to pass in {receive_via_postback: true} in the configurations.Reading the documentation
https://github.com/howdyai/botkit/blob/master/docs/readme-facebook.md#receive-postback-button-clicks-as-typed-messages
I thought that was recommended for custom matches, but it looks like it's
leveraged to use postback in conversations as well 😄 .—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/howdyai/botkit/issues/815#issuecomment-299107901, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AMUR29D1hmp22BsIfLVhKqnT86yOoErHks5r2XLAgaJpZM4NMNo4
.
@federicoweber Thanks, it has helped me too.