2021-06-25 08:07:51 +00:00
|
|
|
import { CSAT_RATINGS } from '../../../../../shared/constants/messages';
|
|
|
|
|
|
|
|
const generateInputSelectContent = contentAttributes => {
|
2021-02-09 09:49:47 +00:00
|
|
|
const { submitted_values: submittedValues = [] } = contentAttributes;
|
|
|
|
const [selectedOption] = submittedValues;
|
|
|
|
|
|
|
|
if (selectedOption && selectedOption.title) {
|
|
|
|
return `<strong>${selectedOption.title}</strong>`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2021-06-25 08:07:51 +00:00
|
|
|
const generateInputEmailContent = contentAttributes => {
|
2021-02-09 09:49:47 +00:00
|
|
|
const { submitted_email: submittedEmail = '' } = contentAttributes;
|
|
|
|
if (submittedEmail) {
|
|
|
|
return `<strong>${submittedEmail}</strong>`;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2021-06-25 08:07:51 +00:00
|
|
|
const generateFormContent = (contentAttributes, { noResponseText }) => {
|
2021-02-09 09:49:47 +00:00
|
|
|
const { items, submitted_values: submittedValues = [] } = contentAttributes;
|
|
|
|
if (submittedValues.length) {
|
|
|
|
const submittedObject = submittedValues.reduce((acc, keyValuePair) => {
|
|
|
|
acc[keyValuePair.name] = keyValuePair.value;
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
let formMessageContent = '';
|
|
|
|
items.forEach(item => {
|
|
|
|
formMessageContent += `<div>${item.label}</div>`;
|
|
|
|
const response = submittedObject[item.name] || noResponseText;
|
|
|
|
formMessageContent += `<strong>${response}</strong><br/><br/>`;
|
|
|
|
});
|
|
|
|
return formMessageContent;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
|
|
|
|
2021-06-25 08:07:51 +00:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2021-02-09 09:49:47 +00:00
|
|
|
export const generateBotMessageContent = (
|
|
|
|
contentType,
|
|
|
|
contentAttributes,
|
2021-06-25 08:07:51 +00:00
|
|
|
{
|
|
|
|
noResponseText = 'No response',
|
|
|
|
csat: { ratingTitle = 'Rating', feedbackTitle = 'Feedback' } = {},
|
|
|
|
} = {}
|
2021-02-09 09:49:47 +00:00
|
|
|
) => {
|
|
|
|
const contentTypeMethods = {
|
|
|
|
input_select: generateInputSelectContent,
|
|
|
|
input_email: generateInputEmailContent,
|
|
|
|
form: generateFormContent,
|
2021-06-25 08:07:51 +00:00
|
|
|
input_csat: generateCSATContent,
|
2021-02-09 09:49:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const contentTypeMethod = contentTypeMethods[contentType];
|
|
|
|
if (contentTypeMethod && typeof contentTypeMethod === 'function') {
|
2021-06-25 08:07:51 +00:00
|
|
|
return contentTypeMethod(contentAttributes, {
|
|
|
|
noResponseText,
|
|
|
|
ratingTitle,
|
|
|
|
feedbackTitle,
|
|
|
|
});
|
2021-02-09 09:49:47 +00:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|