feat: Show the CSAT response to the agent (#2511)
This commit is contained in:
parent
b769fc87d0
commit
bd1b17baf3
6 changed files with 74 additions and 12 deletions
|
@ -54,7 +54,7 @@ class Api::V1::Widget::MessagesController < Api::V1::Widget::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def message_update_params
|
def message_update_params
|
||||||
params.permit(message: [{ submitted_values: [:name, :title, :value, { csat_survey_response: [:feedback_text, :rating] }] }])
|
params.permit(message: [{ submitted_values: [:name, :title, :value, { csat_survey_response: [:feedback, :rating] }] }])
|
||||||
end
|
end
|
||||||
|
|
||||||
def permitted_params
|
def permitted_params
|
||||||
|
|
|
@ -100,7 +100,13 @@ export default {
|
||||||
const botMessageContent = generateBotMessageContent(
|
const botMessageContent = generateBotMessageContent(
|
||||||
this.contentType,
|
this.contentType,
|
||||||
this.contentAttributes,
|
this.contentAttributes,
|
||||||
this.$t('CONVERSATION.NO_RESPONSE')
|
{
|
||||||
|
noResponseText: this.$t('CONVERSATION.NO_RESPONSE'),
|
||||||
|
csat: {
|
||||||
|
ratingTitle: this.$t('CONVERSATION.RATING_TITLE'),
|
||||||
|
feedbackTitle: this.$t('CONVERSATION.FEEDBACK_TITLE'),
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
const generateInputSelectContent = (contentType, contentAttributes) => {
|
import { CSAT_RATINGS } from '../../../../../shared/constants/messages';
|
||||||
|
|
||||||
|
const generateInputSelectContent = contentAttributes => {
|
||||||
const { submitted_values: submittedValues = [] } = contentAttributes;
|
const { submitted_values: submittedValues = [] } = contentAttributes;
|
||||||
const [selectedOption] = submittedValues;
|
const [selectedOption] = submittedValues;
|
||||||
|
|
||||||
|
@ -8,7 +10,7 @@ const generateInputSelectContent = (contentType, contentAttributes) => {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateInputEmailContent = (contentType, contentAttributes) => {
|
const generateInputEmailContent = contentAttributes => {
|
||||||
const { submitted_email: submittedEmail = '' } = contentAttributes;
|
const { submitted_email: submittedEmail = '' } = contentAttributes;
|
||||||
if (submittedEmail) {
|
if (submittedEmail) {
|
||||||
return `<strong>${submittedEmail}</strong>`;
|
return `<strong>${submittedEmail}</strong>`;
|
||||||
|
@ -16,11 +18,7 @@ const generateInputEmailContent = (contentType, contentAttributes) => {
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const generateFormContent = (
|
const generateFormContent = (contentAttributes, { noResponseText }) => {
|
||||||
contentType,
|
|
||||||
contentAttributes,
|
|
||||||
noResponseText
|
|
||||||
) => {
|
|
||||||
const { items, submitted_values: submittedValues = [] } = contentAttributes;
|
const { items, submitted_values: submittedValues = [] } = contentAttributes;
|
||||||
if (submittedValues.length) {
|
if (submittedValues.length) {
|
||||||
const submittedObject = submittedValues.reduce((acc, keyValuePair) => {
|
const submittedObject = submittedValues.reduce((acc, keyValuePair) => {
|
||||||
|
@ -38,20 +36,52 @@ const generateFormContent = (
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateCSATContent = (
|
||||||
|
contentAttributes,
|
||||||
|
{ ratingTitle, feedbackTitle }
|
||||||
|
) => {
|
||||||
|
const {
|
||||||
|
submitted_values: { csat_survey_response: surveyResponse = {} } = {},
|
||||||
|
} = contentAttributes;
|
||||||
|
const { rating, feedback } = surveyResponse || {};
|
||||||
|
|
||||||
|
let messageContent = '';
|
||||||
|
if (rating) {
|
||||||
|
const [ratingObject = {}] = CSAT_RATINGS.filter(
|
||||||
|
csatRating => csatRating.value === rating
|
||||||
|
);
|
||||||
|
messageContent += `<div><strong>${ratingTitle}</strong></div>`;
|
||||||
|
messageContent += `<p>${ratingObject.emoji}</p>`;
|
||||||
|
}
|
||||||
|
if (feedback) {
|
||||||
|
messageContent += `<div><strong>${feedbackTitle}</strong></div>`;
|
||||||
|
messageContent += `<p>${feedback}</p>`;
|
||||||
|
}
|
||||||
|
return messageContent;
|
||||||
|
};
|
||||||
|
|
||||||
export const generateBotMessageContent = (
|
export const generateBotMessageContent = (
|
||||||
contentType,
|
contentType,
|
||||||
contentAttributes,
|
contentAttributes,
|
||||||
noResponseText = 'No response'
|
{
|
||||||
|
noResponseText = 'No response',
|
||||||
|
csat: { ratingTitle = 'Rating', feedbackTitle = 'Feedback' } = {},
|
||||||
|
} = {}
|
||||||
) => {
|
) => {
|
||||||
const contentTypeMethods = {
|
const contentTypeMethods = {
|
||||||
input_select: generateInputSelectContent,
|
input_select: generateInputSelectContent,
|
||||||
input_email: generateInputEmailContent,
|
input_email: generateInputEmailContent,
|
||||||
form: generateFormContent,
|
form: generateFormContent,
|
||||||
|
input_csat: generateCSATContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
const contentTypeMethod = contentTypeMethods[contentType];
|
const contentTypeMethod = contentTypeMethods[contentType];
|
||||||
if (contentTypeMethod && typeof contentTypeMethod === 'function') {
|
if (contentTypeMethod && typeof contentTypeMethod === 'function') {
|
||||||
return contentTypeMethod(contentType, contentAttributes, noResponseText);
|
return contentTypeMethod(contentAttributes, {
|
||||||
|
noResponseText,
|
||||||
|
ratingTitle,
|
||||||
|
feedbackTitle,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,30 @@ describe('#generateBotMessageContent', () => {
|
||||||
).toEqual('<strong>hello@chatwoot.com</strong>');
|
).toEqual('<strong>hello@chatwoot.com</strong>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('return correct input_csat content', () => {
|
||||||
|
expect(
|
||||||
|
generateBotMessageContent('input_csat', {
|
||||||
|
submitted_values: {
|
||||||
|
csat_survey_response: { rating: 5, feedback: 'Great Service' },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
).toEqual(
|
||||||
|
'<div><strong>Rating</strong></div><p>😍</p><div><strong>Feedback</strong></div><p>Great Service</p>'
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
generateBotMessageContent(
|
||||||
|
'input_csat',
|
||||||
|
{
|
||||||
|
submitted_values: {
|
||||||
|
csat_survey_response: { rating: 1, feedback: '' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ csat: { ratingTitle: 'റേറ്റിംഗ്', feedbackTitle: 'പ്രതികരണം' } }
|
||||||
|
)
|
||||||
|
).toEqual('<div><strong>റേറ്റിംഗ്</strong></div><p>😞</p>');
|
||||||
|
});
|
||||||
|
|
||||||
it('return correct form content', () => {
|
it('return correct form content', () => {
|
||||||
expect(
|
expect(
|
||||||
generateBotMessageContent('form', {
|
generateBotMessageContent('form', {
|
||||||
|
|
|
@ -28,6 +28,8 @@
|
||||||
"DOWNLOAD": "Download",
|
"DOWNLOAD": "Download",
|
||||||
"UPLOADING_ATTACHMENTS": "Uploading attachments...",
|
"UPLOADING_ATTACHMENTS": "Uploading attachments...",
|
||||||
"NO_RESPONSE": "No response",
|
"NO_RESPONSE": "No response",
|
||||||
|
"RATING_TITLE": "Rating",
|
||||||
|
"FEEDBACK_TITLE": "Feedback",
|
||||||
"HEADER": {
|
"HEADER": {
|
||||||
"RESOLVE_ACTION": "Resolve",
|
"RESOLVE_ACTION": "Resolve",
|
||||||
"REOPEN_ACTION": "Reopen",
|
"REOPEN_ACTION": "Reopen",
|
||||||
|
|
|
@ -130,7 +130,7 @@ export default {
|
||||||
submittedValues: {
|
submittedValues: {
|
||||||
csat_survey_response: {
|
csat_survey_response: {
|
||||||
rating,
|
rating,
|
||||||
feedback_text: feedback,
|
feedback,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
messageId: this.messageId,
|
messageId: this.messageId,
|
||||||
|
|
Loading…
Reference in a new issue