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

Add a type field to message to distinguish between 'message_received' and 'postback' #469

Merged
merged 4 commits into from
Nov 7, 2016
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
4 changes: 3 additions & 1 deletion lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ function Facebookbot(configuration) {
mid: facebook_message.message.mid,
sticker_id: facebook_message.message.sticker_id,
attachments: facebook_message.message.attachments,
quick_reply: facebook_message.message.quick_reply
quick_reply: facebook_message.message.quick_reply,
type: "user_message",
};

facebook_botkit.receiveMessage(bot, message);
Expand All @@ -219,6 +220,7 @@ function Facebookbot(configuration) {
user: facebook_message.sender.id,
channel: facebook_message.sender.id,
timestamp: facebook_message.timestamp,
type: "facebook_postback",
};

facebook_botkit.receiveMessage(bot, message);
Expand Down
4 changes: 3 additions & 1 deletion readme-facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ All incoming events will contain the fields `user` and `channel`, both of which

`message_received` events will also contain either a `text` field or an `attachment` field.

`facebook_postback` events will contain a `payload` field.
`facebook_postback` events will contain a `payload` field.

Notice also that `facebook_postback` events trigger the `message_received` event as well. That is why messages will have the `type` field as well. When the message is directly from the user (i.e. onlye `message_received` event) `type` will be set to `"user_message"` and when the message is originated in a `facebook_postback` then `type` will be set to `facebook_postback`.

More information about the data found in these fields can be found [here](https://developers.facebook.com/docs/messenger-platform/webhook-reference).

Expand Down