Skip to content

Commit

Permalink
[NEW] Allow to send Agent custom fields through the Omnichannel CRM i…
Browse files Browse the repository at this point in the history
…ntegration (#16286)
  • Loading branch information
renatobecker authored Apr 20, 2020
1 parent 01fbdb8 commit 83240bc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ export const Livechat = {
const visitor = LivechatVisitors.findOneById(room.v._id);
const agent = Users.findOneById(room.servedBy && room.servedBy._id);

const externalCustomFields = () => {
try {
const customFields = JSON.parse(settings.get('Accounts_CustomFields'));
return Object.keys(customFields)
.filter((customFieldKey) => customFields[customFieldKey].sendToIntegrations === true);
} catch (error) {
return [];
}
};

const ua = new UAParser();
ua.setUA(visitor.userAgent);

Expand Down Expand Up @@ -655,11 +665,16 @@ export const Livechat = {
};

if (agent) {
const { customFields: agentCustomFields = {} } = agent;
const externalCF = externalCustomFields();
const customFields = Object.keys(agentCustomFields).reduce((newObj, key) => (externalCF.includes(key) ? { ...newObj, [key]: agentCustomFields[key] } : newObj), null);

postData.agent = {
_id: agent._id,
username: agent.username,
name: agent.name,
email: null,
...customFields && { customFields },
};

if (agent.emails && agent.emails.length > 0) {
Expand Down

0 comments on commit 83240bc

Please sign in to comment.