mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-02 12:08:01 +00:00
chore: Auto capitalize the name field while sending the canned response/variables (#6758)
* capitalize name before sending the message * Fix specs * Code cleanups
This commit is contained in:
@@ -7,10 +7,15 @@ export const replaceVariablesInMessage = ({ message, variables }) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const capitalizeName = string => {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
};
|
||||
|
||||
const skipCodeBlocks = str => str.replace(/```(?:.|\n)+?```/g, '');
|
||||
|
||||
export const getFirstName = ({ user }) => {
|
||||
return user?.name ? user.name.split(' ').shift() : '';
|
||||
const firstName = user?.name ? user.name.split(' ').shift() : '';
|
||||
return capitalizeName(firstName);
|
||||
};
|
||||
|
||||
export const getLastName = ({ user }) => {
|
||||
@@ -27,7 +32,7 @@ export const getMessageVariables = ({ conversation }) => {
|
||||
} = conversation;
|
||||
|
||||
return {
|
||||
'contact.name': sender?.name,
|
||||
'contact.name': capitalizeName(sender?.name),
|
||||
'contact.first_name': getFirstName({ user: sender }),
|
||||
'contact.last_name': getLastName({ user: sender }),
|
||||
'contact.email': sender?.email,
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
getLastName,
|
||||
getMessageVariables,
|
||||
getUndefinedVariablesInMessage,
|
||||
capitalizeName,
|
||||
} from '../messageHelper';
|
||||
|
||||
const variables = {
|
||||
@@ -136,3 +137,18 @@ describe('#getUndefinedVariablesInMessage', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#capitalizeName', () => {
|
||||
it('Capitalize name if name is passed', () => {
|
||||
const string = 'hello world';
|
||||
expect(capitalizeName(string)).toBe('Hello world');
|
||||
});
|
||||
it('returns empty string if the string is empty', () => {
|
||||
const string = '';
|
||||
expect(capitalizeName(string)).toBe('');
|
||||
});
|
||||
it('Capitalize first name if full name is passed', () => {
|
||||
const string = 'john Doe';
|
||||
expect(capitalizeName(string)).toBe('John Doe');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user