Setup
controller = Botkit.facebookbot({
...
require_delivery: true
});
controller.hears('convo-test', 'message_received', (bot, message) => {
bot.startConversation(message, function(err, convo) {
convo.say('Look');
convo.say({
"attachment": {
"type": "image",
"payload": {
"url": "https://c1.staticflickr.com/1/34/122530930_6e16f1eb5c.jpg"
}
}
});
convo.say('That is a fat cat!');
});
});
If I type convo-test in messenger, I only get:
The message is never set to delivered
On line 27: when checking for a mid match, convo.sent[s].api_response.mid is undefined
convo.sent[s].api_response && convo.sent[s].api_response.mid == mid
the correct property is message_id
// convo.sent[s].api_response
{
recipient_id: '1127397383997557',
message_id: 'mid.$cAAZoIpjMd8BnLT1FD1g-_f8eDAwu'
}
https://github.com/howdyai/botkit/blob/5d237d5839f0bf3715d143e9fcb5f8bab4581aa9/lib/Facebook.js#L13-L37
I will submit a PR
see Facebook doco on this:
https://developers.facebook.com/docs/messenger-platform/reference/send-api#response
workaround until PR #1213 is merged
is just repeats the basic logic from above, but with the fix
controller.on('message_delivered', function(bot, message) {
// get list of mids in this message
for (var m = 0; m < message.delivery.mids.length; m++) {
var mid = message.delivery.mids[m];
// loop through all active conversations this bot is having
// and mark messages in conversations as delivered = true
bot.findConversation(message, function(convo) {
if (convo) {
for (var s = 0; s < convo.sent.length; s++) {
if (convo.sent[s].api_response && convo.sent[s].api_response.message_id == mid) {
convo.sent[s].delivered = true;
}
}
}
});
}
});
@jsalwen
message_deliveries webhook event ?I dont know if a have a local problem or facebook doesn't send a delivery confirmation !
Tha "Require Delivery Confirmation" functionality works fine for you ?
@ouadie-lahdioui
yes, my Facebook Messenger is subscribed to the message_deliveries event.
yes, I tested my fix #1213 and it works
@ouadie-lahdioui is shouldn't matter if you are subscribed to message_deliveries, since the api_response is set using the response message from Facebook after the message is received:
https://developers.facebook.com/docs/messenger-platform/reference/send-api#response
The PR was reviewed, so when it will be merged?
This fix was merged into Botkit 0.6.8.
Thanks for the work on this @jsalwen @ouadie-lahdioui @gcfabri and anyone else!
Most helpful comment
This fix was merged into Botkit 0.6.8.
Thanks for the work on this @jsalwen @ouadie-lahdioui @gcfabri and anyone else!