feat: CSAT for all channels (#2749)
This commit is contained in:
parent
5debe9e8ee
commit
6515b69560
23 changed files with 382 additions and 68 deletions
|
@ -170,7 +170,7 @@
|
||||||
</p>
|
</p>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label v-if="isAWebWidgetInbox" class="medium-9 columns">
|
<label class="medium-9 columns">
|
||||||
{{ $t('INBOX_MGMT.SETTINGS_POPUP.ENABLE_CSAT') }}
|
{{ $t('INBOX_MGMT.SETTINGS_POPUP.ENABLE_CSAT') }}
|
||||||
<select v-model="csatSurveyEnabled">
|
<select v-model="csatSurveyEnabled">
|
||||||
<option :value="true">
|
<option :value="true">
|
||||||
|
@ -416,7 +416,7 @@ export default {
|
||||||
return this.$t('INBOX_MGMT.ADD.WEBSITE_NAME.PLACEHOLDER');
|
return this.$t('INBOX_MGMT.ADD.WEBSITE_NAME.PLACEHOLDER');
|
||||||
}
|
}
|
||||||
return this.$t('INBOX_MGMT.ADD.CHANNEL_NAME.PLACEHOLDER');
|
return this.$t('INBOX_MGMT.ADD.CHANNEL_NAME.PLACEHOLDER');
|
||||||
},
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
$route(to) {
|
$route(to) {
|
||||||
|
|
13
app/javascript/survey/api/endPoints.js
Normal file
13
app/javascript/survey/api/endPoints.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
const updateSurvey = ({ uuid, data }) => ({
|
||||||
|
url: `/public/api/v1/csat_survey/${uuid}`,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
|
||||||
|
const getSurvey = ({ uuid }) => ({
|
||||||
|
url: `/public/api/v1/csat_survey/${uuid}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
export default {
|
||||||
|
getSurvey,
|
||||||
|
updateSurvey,
|
||||||
|
};
|
38
app/javascript/survey/api/specs/endPoints.spec.js
Normal file
38
app/javascript/survey/api/specs/endPoints.spec.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import endPoints from '../endPoints';
|
||||||
|
const uuid = '98c5d7f3-8873-4262-b101-d56425ff7ee1';
|
||||||
|
|
||||||
|
describe('#getSurvey', () => {
|
||||||
|
it('should returns correct payload', () => {
|
||||||
|
expect(
|
||||||
|
endPoints.getSurvey({
|
||||||
|
uuid,
|
||||||
|
})
|
||||||
|
).toEqual({
|
||||||
|
url: `/public/api/v1/csat_survey/98c5d7f3-8873-4262-b101-d56425ff7ee1`,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#updateSurvey', () => {
|
||||||
|
it('should returns correct payload', () => {
|
||||||
|
const data = {
|
||||||
|
message: {
|
||||||
|
submitted_values: {
|
||||||
|
csat_survey_response: {
|
||||||
|
rating: 4,
|
||||||
|
feedback_message: 'amazing',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
expect(
|
||||||
|
endPoints.updateSurvey({
|
||||||
|
uuid,
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
).toEqual({
|
||||||
|
url: `/public/api/v1/csat_survey/98c5d7f3-8873-4262-b101-d56425ff7ee1`,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
15
app/javascript/survey/api/survey.js
Normal file
15
app/javascript/survey/api/survey.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import endPoints from 'survey/api/endPoints';
|
||||||
|
import { API } from 'survey/helpers/axios';
|
||||||
|
|
||||||
|
const getSurveyDetails = async ({ uuid }) => {
|
||||||
|
const urlData = endPoints.getSurvey({ uuid });
|
||||||
|
const result = await API.get(urlData.url, { params: urlData.params });
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateSurvey = async ({ uuid, data }) => {
|
||||||
|
const urlData = endPoints.updateSurvey({ data, uuid });
|
||||||
|
await API.put(urlData.url, { ...urlData.data });
|
||||||
|
};
|
||||||
|
|
||||||
|
export { getSurveyDetails, updateSurvey };
|
|
@ -7,6 +7,7 @@
|
||||||
@import 'widget/assets/scss/mixins';
|
@import 'widget/assets/scss/mixins';
|
||||||
@import 'widget/assets/scss/forms';
|
@import 'widget/assets/scss/forms';
|
||||||
@import 'shared/assets/fonts/widget_fonts';
|
@import 'shared/assets/fonts/widget_fonts';
|
||||||
|
@import '~shared/assets/stylesheets/ionicons';
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
|
|
31
app/javascript/survey/components/Banner.vue
Normal file
31
app/javascript/survey/components/Banner.vue
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<template>
|
||||||
|
<div class="flex items-center">
|
||||||
|
<i
|
||||||
|
v-if="showSuccess"
|
||||||
|
class="ion-checkmark-circled text-3xl text-green-500 mr-1"
|
||||||
|
/>
|
||||||
|
<i v-if="showError" class="ion-android-alert text-3xl text-red-600 mr-1" />
|
||||||
|
<label class="text-base font-medium text-black-800 mt-4 mb-4">
|
||||||
|
{{ message }}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
showSuccess: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
showError: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
54
app/javascript/survey/components/Feedback.vue
Normal file
54
app/javascript/survey/components/Feedback.vue
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<label class="text-base font-medium text-black-800">
|
||||||
|
{{ $t('SURVEY.FEEDBACK.LABEL') }}
|
||||||
|
</label>
|
||||||
|
<text-area
|
||||||
|
v-model="feedback"
|
||||||
|
class="my-5"
|
||||||
|
:placeholder="$t('SURVEY.FEEDBACK.PLACEHOLDER')"
|
||||||
|
/>
|
||||||
|
<div class="flex items-center font-medium float-right">
|
||||||
|
<custom-button @click="onClick">
|
||||||
|
<spinner v-if="feedback" class="p-0" />
|
||||||
|
{{ $t('SURVEY.FEEDBACK.BUTTON_TEXT') }}
|
||||||
|
</custom-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import CustomButton from 'shared/components/Button';
|
||||||
|
import TextArea from 'shared/components/TextArea.vue';
|
||||||
|
import Spinner from 'shared/components/Spinner';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'Feedback',
|
||||||
|
components: {
|
||||||
|
CustomButton,
|
||||||
|
TextArea,
|
||||||
|
Spinner,
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
isUpdating: {
|
||||||
|
type: Boolean,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
isButtonDisabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: null,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
feedback: '',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onClick() {
|
||||||
|
this.$emit('sendFeedback', this.feedback);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
|
@ -5,7 +5,7 @@
|
||||||
v-for="rating in ratings"
|
v-for="rating in ratings"
|
||||||
:key="rating.key"
|
:key="rating.key"
|
||||||
:class="buttonClass(rating)"
|
:class="buttonClass(rating)"
|
||||||
@click="selectRating(rating)"
|
@click="onClick(rating)"
|
||||||
>
|
>
|
||||||
{{ rating.emoji }}
|
{{ rating.emoji }}
|
||||||
</button>
|
</button>
|
||||||
|
@ -18,35 +18,28 @@ import { CSAT_RATINGS } from 'shared/constants/messages';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
messageContentAttributes: {
|
selectedRating: {
|
||||||
type: Object,
|
type: Number,
|
||||||
default: () => {},
|
default: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
email: '',
|
|
||||||
ratings: CSAT_RATINGS,
|
ratings: CSAT_RATINGS,
|
||||||
selectedRating: null,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
|
||||||
isRatingSubmitted() {
|
|
||||||
return this.messageContentAttributes?.csat_survey_response?.rating;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
buttonClass(rating) {
|
buttonClass(rating) {
|
||||||
return [
|
return [
|
||||||
{ selected: rating.value === this.selectedRating },
|
{ selected: rating.value === this.selectedRating },
|
||||||
{ disabled: this.isRatingSubmitted },
|
{ disabled: !!this.selectedRating },
|
||||||
{ hover: this.isRatingSubmitted },
|
{ hover: !!this.selectedRating },
|
||||||
'emoji-button shadow-none text-4xl outline-none mr-8',
|
'emoji-button shadow-none text-4xl outline-none mr-8',
|
||||||
];
|
];
|
||||||
},
|
},
|
||||||
selectRating(rating) {
|
onClick(rating) {
|
||||||
this.selectedRating = rating.value;
|
this.$emit('selectRating', rating.value);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
6
app/javascript/survey/helpers/axios.js
Normal file
6
app/javascript/survey/helpers/axios.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import axios from 'axios';
|
||||||
|
import { APP_BASE_URL } from 'widget/helpers/constants';
|
||||||
|
|
||||||
|
export const API = axios.create({
|
||||||
|
baseURL: APP_BASE_URL,
|
||||||
|
});
|
|
@ -9,6 +9,10 @@
|
||||||
"LABEL": "Do you have any thoughts you'd like to share?",
|
"LABEL": "Do you have any thoughts you'd like to share?",
|
||||||
"PLACEHOLDER": "Your feedback (optional)",
|
"PLACEHOLDER": "Your feedback (optional)",
|
||||||
"BUTTON_TEXT": "Submit feedback"
|
"BUTTON_TEXT": "Submit feedback"
|
||||||
|
},
|
||||||
|
"API": {
|
||||||
|
"SUCCESS_MESSAGE": "Survey updated successfully",
|
||||||
|
"ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"POWERED_BY": "Powered by Chatwoot"
|
"POWERED_BY": "Powered by Chatwoot"
|
||||||
|
|
|
@ -1,29 +1,43 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
|
v-if="isLoading"
|
||||||
|
class="flex flex-1 items-center h-full bg-black-25 justify-center"
|
||||||
|
>
|
||||||
|
<spinner size="" />
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
class="w-full h-full flex flex-col flex-no-wrap overflow-hidden bg-white"
|
class="w-full h-full flex flex-col flex-no-wrap overflow-hidden bg-white"
|
||||||
>
|
>
|
||||||
<div class="flex flex-1 overflow-auto">
|
<div class="flex flex-1 overflow-auto">
|
||||||
<div class="max-w-screen-sm w-full my-0 m-auto px-8 py-12">
|
<div class="max-w-screen-sm w-full my-0 m-auto px-8 py-12">
|
||||||
<img src="/brand-assets/logo.svg" alt="Chatwoot logo" class="logo" />
|
<img :src="logo" alt="Chatwoot logo" class="logo" @error="imgUrlAlt" />
|
||||||
<p class="text-black-700 text-lg leading-relaxed mt-4 mb-4">
|
<p class="text-black-700 text-lg leading-relaxed mt-4 mb-4">
|
||||||
{{ $t('SURVEY.DESCRIPTION') }}
|
{{ surveyDescription }}
|
||||||
</p>
|
</p>
|
||||||
<label class="text-base font-medium text-black-800">
|
<banner
|
||||||
|
v-if="shouldShowBanner"
|
||||||
|
:show-success="shouldShowSuccessMesage"
|
||||||
|
:show-error="shouldShowErrorMesage"
|
||||||
|
:message="message"
|
||||||
|
/>
|
||||||
|
<label
|
||||||
|
v-if="!isRatingSubmitted"
|
||||||
|
class="text-base font-medium text-black-800 mt-4 mb-4"
|
||||||
|
>
|
||||||
{{ $t('SURVEY.RATING.LABEL') }}
|
{{ $t('SURVEY.RATING.LABEL') }}
|
||||||
</label>
|
</label>
|
||||||
<rating />
|
<rating
|
||||||
<label class="text-base font-medium text-black-800">
|
:selected-rating="selectedRating"
|
||||||
{{ $t('SURVEY.FEEDBACK.LABEL') }}
|
@selectRating="selectRating"
|
||||||
</label>
|
/>
|
||||||
<text-area
|
<feedback
|
||||||
v-model="message"
|
v-if="enableFeedbackForm"
|
||||||
class="my-5"
|
:is-updating="isUpdating"
|
||||||
:placeholder="$t('SURVEY.FEEDBACK.PLACEHOLDER')"
|
:is-button-disabled="isButtonDisabled"
|
||||||
|
:selected-rating="selectedRating"
|
||||||
|
@sendFeedback="sendFeedback"
|
||||||
/>
|
/>
|
||||||
<custom-button class="font-medium float-right">
|
|
||||||
<spinner v-if="isSubmitted" class="p-0" />
|
|
||||||
{{ $t('SURVEY.FEEDBACK.BUTTON_TEXT') }}
|
|
||||||
</custom-button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer-wrap flex-shrink-0 w-full flex flex-col relative">
|
<div class="footer-wrap flex-shrink-0 w-full flex flex-col relative">
|
||||||
|
@ -33,26 +47,138 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import Branding from 'shared/components/Branding.vue';
|
import Branding from 'shared/components/Branding';
|
||||||
import Rating from 'survey/components/Rating.vue';
|
import Spinner from 'shared/components/Spinner';
|
||||||
import CustomButton from 'shared/components/Button';
|
import Rating from 'survey/components/Rating';
|
||||||
import TextArea from 'shared/components/TextArea.vue';
|
import Feedback from 'survey/components/Feedback';
|
||||||
|
import Banner from 'survey/components/Banner';
|
||||||
import configMixin from 'shared/mixins/configMixin';
|
import configMixin from 'shared/mixins/configMixin';
|
||||||
|
import { getSurveyDetails, updateSurvey } from 'survey/api/survey';
|
||||||
|
import alertMixin from 'shared/mixins/alertMixin';
|
||||||
|
const BRAND_LOGO = '/brand-assets/logo.svg';
|
||||||
export default {
|
export default {
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
components: {
|
components: {
|
||||||
Branding,
|
Branding,
|
||||||
Rating,
|
Rating,
|
||||||
CustomButton,
|
Spinner,
|
||||||
TextArea,
|
Banner,
|
||||||
|
Feedback,
|
||||||
},
|
},
|
||||||
mixins: [configMixin],
|
mixins: [alertMixin, configMixin],
|
||||||
|
props: {
|
||||||
|
showHomePage: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
message: '',
|
surveyDetails: null,
|
||||||
isSubmitted: false,
|
isLoading: false,
|
||||||
|
errorMessage: null,
|
||||||
|
selectedRating: null,
|
||||||
|
feedbackMessage: '',
|
||||||
|
isUpdating: false,
|
||||||
|
logo: '',
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
surveyId() {
|
||||||
|
const pageURL = window.location.href;
|
||||||
|
return pageURL.substr(pageURL.lastIndexOf('/') + 1);
|
||||||
|
},
|
||||||
|
isRatingSubmitted() {
|
||||||
|
return this.surveyDetails && this.surveyDetails.rating;
|
||||||
|
},
|
||||||
|
isFeedbackSubmitted() {
|
||||||
|
return this.surveyDetails && this.surveyDetails.feedback_message;
|
||||||
|
},
|
||||||
|
isButtonDisabled() {
|
||||||
|
return !(this.selectedRating && this.feedback);
|
||||||
|
},
|
||||||
|
shouldShowBanner() {
|
||||||
|
return this.isRatingSubmitted || this.errorMessage;
|
||||||
|
},
|
||||||
|
enableFeedbackForm() {
|
||||||
|
return !this.isFeedbackSubmitted && this.isRatingSubmitted;
|
||||||
|
},
|
||||||
|
shouldShowErrorMesage() {
|
||||||
|
return !!this.errorMessage;
|
||||||
|
},
|
||||||
|
shouldShowSuccessMesage() {
|
||||||
|
return !!this.isRatingSubmitted;
|
||||||
|
},
|
||||||
|
message() {
|
||||||
|
if (this.errorMessage) {
|
||||||
|
return this.errorMessage;
|
||||||
|
}
|
||||||
|
return this.$t('SURVEY.RATING.SUCCESS_MESSAGE');
|
||||||
|
},
|
||||||
|
surveyDescription() {
|
||||||
|
return this.isRatingSubmitted ? '' : this.$t('SURVEY.DESCRIPTION');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
async mounted() {
|
||||||
|
this.getSurveyDetails();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
selectRating(rating) {
|
||||||
|
this.selectedRating = rating;
|
||||||
|
this.updateSurveyDetails();
|
||||||
|
},
|
||||||
|
sendFeedback(message) {
|
||||||
|
this.feedbackMessage = message;
|
||||||
|
this.updateSurveyDetails();
|
||||||
|
},
|
||||||
|
imgUrlAlt() {
|
||||||
|
this.logo = BRAND_LOGO;
|
||||||
|
},
|
||||||
|
async getSurveyDetails() {
|
||||||
|
this.isLoading = true;
|
||||||
|
try {
|
||||||
|
const result = await getSurveyDetails({ uuid: this.surveyId });
|
||||||
|
this.logo = result.data.inbox_avatar_url;
|
||||||
|
this.surveyDetails = result?.data?.csat_survey_response;
|
||||||
|
this.selectedRating = this.surveyDetails?.rating;
|
||||||
|
this.feedbackMessage = this.surveyDetails?.feedback_message || '';
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = error?.response?.data?.message;
|
||||||
|
this.errorMessage = errorMessage || this.$t('SURVEY.API.ERROR_MESSAGE');
|
||||||
|
} finally {
|
||||||
|
this.isLoading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async updateSurveyDetails() {
|
||||||
|
this.isUpdating = true;
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
message: {
|
||||||
|
submitted_values: {
|
||||||
|
csat_survey_response: {
|
||||||
|
rating: this.selectedRating,
|
||||||
|
feedback_message: this.feedbackMessage,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await updateSurvey({
|
||||||
|
uuid: this.surveyId,
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
this.surveyDetails = {
|
||||||
|
rating: this.selectedRating,
|
||||||
|
feedback_message: this.feedbackMessage,
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
const errorMessage = error?.response?.data?.message;
|
||||||
|
this.errorMessage = errorMessage || this.$t('SURVEY.API.ERROR_MESSAGE');
|
||||||
|
} finally {
|
||||||
|
this.isUpdating = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ class AgentBotListener < BaseListener
|
||||||
def message_created(event)
|
def message_created(event)
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
inbox = message.inbox
|
inbox = message.inbox
|
||||||
return unless message.reportable? && inbox.agent_bot_inbox.present?
|
return unless message.webhook_sendable? && inbox.agent_bot_inbox.present?
|
||||||
return unless inbox.agent_bot_inbox.active?
|
return unless inbox.agent_bot_inbox.active?
|
||||||
|
|
||||||
agent_bot = inbox.agent_bot_inbox.agent_bot
|
agent_bot = inbox.agent_bot_inbox.agent_bot
|
||||||
|
@ -38,7 +38,7 @@ class AgentBotListener < BaseListener
|
||||||
def message_updated(event)
|
def message_updated(event)
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
inbox = message.inbox
|
inbox = message.inbox
|
||||||
return unless message.reportable? && inbox.agent_bot_inbox.present?
|
return unless message.webhook_sendable? && inbox.agent_bot_inbox.present?
|
||||||
return unless inbox.agent_bot_inbox.active?
|
return unless inbox.agent_bot_inbox.active?
|
||||||
|
|
||||||
agent_bot = inbox.agent_bot_inbox.agent_bot
|
agent_bot = inbox.agent_bot_inbox.agent_bot
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class HookListener < BaseListener
|
class HookListener < BaseListener
|
||||||
def message_created(event)
|
def message_created(event)
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
return unless message.reportable?
|
return unless message.webhook_sendable?
|
||||||
|
|
||||||
message.account.hooks.each do |hook|
|
message.account.hooks.each do |hook|
|
||||||
HookJob.perform_later(hook, event.name, message: message)
|
HookJob.perform_later(hook, event.name, message: message)
|
||||||
|
@ -10,7 +10,7 @@ class HookListener < BaseListener
|
||||||
|
|
||||||
def message_updated(event)
|
def message_updated(event)
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
return unless message.reportable?
|
return unless message.webhook_sendable?
|
||||||
|
|
||||||
message.account.hooks.each do |hook|
|
message.account.hooks.each do |hook|
|
||||||
HookJob.perform_later(hook, event.name, message: message)
|
HookJob.perform_later(hook, event.name, message: message)
|
||||||
|
|
|
@ -26,7 +26,7 @@ class WebhookListener < BaseListener
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
inbox = message.inbox
|
inbox = message.inbox
|
||||||
|
|
||||||
return unless message.reportable?
|
return unless message.webhook_sendable?
|
||||||
|
|
||||||
payload = message.webhook_data.merge(event: __method__.to_s)
|
payload = message.webhook_data.merge(event: __method__.to_s)
|
||||||
deliver_webhook_payloads(payload, inbox)
|
deliver_webhook_payloads(payload, inbox)
|
||||||
|
@ -36,7 +36,7 @@ class WebhookListener < BaseListener
|
||||||
message = extract_message_and_account(event)[0]
|
message = extract_message_and_account(event)[0]
|
||||||
inbox = message.inbox
|
inbox = message.inbox
|
||||||
|
|
||||||
return unless message.reportable?
|
return unless message.webhook_sendable?
|
||||||
|
|
||||||
payload = message.webhook_data.merge(event: __method__.to_s)
|
payload = message.webhook_data.merge(event: __method__.to_s)
|
||||||
deliver_webhook_payloads(payload, inbox)
|
deliver_webhook_payloads(payload, inbox)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class ConversationReplyMailer < ApplicationMailer
|
||||||
recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10)
|
recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10)
|
||||||
new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time)
|
new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time)
|
||||||
@messages = recap_messages + new_messages
|
@messages = recap_messages + new_messages
|
||||||
@messages = @messages.select(&:reportable?)
|
@messages = @messages.select(&:email_reply_summarizable?)
|
||||||
|
|
||||||
mail({
|
mail({
|
||||||
to: @contact&.email,
|
to: @contact&.email,
|
||||||
|
@ -29,7 +29,8 @@ class ConversationReplyMailer < ApplicationMailer
|
||||||
init_conversation_attributes(conversation)
|
init_conversation_attributes(conversation)
|
||||||
return if conversation_already_viewed?
|
return if conversation_already_viewed?
|
||||||
|
|
||||||
@messages = @conversation.messages.chat.outgoing.where('created_at >= ?', message_queued_time)
|
@messages = @conversation.messages.chat.where(message_type: [:outgoing, :template]).where('created_at >= ?', message_queued_time)
|
||||||
|
@messages = @messages.reject { |m| m.template? && !m.input_csat? }
|
||||||
return false if @messages.count.zero?
|
return false if @messages.count.zero?
|
||||||
|
|
||||||
mail({
|
mail({
|
||||||
|
@ -47,7 +48,7 @@ class ConversationReplyMailer < ApplicationMailer
|
||||||
|
|
||||||
init_conversation_attributes(conversation)
|
init_conversation_attributes(conversation)
|
||||||
|
|
||||||
@messages = @conversation.messages.chat.select(&:reportable?)
|
@messages = @conversation.messages.chat.select(&:conversation_transcriptable?)
|
||||||
|
|
||||||
mail({
|
mail({
|
||||||
to: to_email,
|
to: to_email,
|
||||||
|
|
19
app/models/concerns/message_filter_helpers.rb
Normal file
19
app/models/concerns/message_filter_helpers.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
module MessageFilterHelpers
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
|
def reportable?
|
||||||
|
incoming? || outgoing?
|
||||||
|
end
|
||||||
|
|
||||||
|
def webhook_sendable?
|
||||||
|
incoming? || outgoing?
|
||||||
|
end
|
||||||
|
|
||||||
|
def conversation_transcriptable?
|
||||||
|
incoming? || outgoing?
|
||||||
|
end
|
||||||
|
|
||||||
|
def email_reply_summarizable?
|
||||||
|
incoming? || outgoing? || input_csat?
|
||||||
|
end
|
||||||
|
end
|
|
@ -142,6 +142,10 @@ class Conversation < ApplicationRecord
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def tweet?
|
||||||
|
inbox.inbox_type == 'Twitter' && additional_attributes['type'] == 'tweet'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def ensure_snooze_until_reset
|
def ensure_snooze_until_reset
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class Message < ApplicationRecord
|
class Message < ApplicationRecord
|
||||||
|
include MessageFilterHelpers
|
||||||
NUMBER_OF_PERMITTED_ATTACHMENTS = 15
|
NUMBER_OF_PERMITTED_ATTACHMENTS = 15
|
||||||
|
|
||||||
validates :account_id, presence: true
|
validates :account_id, presence: true
|
||||||
|
@ -81,9 +82,6 @@ class Message < ApplicationRecord
|
||||||
has_many :attachments, dependent: :destroy, autosave: true, before_add: :validate_attachments_limit
|
has_many :attachments, dependent: :destroy, autosave: true, before_add: :validate_attachments_limit
|
||||||
has_one :csat_survey_response, dependent: :destroy
|
has_one :csat_survey_response, dependent: :destroy
|
||||||
|
|
||||||
after_create :reopen_conversation,
|
|
||||||
:notify_via_mail
|
|
||||||
|
|
||||||
after_create_commit :execute_after_create_commit_callbacks
|
after_create_commit :execute_after_create_commit_callbacks
|
||||||
|
|
||||||
after_update_commit :dispatch_update_event
|
after_update_commit :dispatch_update_event
|
||||||
|
@ -109,10 +107,6 @@ class Message < ApplicationRecord
|
||||||
data
|
data
|
||||||
end
|
end
|
||||||
|
|
||||||
def reportable?
|
|
||||||
incoming? || outgoing?
|
|
||||||
end
|
|
||||||
|
|
||||||
def webhook_data
|
def webhook_data
|
||||||
{
|
{
|
||||||
id: id,
|
id: id,
|
||||||
|
@ -130,10 +124,19 @@ class Message < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content
|
||||||
|
# move this to a presenter
|
||||||
|
return self[:content] if !input_csat? || inbox.web_widget?
|
||||||
|
|
||||||
|
I18n.t('conversations.survey.response', link: "#{ENV['FRONTEND_URL']}/survey/responses/#{conversation.uuid}")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def execute_after_create_commit_callbacks
|
def execute_after_create_commit_callbacks
|
||||||
# rails issue with order of active record callbacks being executed https://github.com/rails/rails/issues/20911
|
# rails issue with order of active record callbacks being executed https://github.com/rails/rails/issues/20911
|
||||||
|
reopen_conversation
|
||||||
|
notify_via_mail
|
||||||
set_conversation_activity
|
set_conversation_activity
|
||||||
dispatch_create_events
|
dispatch_create_events
|
||||||
send_reply
|
send_reply
|
||||||
|
@ -175,7 +178,7 @@ class Message < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def email_notifiable_message?
|
def email_notifiable_message?
|
||||||
return false unless outgoing?
|
return false unless outgoing? || input_csat?
|
||||||
return false if private?
|
return false if private?
|
||||||
|
|
||||||
true
|
true
|
||||||
|
|
|
@ -46,17 +46,18 @@ class MessageTemplates::HookExecutionService
|
||||||
contact.email
|
contact.email
|
||||||
end
|
end
|
||||||
|
|
||||||
def csat_enabled_inbox?
|
def csat_enabled_conversation?
|
||||||
# for now csat only available in web widget channel
|
return false unless conversation.resolved?
|
||||||
return unless inbox.web_widget?
|
# should not sent since the link will be public
|
||||||
return unless inbox.csat_survey_enabled?
|
return false if conversation.tweet?
|
||||||
|
return false unless inbox.csat_survey_enabled?
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_send_csat_survey?
|
def should_send_csat_survey?
|
||||||
return unless conversation.resolved?
|
return unless csat_enabled_conversation?
|
||||||
return unless csat_enabled_inbox?
|
|
||||||
# only send CSAT once in a conversation
|
# only send CSAT once in a conversation
|
||||||
return if conversation.messages.where(content_type: :input_csat).present?
|
return if conversation.messages.where(content_type: :input_csat).present?
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,8 @@ en:
|
||||||
reply:
|
reply:
|
||||||
email_subject: "New messages on this conversation"
|
email_subject: "New messages on this conversation"
|
||||||
transcript_subject: "Conversation Transcript"
|
transcript_subject: "Conversation Transcript"
|
||||||
|
survey:
|
||||||
|
response: "Please rate this conversation, %{link}"
|
||||||
|
|
||||||
integration_apps:
|
integration_apps:
|
||||||
slack:
|
slack:
|
||||||
|
|
|
@ -20,6 +20,7 @@ class Integrations::Dialogflow::ProcessorService
|
||||||
end
|
end
|
||||||
|
|
||||||
def processable_message?(message)
|
def processable_message?(message)
|
||||||
|
# TODO: change from reportable and create a dedicated method for this?
|
||||||
return unless message.reportable?
|
return unless message.reportable?
|
||||||
return if message.outgoing? && !processable_outgoing_message?(message)
|
return if message.outgoing? && !processable_outgoing_message?(message)
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
"start:dev": "foreman start -f ./Procfile.dev",
|
"start:dev": "foreman start -f ./Procfile.dev",
|
||||||
"start:dev-overmind": "overmind start -f ./Procfile.dev",
|
"start:dev-overmind": "overmind start -f ./Procfile.dev",
|
||||||
"storybook": "start-storybook -p 6006",
|
"storybook": "start-storybook -p 6006",
|
||||||
"build-storybook": "build-storybook"
|
"build-storybook": "build-storybook",
|
||||||
|
"ruby:prettier":"bundle exec rubocop -a"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braid/vue-formulate": "^2.5.2",
|
"@braid/vue-formulate": "^2.5.2",
|
||||||
|
|
|
@ -114,9 +114,10 @@ describe ::MessageTemplates::HookExecutionService do
|
||||||
expect(csat_survey).not_to have_received(:perform)
|
expect(csat_survey).not_to have_received(:perform)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not call ::MessageTemplates::Template::CsatSurvey if its not a website widget' do
|
it 'will not call ::MessageTemplates::Template::CsatSurvey if its a tweet conversation' do
|
||||||
api_channel = create(:channel_api)
|
twitter_channel = create(:channel_twitter_profile)
|
||||||
conversation = create(:conversation, inbox: create(:inbox, channel: api_channel))
|
twitter_inbox = create(:inbox, channel: twitter_channel)
|
||||||
|
conversation = create(:conversation, inbox: twitter_inbox, additional_attributes: { type: 'tweet' })
|
||||||
conversation.inbox.update(csat_survey_enabled: true)
|
conversation.inbox.update(csat_survey_enabled: true)
|
||||||
|
|
||||||
conversation.resolved!
|
conversation.resolved!
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue