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

Add FB scheduled broadcast #1354

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
17 changes: 17 additions & 0 deletions docs/readme-facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,23 @@ controller.api.handover.request_thread_control('<RECIPIENT_PSID>', 'String to pa
});
```

### Cancel a Scheduled Broadcast

- To cancel a scheduled broadcast :
```javascript
controller.api.handover.cancel_scheduled_broadcast('<BROADCAST_ID>', function (result) {

});
```

### Get a Broadcast Status

- To get a broadcast status :
```javascript
controller.api.handover.get_broadcast_status('<BROADCAST_ID>', ['scheduled_time', 'status'], function (result) {

});
```

## Messaging type

Expand Down
73 changes: 73 additions & 0 deletions lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,79 @@ function Facebookbot(configuration) {
}
}
});
},
cancel_scheduled_broadcast: function(broadcast_id, cb) {
var uri = 'https://' + api_host + '/' + api_version + '/' + broadcast_id + '?access_token=' + configuration.access_token;

if (facebook_botkit.config.require_appsecret_proof) {
uri += '&appsecret_proof=' + appsecret_proof;
}

var body = {
'operation': 'cancel'
};

request({
method: 'POST',
json: true,
body: body,
uri: uri
}, function(err, res, body) {
if (err) {
facebook_botkit.log('Could not cancel scheduled broadcast');
if (cb) {
cb(err);
}
} else {
if (body.error) {
facebook_botkit.log('ERROR in cencel scheduled broadcast call : ', body.error);
if (cb) {
cb(body.error);
}
} else {
facebook_botkit.debug('Successfully cancel scheduled broadcast', body);
if (cb) {
cb(null, body);
}
}
}
});
},
get_broadcast_status: function(broadcast_id, fields, cb) {
var uri = 'https://' + api_host + '/' + api_version + '/' + broadcast_id + '?access_token=' + configuration.access_token;

if (facebook_botkit.config.require_appsecret_proof) {
uri += '&appsecret_proof=' + appsecret_proof;
}

if (fields && fields.length > 0) {
uri += '&fields=' + fields.join(',');
}

request({
method: 'GET',
json: true,
uri: uri
}, function(err, res, body) {
if (err) {
facebook_botkit.log('Could not get broadcast status');
if (cb) {
cb(err);
}
} else {
if (body.error) {
facebook_botkit.log('ERROR in getting broadcast status call : ', body.error.message);
if (cb) {
cb(body.error);
}
} else {
facebook_botkit.log('Successfully get broadcast status');
if (cb) {
cb(null, body);
}
}
}
});
}
};

Expand Down