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

Commit

Permalink
Merge pull request #1289 from howdyai/march14
Browse files Browse the repository at this point in the history
Version 0.6.12
  • Loading branch information
Ben Brown authored Mar 15, 2018
2 parents 49e00f8 + 8737755 commit 2d64825
Show file tree
Hide file tree
Showing 11 changed files with 2,098 additions and 787 deletions.
21 changes: 21 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@

[Want to contribute? Read our guide!](https://github.com/howdyai/botkit/blob/master/CONTRIBUTING.md)

* 0.6.12

* [Botkit has a brand new docs site!](https://botkit.ai/docs) We have begun transitioning the documentation out of this repo into a [dedicated documentation repo](https://github.com/howdyai/botkit-docs).

* Remove dependency on Python introduced in 0.6.10. Thanks to @qiongfangzhang for the attention on that!

* Fix for Facebook Messenger send broadcast function. [PR #1280](https://github.com/howdyai/botkit/pull/1280) Thanks @OmranAbazid

* Extend Facebook's user profile object with locale. [PR #1265](https://github.com/howdyai/botkit/pull/1265) Thanks @julianusti

* Added 'picture' to Facebook User Profile endpoint. [PR #1264](https://github.com/howdyai/botkit/pull/1264) Thanks @se

* Add FB request thread control [PR #1257)(https://github.com/howdyai/botkit/pull/1257) Thanks as always to @oaudie-lahdioui

* Remove requirement that Cisco Spark endpoint be SSL. [PR #1284](https://github.com/howdyai/botkit/pull/1284) thanks @akalsey and your beard.

* Add support for Slack's `users.lookupByEmail` API. [PR #1285](https://github.com/howdyai/botkit/pull/1285)
Thanks to @piglovesyou

* Fix to the way variables are copied between conversations while using Botkit Studio scripts

# 0.6.11

* For Botkit Studio users, added `controller.studio.getById()` for loading scripts
Expand Down
28 changes: 28 additions & 0 deletions docs/readme-facebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,18 @@ controller.api.handover.pass_thread_control('<RECIPIENT_PSID>', '<TARGET_PSID>',
});
```

### Request Thread Control

The Request Thread Control API allows a Secondary Receiver app to notify the Primary Receiver that it wants control of the chat :

- To pass thread control:
```javascript
controller.api.handover.request_thread_control('<RECIPIENT_PSID>', 'String to pass to request the thread control', function (result) {

});
```


## Messaging type

You can identify the purpose of the message being sent to Facebook by adding `messaging_type: <MESSAGING_TYPE>` property when sending the message:
Expand Down Expand Up @@ -710,6 +722,22 @@ controller.api.broadcast.send('<CREATIVE_ID>', null, function (err, body) {
});
```

If you would like to add notification type and tag you can pass an object:

```javascript
var message = {
message_creative_id: '<CREATIVE_ID>',
notification_type: '<REGULAR | SILENT_PUSH | NO_PUSH>',
tag: '<MESSAGE_TAG>'
}

controller.api.broadcast.send(message, null, function (err, body) {
// Your awesome code here
console.log(body['broadcast_id']);
// And here
});
```

### Broadcast Metrics

Once a broadcast has been delivered, you can find out the total number of people it reached by calling ```controller.api.broadcast.get_broadcast_metrics(...)```.
Expand Down
2 changes: 0 additions & 2 deletions lib/CiscoSparkbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ function Sparkbot(configuration) {
var endpoint = url.parse(controller.config.public_address);
if (!endpoint.hostname) {
throw new Error('Could not determine hostname of public address: ' + controller.config.public_address);
} else if (endpoint.protocol != 'https:') {
throw new Error('Please specify an SSL-enabled url for your public address: ' + controller.config.public_address);
} else {
controller.config.public_address = endpoint.hostname + (endpoint.port ? ':' + endpoint.port : '');
}
Expand Down
12 changes: 10 additions & 2 deletions lib/CoreBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,16 @@ function Botkit(configuration) {
that.context.transition_to_id = new_convo.context.script_id || null;
that.stop('transitioning to ' + script);

new_convo.responses = that.responses;
new_convo.vars = that.vars;
// copy any question responses
for (var key in that.responses) {
new_convo.responses[key] = that.responses[key];
}

// copy old variables into new conversation
for (var key in that.vars) {
new_convo.setVar(key,that.vars[key]);
}

new_convo.context.transition_from = that.context.script_name || null;
new_convo.context.transition_from_id = that.context.script_id || null;

Expand Down
61 changes: 56 additions & 5 deletions lib/Facebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ function Facebookbot(configuration) {
full_name: identity.first_name + ' ' + identity.last_name,
email: identity.email || null,
gender: identity.gender,
locale: identity.locale,
picture: identity.picture,
timezone_offset: identity.timezone,
};

Expand Down Expand Up @@ -497,6 +499,9 @@ function Facebookbot(configuration) {
if (message.take_thread_control) {
message.type = 'facebook_lose_thread_control';
}
if (message.request_thread_control) {
message.type = 'facebook_request_thread_control';
}

next();

Expand Down Expand Up @@ -908,7 +913,7 @@ function Facebookbot(configuration) {

var user_profile = function(uid, fields, cb) {
if (!fields) {
fields = 'first_name,last_name,timezone,gender,locale,email';
fields = 'first_name,last_name,timezone,gender,locale,email,picture';
}
return new Promise(function(resolve, reject) {
var uri = 'https://' + api_host + '/' + api_version + '/' + uid + '?fields=' + fields + '&access_token=' + configuration.access_token;
Expand Down Expand Up @@ -1134,6 +1139,47 @@ function Facebookbot(configuration) {
}
}
});
},
request_thread_control: function(recipient, metadata, cb) {
var uri = 'https://' + api_host + '/' + api_version + '/me/request_thread_control';

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

var request_body = {
recipient: {
id: recipient
},
metadata: metadata
};
request.post({
url: uri,
qs: {
access_token: configuration.access_token
},
body: request_body,
json: true
}, function(err, res, body) {
if (err) {
facebook_botkit.log('Could not request thread control');
if (cb) {
cb(err);
}
} else {
if (body.error) {
facebook_botkit.log('ERROR in request thread control API call: ', body.error.message);
if (cb) {
cb(body.error);
}
} else {
facebook_botkit.debug('Successfully requested thread control', body);
if (cb) {
cb(null, body);
}
}
}
});
}
};
var broadcast_api = {
Expand Down Expand Up @@ -1182,16 +1228,21 @@ function Facebookbot(configuration) {
}
});
},
send: function(message_creative_id, custom_label_id, cb) {
send: function(message_creative, custom_label_id, cb) {
var uri = 'https://' + api_host + '/' + api_version + '/me/broadcast_messages?access_token=' + configuration.access_token;
var body = {};

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

var body = {
'message_creative_id': message_creative_id
};
if (typeof message_creative === 'string') {
body = {
'message_creative_id': message_creative
};
} else {
body = message_creative;
}

if (custom_label_id) {
body.custom_label_id = custom_label_id;
Expand Down
8 changes: 6 additions & 2 deletions lib/JabberBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function JabberBot(configuration) {
return jid === bot.client_jid;
}

function matchBotJid(jid_left, jid_right) {
return jid_left.toLowerCase() === jid_right.toLowerCase();
}

function IsBotMentioned(message) {
let mention_jids = extractMentionJids(message);
if (mention_jids.find(findBotJid)) {
Expand Down Expand Up @@ -110,7 +114,7 @@ function JabberBot(configuration) {

controller.on('message_received', function(bot, message) {
if (message.group == false) {
if (message.user === bot.client_jid) {
if (matchBotJid(message.user, bot.client_jid)) {
controller.trigger('self_message', [bot, message]);
return false;
} else {
Expand All @@ -119,7 +123,7 @@ function JabberBot(configuration) {
}
} else {
if (IsBotMentioned(message)) {
if (bot.client_jid == message.from_jid) {
if (matchBotJid(bot.client_jid, message.from_jid)) {
controller.trigger('self_message', [bot, message]);
} else {
controller.trigger('direct_mention', [bot, message]);
Expand Down
Loading

0 comments on commit 2d64825

Please sign in to comment.