Skip to content

Commit

Permalink
Merge pull request #8304 from RocketChat/add-rdstation-livechat-integ…
Browse files Browse the repository at this point in the history
…ration

[NEW] Add RD Station integration to livechat
  • Loading branch information
rodrigok committed Sep 26, 2017
1 parent 96528fe commit 0e2de7c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -1430,6 +1430,7 @@
"quote": "quote",
"Quote": "Quote",
"Random": "Random",
"RDStation_Token": "RD Station Token",
"React_when_read_only": "Allow Reacting",
"React_when_read_only_changed_successfully": "Allow reacting when read only changed successfully",
"Reacted_with": "Reacted with",
Expand Down
8 changes: 8 additions & 0 deletions packages/rocketchat-livechat/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,12 @@ Meteor.startup(function() {
i18nLabel: 'Livechat_AllowedDomainsList',
i18nDescription: 'Domains_allowed_to_embed_the_livechat_widget'
});

RocketChat.settings.add('Livechat_RDStation_Token', '', {
type: 'string',
group: 'Livechat',
public: false,
section: 'RD Station',
i18nLabel: 'RDStation_Token'
});
});
1 change: 1 addition & 0 deletions packages/rocketchat-livechat/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ Package.onUse(function(api) {
api.addFiles('server/hooks/externalMessage.js', 'server');
api.addFiles('server/hooks/markRoomResponded.js', 'server');
api.addFiles('server/hooks/offlineMessage.js', 'server');
api.addFiles('server/hooks/RDStation.js', 'server');
api.addFiles('server/hooks/sendToCRM.js', 'server');

// methods
Expand Down
53 changes: 53 additions & 0 deletions packages/rocketchat-livechat/server/hooks/RDStation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
function sendToRDStation(room) {
if (!RocketChat.settings.get('Livechat_RDStation_Token')) {
return room;
}

const livechatData = RocketChat.Livechat.getLivechatRoomGuestInfo(room);

if (!livechatData.visitor.email) {
return room;
}

const options = {
headers: {
'Content-Type': 'application/json'
},
data: {
token_rdstation: RocketChat.settings.get('Livechat_RDStation_Token'),
identificador: 'rocketchat-livechat',
client_id: livechatData.visitor._id,
email: livechatData.visitor.email
}
};

options.data.nome = livechatData.visitor.name || livechatData.visitor.username;

if (livechatData.visitor.phone) {
options.data.telefone = livechatData.visitor.phone;
}

if (livechatData.tags) {
options.data.tags = livechatData.tags;
}

Object.keys(livechatData.customFields || {}).forEach(field => {
options.data[field] = livechatData.customFields[field];
});

Object.keys(livechatData.visitor.customFields || {}).forEach(field => {
options.data[field] = livechatData.visitor.customFields[field];
});

try {
HTTP.call('POST', 'https://www.rdstation.com.br/api/1.3/conversions', options);
} catch (e) {
console.error('Error sending lead to RD Station ->', e);
}

return room;
}

RocketChat.callbacks.add('livechat.closeRoom', sendToRDStation, RocketChat.callbacks.priority.MEDIUM, 'livechat-rd-station-close-room');

RocketChat.callbacks.add('livechat.saveInfo', sendToRDStation, RocketChat.callbacks.priority.MEDIUM, 'livechat-rd-station-save-info');

0 comments on commit 0e2de7c

Please sign in to comment.