-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3063 from glific/templates-refactoring
Refactoring: Separating HSM and Speed sends
- Loading branch information
Showing
43 changed files
with
3,189 additions
and
3,578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ jobs: | |
git clone https://github.com/glific/cypress-testing.git | ||
echo done. go to dir. | ||
cd cypress-testing | ||
git checkout main | ||
git checkout templates | ||
cd .. | ||
cp -r cypress-testing/cypress cypress | ||
yarn add [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/containers/Chat/ChatMessages/ChatTemplates/ChatTemplates.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { CALL_TO_ACTION, MEDIA_MESSAGE_TYPES, QUICK_REPLY } from 'common/constants'; | ||
|
||
export interface CallToActionTemplate { | ||
type: string; | ||
title: string; | ||
value: string; | ||
} | ||
|
||
export interface QuickReplyTemplate { | ||
value: string; | ||
} | ||
|
||
export const mediaOptions = MEDIA_MESSAGE_TYPES.map((option: string) => ({ id: option, label: option })).filter( | ||
({ label }) => label !== 'AUDIO' && label !== 'STICKER' | ||
); | ||
|
||
export const removeFirstLineBreak = (text: any) => | ||
text?.length === 1 ? text.slice(0, 1).replace(/(\r\n|\n|\r)/, '') : text; | ||
|
||
/** | ||
* Function to convert buttons to template format | ||
* | ||
* @param templateButtons buttons that need to be converted to gupshup format | ||
* @param templateType depending on template type convert button to gupshup format | ||
* | ||
* @return array result | ||
*/ | ||
export const convertButtonsToTemplate = (templateButtons: Array<any>, templateType: string | null) => | ||
templateButtons.reduce((result: any, temp: any) => { | ||
const { title, value } = temp; | ||
if (templateType === CALL_TO_ACTION && value && title) { | ||
result.push(`[${title}, ${value}]`); | ||
} | ||
if (templateType === QUICK_REPLY && value) { | ||
result.push(`[${value}]`); | ||
} | ||
return result; | ||
}, []); | ||
|
||
/** | ||
* As messages and buttons are now separated | ||
* we are combining both message and buttons, | ||
* so that you can see preview in simulator | ||
* | ||
* @param templateType template type | ||
* @param message | ||
* @param buttons | ||
* | ||
* @return object {buttons, template} | ||
*/ | ||
export const getTemplateAndButtons = (templateType: string, message: string, buttons: string) => { | ||
const templateButtons = JSON.parse(buttons); | ||
let result: any; | ||
if (templateType === CALL_TO_ACTION) { | ||
result = templateButtons.map((button: any) => { | ||
const { phone_number: phoneNo, url, type, text } = button; | ||
return { type, value: url || phoneNo, title: text }; | ||
}); | ||
} | ||
|
||
if (templateType === QUICK_REPLY) { | ||
result = templateButtons.map((button: any) => { | ||
const { text, type } = button; | ||
return { type, value: text }; | ||
}); | ||
} | ||
|
||
// Getting in template format of gupshup | ||
const templateFormat = convertButtonsToTemplate(result, templateType); | ||
// Pre-pending message with buttons | ||
const template = `${message} | ${templateFormat.join(' | ')}`; | ||
return { buttons: result, template }; | ||
}; | ||
|
||
export const getExampleFromBody = (body: string, variables: Array<any>) => { | ||
return body.replace(/{{(\d+)}}/g, (match, number) => { | ||
let index = parseInt(number) - 1; | ||
|
||
return variables[index]?.text ? (variables[index] ? `[${variables[index]?.text}]` : match) : `{{${number}}}`; | ||
}); | ||
}; | ||
|
||
export const getVariables = (message: string, variables: any) => { | ||
const regex = /{{\d+}}/g; | ||
const matches = message.match(regex); | ||
|
||
if (!matches) { | ||
return []; | ||
} | ||
|
||
return matches.map((match, index) => (variables[index]?.text ? variables[index] : { text: '', id: index + 1 })); | ||
}; | ||
|
||
export const getExampleValue = (example: string) => { | ||
const regex = /\[([^\]]+)\]/g; | ||
let match; | ||
const variables = []; | ||
let id = 1; | ||
|
||
while ((match = regex.exec(example)) !== null) { | ||
variables.push({ text: match[1], id }); | ||
id++; | ||
} | ||
|
||
return variables; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
.Template { | ||
margin: 20px auto; | ||
width: 80%; | ||
text-align: center; | ||
box-shadow: 0 2px 3px #cccccc; | ||
border: 1px solid #eeeeee; | ||
padding: 10px; | ||
box-sizing: border-box; | ||
} | ||
|
||
@media (min-width: 600px) { | ||
.Template { | ||
width: 500px; | ||
} | ||
} | ||
|
||
.DeleteIcon { | ||
margin-right: 9px !important; | ||
} | ||
|
||
.DialogText { | ||
margin-top: 0px; | ||
text-align: center; | ||
color: #073f24; | ||
font-weight: 400; | ||
} | ||
|
||
.DeleteButton { | ||
margin-left: auto !important; | ||
} | ||
|
||
.Title { | ||
margin-left: 24px !important; | ||
margin-top: 16px !important; | ||
vertical-align: middle; | ||
font-weight: 500 !important; | ||
color: #073f24; | ||
} | ||
|
||
.Input { | ||
display: flex; | ||
padding: 8px; | ||
} | ||
|
||
.Label { | ||
width: 50%; | ||
align-self: center; | ||
font-weight: bold; | ||
} | ||
|
||
.TemplateAdd { | ||
width: fit-content; | ||
} | ||
|
||
.Form { | ||
padding: 16px 16px; | ||
width: 470px; | ||
} | ||
|
||
.Buttons { | ||
margin-top: 24px; | ||
margin-left: 8px; | ||
display: flex; | ||
justify-content: flex-start; | ||
} | ||
|
||
.Icon { | ||
background-color: #eaedec !important; | ||
margin-right: 10px !important; | ||
} | ||
|
||
.ButtonsCenter { | ||
justify-content: center !important; | ||
} | ||
|
||
.Button { | ||
margin-right: 24px !important; | ||
} | ||
|
||
.Warning { | ||
color: #ff0000; | ||
margin-left: -43px; | ||
} | ||
|
||
.IsActive { | ||
color: #555555; | ||
font-weight: 400; | ||
line-height: 18px; | ||
font-size: 16px; | ||
} | ||
|
||
.TemplateIcon { | ||
width: 29px; | ||
height: 29px; | ||
} | ||
|
||
.Checkbox { | ||
color: #555555; | ||
font-weight: 400; | ||
line-height: 18px; | ||
font-size: 16px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.