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

Adding support for Facebook Notification Settings (Regular Push, Silent Push, Silent) #472

Merged
merged 3 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
15 changes: 15 additions & 0 deletions facebook_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ controller.hears(['hello', 'hi'], 'message_received', function(bot, message) {
});
});

controller.hears(['silent push reply'], 'message_received', function(bot, message) {
reply_message = {
text: "This message will have a push notification on a mobile phone, but no sound notification",
notification_type: "SILENT_PUSH"
}
bot.reply(message, reply_message)
})

controller.hears(['no push'], 'message_received', function(bot, message) {
reply_message = {
text: "This message will not have any push notification on a mobile phone",
notification_type: "NO_PUSH"
}
bot.reply(message, reply_message)
})

controller.hears(['structured'], 'message_received', function(bot, message) {

Expand Down
5 changes: 4 additions & 1 deletion lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ function Facebookbot(configuration) {
facebook_message.sender_action = message.sender_action;
}

//Add Access Token to outgoing request
if (message.notification_type) {
facebook_message.notification_type = message.notification_type
}

//Add Access Token to outgoing request
facebook_message.access_token = configuration.access_token;

request({
Expand Down
16 changes: 16 additions & 0 deletions readme-facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@ bot.stopTyping(message, function () {
bot.replyWithTyping(message, 'Hello there, my friend!');
```

## Silent and No Notifications
When sending a user a message you can make the message have either no notification or have a notification that doesn't play a sound. Both of these features are unique to the mobile application messenger. To do this add the `notification_type` field to message. Notification type must be one of the following:
- REGULAR will emit a sound/vibration and a phone notification
- SILENT_PUSH will just emit a phone notification
- NO_PUSH will not emit either

`notification_type` is optional. By default, messages will be REGULAR push notification type

```
reply_message = {
text: "Message text here",
notification_type: NOTIFICATION_TYPE
}
bot.reply(message, reply_message)
```

## Use BotKit for Facebook Messenger with an Express web server
Instead of the web server generated with setupWebserver(), it is possible to use a different web server to receive webhooks, as well as serving web pages.

Expand Down