diff --git a/ee/app/canned-responses/server/hooks/onMessageSentParsePlaceholder.ts b/ee/app/canned-responses/server/hooks/onMessageSentParsePlaceholder.ts index 7afe45463a93..c8a0006c7c07 100644 --- a/ee/app/canned-responses/server/hooks/onMessageSentParsePlaceholder.ts +++ b/ee/app/canned-responses/server/hooks/onMessageSentParsePlaceholder.ts @@ -29,6 +29,8 @@ const placeholderFields = { }, }; +const replaceAll = (text: string, old: string, replace: string): string => text.replace(new RegExp(old, 'g'), replace); + const handleBeforeSaveMessage = (message: IMessage, room: IOmnichannelRoom): any => { if (!message.msg || message.msg === '') { return message; @@ -50,7 +52,7 @@ const handleBeforeSaveMessage = (message: IMessage, room: IOmnichannelRoom): any const placeholderConfig = placeholderFields[field as keyof typeof placeholderFields]; const from = placeholderConfig.from === 'agent' ? agent : visitor; const data = get(from, placeholderConfig.dataKey, ''); - messageText = messageText.replace(templateKey, data); + messageText = replaceAll(messageText, templateKey, data); return messageText; });