Skip to content

Commit

Permalink
Merge pull request #469 from agamrafaeli/issue-447
Browse files Browse the repository at this point in the history
Add a type field to message to distinguish between 'message_received' and 'postback'
  • Loading branch information
Ben Brown committed Nov 7, 2016
2 parents 7282a8f + adb6a48 commit 689ae7c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,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 @@ -222,6 +223,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

0 comments on commit 689ae7c

Please sign in to comment.