Skip to content

Commit

Permalink
Merge pull request #9640 from RocketChat/fix-facebook-integration
Browse files Browse the repository at this point in the history
[FIX] Facebook integration in livechat not working on version 0.61.0
  • Loading branch information
rodrigok authored Feb 14, 2018
2 parents 8038eec + e0ec38b commit 074e4f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions packages/rocketchat-livechat/imports/server/rest/facebook.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import crypto from 'crypto';

import LivechatVisitors from '../../../server/models/LivechatVisitors';

/**
* @api {post} /livechat/facebook Send Facebook message
* @apiName Facebook
Expand Down Expand Up @@ -52,17 +55,15 @@ RocketChat.API.v1.addRoute('livechat/facebook', {
}
}
};

let visitor = RocketChat.models.Users.getVisitorByToken(this.bodyParams.token);
let visitor = LivechatVisitors.getVisitorByToken(this.bodyParams.token);
if (visitor) {
const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.profile.token).fetch();

const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.token).fetch();
if (rooms && rooms.length > 0) {
sendMessage.message.rid = rooms[0]._id;
} else {
sendMessage.message.rid = Random.id();
}
sendMessage.message.token = visitor.profile.token;
sendMessage.message.token = visitor.token;
} else {
sendMessage.message.rid = Random.id();
sendMessage.message.token = this.bodyParams.token;
Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-livechat/server/sendMessageBySMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RocketChat.callbacks.add('afterSaveMessage', function(message, room) {

const visitor = LivechatVisitors.getVisitorByToken(room.v.token);

if (!visitor || !visitor.profile || !visitor.phone || visitor.phone.length === 0) {
if (!visitor || !visitor.phone || visitor.phone.length === 0) {
return message;
}

Expand Down

0 comments on commit 074e4f9

Please sign in to comment.