Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Facebook echoes and read receipts #403

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ function Facebookbot(configuration) {
for (var m = 0; m < obj.entry[e].messaging.length; m++) {
var facebook_message = obj.entry[e].messaging[m];
if (facebook_message.message) {

var message = {
text: facebook_message.message.text,
user: facebook_message.sender.id,
channel: facebook_message.sender.id,
timestamp: facebook_message.timestamp,
seq: facebook_message.message.seq,
is_echo: facebook_message.message.is_echo,
mid: facebook_message.message.mid,
sticker_id: facebook_message.message.sticker_id,
attachments: facebook_message.message.attachments,
Expand Down Expand Up @@ -192,7 +192,16 @@ function Facebookbot(configuration) {
};

facebook_botkit.trigger('message_delivered', [bot, message]);
} else if (facebook_message.read) {

var message = {
optin: facebook_message.read,
user: facebook_message.sender.id,
channel: facebook_message.sender.id,
timestamp: facebook_message.timestamp,
};

facebook_botkit.trigger('message_read', [bot, message]);
} else {
facebook_botkit.log('Got an unexpected message from Facebook: ', facebook_message);
}
Expand Down
1 change: 1 addition & 0 deletions readme-facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Normal messages will be sent to your bot using the `message_received` event. In
| message_received | a message was received by the bot
| facebook_postback | user clicked a button in an attachment and triggered a webhook postback
| message_delivered | a confirmation from Facebook that a message has been received
| message_read | a confirmation from Facebook that a message has been read
| facebook_optin | a user has clicked the [Send-to-Messenger plugin](https://developers.facebook.com/docs/messenger-platform/implementation#send_to_messenger_plugin)

All incoming events will contain the fields `user` and `channel`, both of which represent the Facebook user's ID, and a `timestamp` field.
Expand Down