Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Allow to send Agent custom fields through the Omnichannel CRM integration #16286

Merged
16 changes: 16 additions & 0 deletions app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,17 @@ 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].allowExternalSharing === true)
renatobecker marked this conversation as resolved.
Show resolved Hide resolved
.map((field) => field);
} catch (error) {
return [];
}
};

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

Expand Down Expand Up @@ -630,11 +641,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