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

Commit

Permalink
Add support for facebook's built-in nlp
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Brown committed Aug 29, 2017
1 parent 2fba7ac commit fac122b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 2 deletions.
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@

Slack: Support for sending ephemeral messages with `bot.whisper()` and `bot.sendEphemeral()`. In addition, any message with `message.ephemeral` set to true will be sent with `bot.sendEphemeral()` automatically. [Read documentation here.](docs/readme-slack.md#ephemeral-messages) Thanks to [@jonchurch](https://github.com/howdyai/botkit/pull/958)

Slack: Add support for `bot.api.files.sharedPublicURL()` method. Thanks to [@GitTristan](https://github.com/howdyai/botkit/pull/912)

Facebook: Support for using [message tags](https://developers.facebook.com/docs/messenger-platform/message-tags). [Read documentation here.](docs/readme-facebook.md#message-tags) Thanks to [@ouadie-lahdioui](https://github.com/howdyai/botkit/pull/960)

Facebook: Support for using Facebook's new built-in NLP tools. [Read documentation here.](docs/readme-facebook.md#built-in-nlp) Thanks to [@ouadie-lahdioui](https://github.com/howdyai/botkit/pull/943) for this one too!!


Twilio SMS: Add support for sending MMS messages (file attachments) via Twilio. [Read documentation here.](docs/readme-twiliosms.md#sending-media-attachments-mms) Thanks to [@krismuniz](https://github.com/howdyai/botkit/pull/951)!

Cisco Spark: Emit a console warning when a bot receives messages from outside the allowed domain list. Thanks to [@MathRobin](https://github.com/howdyai/botkit/pull/918)!

New: Typescript declarations! Thanks to [@uny and @naktibalda](https://github.com/howdyai/botkit/pull/953) for their work on this.


Expand Down
12 changes: 12 additions & 0 deletions docs/readme-facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,18 @@ var attachment = {

```

## Built-in NLP

Facebook offers some built-in natural language processing tools. Once enabled, messages may contain a `message.nlp.` object with the results of the Facebook NLP.
More information can be found [in Facebook's official documentation of this feature](https://developers.facebook.com/docs/messenger-platform/built-in-nlp).

If specified, `message.nlp.entities` will include a list of entities and intents extracted by Facebook.

Facebook's NLP option can be enabled by calling `controller.api.nlp.enable()` in your Botkit app.

Facebook's NLP option can be disabled by calling `controller.api.nlp.enable()` in your Botkit app.


## Message Tags

Adding a tag to a message allows you to send it outside the 24+1 window.
Expand Down
2 changes: 2 additions & 0 deletions examples/facebook_bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ controller.hears(['attachment_upload'], 'message_received', function(bot, messag
});
});


controller.api.nlp.enable();
controller.api.messenger_profile.greeting('Hello! I\'m a Botkit bot!');
controller.api.messenger_profile.get_started('sample_get_started_payload');
controller.api.messenger_profile.menu([{
Expand Down
2 changes: 2 additions & 0 deletions lib/Botkit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ declare namespace botkit {
messenger_profile: any;
thread_settings: any;
tags: any;
nlp: any;

};
createWebhookEndpoints(webserver: any, bot: FacebookBot, cb?: () => void): this;
}
Expand Down
41 changes: 40 additions & 1 deletion lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ function Facebookbot(configuration) {
sticker_id: facebook_message.message.sticker_id,
attachments: facebook_message.message.attachments,
quick_reply: facebook_message.message.quick_reply,
nlp: facebook_message.message.nlp,
type: 'user_message',
};

Expand Down Expand Up @@ -679,11 +680,49 @@ function Facebookbot(configuration) {
}
};

var nlp = {
enable: function(custom_token) {
facebook_botkit.api.nlp.postAPI(true, custom_token);
},
disable: function() {
facebook_botkit.api.nlp.postAPI(false);
},
postAPI: function(value, custom_token) {
var uri = 'https://' + api_host + '/v2.8/me/nlp_configs?nlp_enabled=' + value + '&access_token=' + configuration.access_token;
if (custom_token) {
uri += '&custom_token=' + custom_token;
}
request.post(uri, {},
function(err, res, body) {
if (err) {
facebook_botkit.log('Could not enable/disable build-in NLP');
} else {

var results = null;
try {
results = JSON.parse(body);
} catch (err) {
facebook_botkit.log('ERROR in build-in NLP API call: Could not parse JSON', err, body);
}

if (results) {
if (results.error) {
facebook_botkit.log('ERROR in build-in API call: ', results.error.message);
} else {
facebook_botkit.debug('Successfully enable/disable build-in NLP', body);
}
}
}
});
}
};

facebook_botkit.api = {
'messenger_profile': messenger_profile_api,
'thread_settings': messenger_profile_api,
'attachment_upload': attachment_upload_api,
'tags': tags
'nlp': nlp,
'tags': tags,
};

// Verifies the SHA1 signature of the raw request payload before bodyParser parses it
Expand Down
2 changes: 1 addition & 1 deletion lib/TwilioSMSBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function TwilioSMS(configuration) {
};

if (message.hasOwnProperty('medaUrl')) {
sms.mediaUrl = message.mediaUrl
sms.mediaUrl = message.mediaUrl;
}

client.messages.create(sms, function(err, message) {
Expand Down

0 comments on commit fac122b

Please sign in to comment.