Add message helper
This commit is contained in:
parent
a151b86637
commit
5237fee661
4 changed files with 90 additions and 9 deletions
|
@ -6,7 +6,7 @@
|
||||||
@click="insertMentionNode"
|
@click="insertMentionNode"
|
||||||
/>
|
/>
|
||||||
<canned-response
|
<canned-response
|
||||||
v-if="showCannedMenu && !isPrivate"
|
v-if="shouldShowCannedResponses"
|
||||||
:search-key="cannedSearchTerm"
|
:search-key="cannedSearchTerm"
|
||||||
@click="insertCannedResponse"
|
@click="insertCannedResponse"
|
||||||
/>
|
/>
|
||||||
|
@ -80,7 +80,8 @@ export default {
|
||||||
enableSuggestions: { type: Boolean, default: true },
|
enableSuggestions: { type: Boolean, default: true },
|
||||||
overrideLineBreaks: { type: Boolean, default: false },
|
overrideLineBreaks: { type: Boolean, default: false },
|
||||||
updateSelectionWith: { type: String, default: '' },
|
updateSelectionWith: { type: String, default: '' },
|
||||||
enableVariables: { type: Boolean, default: true },
|
enableVariables: { type: Boolean, default: false },
|
||||||
|
enableCannedResponses: { type: Boolean, default: true },
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -104,6 +105,11 @@ export default {
|
||||||
shouldShowVariables() {
|
shouldShowVariables() {
|
||||||
return this.enableVariables && this.showVariables && !this.isPrivate;
|
return this.enableVariables && this.showVariables && !this.isPrivate;
|
||||||
},
|
},
|
||||||
|
shouldShowCannedResponses() {
|
||||||
|
return (
|
||||||
|
this.enableCannedResponses && this.showCannedMenu && !this.isPrivate
|
||||||
|
);
|
||||||
|
},
|
||||||
plugins() {
|
plugins() {
|
||||||
if (!this.enableSuggestions) {
|
if (!this.enableSuggestions) {
|
||||||
return [];
|
return [];
|
||||||
|
|
8
app/javascript/dashboard/helper/messageHelper.js
Normal file
8
app/javascript/dashboard/helper/messageHelper.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
export const findReplaceMessageVariables = ({ message, replacementList }) => {
|
||||||
|
const regex = /{{(.*?)}}/g;
|
||||||
|
return message.replace(regex, (match, replace) => {
|
||||||
|
return replacementList[replace.trim()]
|
||||||
|
? replacementList[replace.trim().toLowerCase()]
|
||||||
|
: '';
|
||||||
|
});
|
||||||
|
};
|
49
app/javascript/dashboard/helper/specs/messageHelper.spec.js
Normal file
49
app/javascript/dashboard/helper/specs/messageHelper.spec.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import { findReplaceMessageVariables } from '../messageHelper';
|
||||||
|
|
||||||
|
const replacementList = {
|
||||||
|
'contact.name': 'John',
|
||||||
|
'contact.email': 'john.p@example.com',
|
||||||
|
'contact.phone': '1234567890',
|
||||||
|
'conversation.id': 1,
|
||||||
|
'agent.name': 'Samuel',
|
||||||
|
'agent.email': 'samuel@gmail.com',
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('#findReplaceMessageVariables', () => {
|
||||||
|
it('returns the message with variable name', () => {
|
||||||
|
const message = 'hey {{contact.name}} how may I help you?';
|
||||||
|
expect(findReplaceMessageVariables({ message, replacementList })).toBe(
|
||||||
|
'hey John how may I help you?'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the message with variable name having white space', () => {
|
||||||
|
const message = 'hey {{contact.name}} how may I help you?';
|
||||||
|
expect(findReplaceMessageVariables({ message, replacementList })).toBe(
|
||||||
|
'hey John how may I help you?'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the message with variable email', () => {
|
||||||
|
const message =
|
||||||
|
'No issues. We will send the reset instructions to your email at {{contact.email}}';
|
||||||
|
expect(findReplaceMessageVariables({ message, replacementList })).toBe(
|
||||||
|
'No issues. We will send the reset instructions to your email at john.p@example.com'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the message with multiple variables', () => {
|
||||||
|
const message =
|
||||||
|
'hey {{ contact.name }}, no issues. We will send the reset instructions to your email at {{contact.email}}';
|
||||||
|
expect(findReplaceMessageVariables({ message, replacementList })).toBe(
|
||||||
|
'hey John, no issues. We will send the reset instructions to your email at john.p@example.com'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the message if the variable is not present in replacementList', () => {
|
||||||
|
const message = 'Please dm me at {{contact.twitter}}';
|
||||||
|
expect(findReplaceMessageVariables({ message, replacementList })).toBe(
|
||||||
|
'Please dm me at '
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -21,13 +21,17 @@
|
||||||
<div class="medium-12 columns">
|
<div class="medium-12 columns">
|
||||||
<label :class="{ error: $v.content.$error }">
|
<label :class="{ error: $v.content.$error }">
|
||||||
{{ $t('CANNED_MGMT.ADD.FORM.CONTENT.LABEL') }}
|
{{ $t('CANNED_MGMT.ADD.FORM.CONTENT.LABEL') }}
|
||||||
<textarea
|
<label class="editor-wrap">
|
||||||
v-model.trim="content"
|
<woot-message-editor
|
||||||
rows="5"
|
v-model="content"
|
||||||
type="text"
|
class="message-editor"
|
||||||
:placeholder="$t('CANNED_MGMT.ADD.FORM.CONTENT.PLACEHOLDER')"
|
:class="{ editor_warning: $v.content.$error }"
|
||||||
@input="$v.content.$touch"
|
:enable-variables="true"
|
||||||
/>
|
:enable-canned-responses="false"
|
||||||
|
:placeholder="$t('CANNED_MGMT.ADD.FORM.CONTENT.PLACEHOLDER')"
|
||||||
|
@blur="$v.content.$touch"
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -56,12 +60,14 @@ import { required, minLength } from 'vuelidate/lib/validators';
|
||||||
|
|
||||||
import WootSubmitButton from '../../../../components/buttons/FormSubmitButton';
|
import WootSubmitButton from '../../../../components/buttons/FormSubmitButton';
|
||||||
import Modal from '../../../../components/Modal';
|
import Modal from '../../../../components/Modal';
|
||||||
|
import WootMessageEditor from 'dashboard/components/widgets/WootWriter/Editor';
|
||||||
import alertMixin from 'shared/mixins/alertMixin';
|
import alertMixin from 'shared/mixins/alertMixin';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
WootSubmitButton,
|
WootSubmitButton,
|
||||||
Modal,
|
Modal,
|
||||||
|
WootMessageEditor,
|
||||||
},
|
},
|
||||||
mixins: [alertMixin],
|
mixins: [alertMixin],
|
||||||
props: {
|
props: {
|
||||||
|
@ -125,3 +131,15 @@ export default {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
::v-deep .mention--box {
|
||||||
|
border-left: 1px solid var(--color-border);
|
||||||
|
border-right: 1px solid var(--color-border);
|
||||||
|
left: 0;
|
||||||
|
margin: auto;
|
||||||
|
right: 0;
|
||||||
|
top: 17rem !important;
|
||||||
|
width: 90%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
Loading…
Reference in a new issue