Skip to content

Commit

Permalink
fix: contact custom attributes (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
muhsin-k committed Dec 19, 2023
1 parent a0bd051 commit 2c35fd2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@chatwoot/utils",
"version": "0.0.17",
"version": "0.0.18",
"description": "Chatwoot utils",
"private": false,
"license": "MIT",
Expand Down
5 changes: 4 additions & 1 deletion src/canned.ts
Expand Up @@ -3,6 +3,7 @@ import {
Sender,
Variables,
CustomAttributes,
Contact,
} from './types/conversation';
const MESSAGE_VARIABLES_REGEX = /{{(.*?)}}/g;

Expand All @@ -28,15 +29,17 @@ export const getLastName = ({ user }: { user: Sender }) => {

export const getMessageVariables = ({
conversation,
contact

Check failure on line 32 in src/canned.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x and macOS-latest

Insert `,`

Check failure on line 32 in src/canned.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 16.x and ubuntu-latest

Insert `,`
}: {
conversation: Conversation;
contact?: Contact;
}) => {
const {
meta: { assignee, sender },
id,
custom_attributes: conversationCustomAttributes = {},
} = conversation;
const { custom_attributes: contactCustomAttributes } = sender || {};
const { custom_attributes: contactCustomAttributes } = contact || {};

const standardVariables = {
'contact.name': capitalizeName(sender?.name || ''),
Expand Down
8 changes: 8 additions & 0 deletions src/types/conversation.ts
Expand Up @@ -17,6 +17,14 @@ export interface Sender {
custom_attributes?: CustomAttributes;
}

export interface Contact {
id: number;
email?: string;
name?: string;
phone_number?: string;
custom_attributes?: CustomAttributes;
}

export interface Assignee {
id: number;
email?: string;
Expand Down
11 changes: 9 additions & 2 deletions test/canned.test.ts
Expand Up @@ -98,7 +98,6 @@ describe('#getMessageVariables', () => {
name: 'john Doe',
email: 'john.doe@gmail.com',
phone_number: '1234567890',
custom_attributes: { priority: 'high' },
},
},
id: 1,
Expand All @@ -107,7 +106,15 @@ describe('#getMessageVariables', () => {
car_year: '2022',
},
};
expect(getMessageVariables({ conversation })).toEqual({
const contact = {
id: 3,
name: 'john Doe',
email: 'john.doe@gmail.com',
phone_number: '1234567890',
custom_attributes: { priority: 'high' },
};

expect(getMessageVariables({ conversation, contact })).toEqual({
'contact.name': 'John Doe',
'contact.first_name': 'John',
'contact.id': 3,
Expand Down

0 comments on commit 2c35fd2

Please sign in to comment.