2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2020-05-02 04:17:36 +00:00
|
|
|
<div
|
|
|
|
class="agent-message-wrap"
|
2020-05-17 17:19:45 +00:00
|
|
|
:class="{ 'has-response': hasRecordedResponse || isASubmittedForm }"
|
2020-05-02 04:17:36 +00:00
|
|
|
>
|
2020-05-17 17:19:45 +00:00
|
|
|
<div v-if="!isASubmittedForm" class="agent-message">
|
2020-04-10 11:12:37 +00:00
|
|
|
<div class="avatar-wrap">
|
|
|
|
<thumbnail
|
|
|
|
v-if="message.showAvatar || hasRecordedResponse"
|
|
|
|
:src="avatarUrl"
|
|
|
|
size="24px"
|
|
|
|
:username="agentName"
|
2020-04-02 06:58:38 +00:00
|
|
|
/>
|
2020-04-10 11:12:37 +00:00
|
|
|
</div>
|
|
|
|
<div class="message-wrap">
|
|
|
|
<AgentMessageBubble
|
2021-01-06 12:26:29 +00:00
|
|
|
v-if="shouldDisplayAgentMessage"
|
2020-04-10 11:12:37 +00:00
|
|
|
:content-type="contentType"
|
|
|
|
:message-content-attributes="messageContentAttributes"
|
|
|
|
:message-id="message.id"
|
|
|
|
:message-type="messageType"
|
|
|
|
:message="message.content"
|
2020-03-22 10:24:36 +00:00
|
|
|
/>
|
2021-01-06 12:26:29 +00:00
|
|
|
<div
|
|
|
|
v-if="hasAttachments"
|
|
|
|
class="chat-bubble has-attachment agent"
|
2022-04-01 15:29:03 +00:00
|
|
|
:class="(wrapClass, $dm('bg-white', 'dark:bg-slate-50'))"
|
2021-01-06 12:26:29 +00:00
|
|
|
>
|
2020-04-17 15:45:20 +00:00
|
|
|
<div v-for="attachment in message.attachments" :key="attachment.id">
|
|
|
|
<image-bubble
|
2021-12-21 06:32:43 +00:00
|
|
|
v-if="attachment.file_type === 'image' && !hasImageError"
|
2020-04-17 15:45:20 +00:00
|
|
|
:url="attachment.data_url"
|
2022-06-23 13:47:46 +00:00
|
|
|
:thumb="attachment.data_url"
|
2020-04-17 15:45:20 +00:00
|
|
|
:readable-time="readableTime"
|
2021-12-21 06:32:43 +00:00
|
|
|
@error="onImageLoadError"
|
2020-04-17 15:45:20 +00:00
|
|
|
/>
|
2022-03-24 07:14:34 +00:00
|
|
|
<audio v-else-if="attachment.file_type === 'audio'" controls>
|
|
|
|
<source :src="attachment.data_url" />
|
|
|
|
</audio>
|
2021-12-21 06:32:43 +00:00
|
|
|
<file-bubble v-else :url="attachment.data_url" />
|
2020-04-17 15:45:20 +00:00
|
|
|
</div>
|
2020-04-10 11:12:37 +00:00
|
|
|
</div>
|
2022-04-01 15:29:03 +00:00
|
|
|
<p
|
|
|
|
v-if="message.showAvatar || hasRecordedResponse"
|
|
|
|
class="agent-name"
|
|
|
|
:class="$dm('text-slate-700', 'dark:text-slate-200')"
|
|
|
|
>
|
2020-04-10 11:12:37 +00:00
|
|
|
{{ agentName }}
|
|
|
|
</p>
|
2020-03-22 10:24:36 +00:00
|
|
|
</div>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
2020-04-10 11:12:37 +00:00
|
|
|
|
|
|
|
<UserMessage v-if="hasRecordedResponse" :message="responseMessage" />
|
2020-05-17 17:19:45 +00:00
|
|
|
<div v-if="isASubmittedForm">
|
|
|
|
<UserMessage
|
|
|
|
v-for="submittedValue in submittedFormValues"
|
|
|
|
:key="submittedValue.id"
|
|
|
|
:message="submittedValue"
|
|
|
|
/>
|
|
|
|
</div>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-04-10 11:12:37 +00:00
|
|
|
import UserMessage from 'widget/components/UserMessage';
|
2020-03-22 10:24:36 +00:00
|
|
|
import AgentMessageBubble from 'widget/components/AgentMessageBubble';
|
|
|
|
import timeMixin from 'dashboard/mixins/time';
|
|
|
|
import ImageBubble from 'widget/components/ImageBubble';
|
2020-04-02 06:58:38 +00:00
|
|
|
import FileBubble from 'widget/components/FileBubble';
|
2020-03-22 10:24:36 +00:00
|
|
|
import Thumbnail from 'dashboard/components/widgets/Thumbnail';
|
|
|
|
import { MESSAGE_TYPE } from 'widget/helpers/constants';
|
2020-05-09 16:32:43 +00:00
|
|
|
import configMixin from '../mixins/configMixin';
|
2021-07-15 08:57:37 +00:00
|
|
|
import messageMixin from '../mixins/messageMixin';
|
2020-05-17 17:19:45 +00:00
|
|
|
import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper';
|
2022-04-01 15:29:03 +00:00
|
|
|
import darkModeMixin from 'widget/mixins/darkModeMixin.js';
|
|
|
|
|
2019-10-29 07:20:54 +00:00
|
|
|
export default {
|
|
|
|
name: 'AgentMessage',
|
|
|
|
components: {
|
|
|
|
AgentMessageBubble,
|
2020-03-22 10:24:36 +00:00
|
|
|
ImageBubble,
|
2020-04-10 11:12:37 +00:00
|
|
|
Thumbnail,
|
|
|
|
UserMessage,
|
2020-04-02 06:58:38 +00:00
|
|
|
FileBubble,
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2022-04-01 15:29:03 +00:00
|
|
|
mixins: [timeMixin, configMixin, messageMixin, darkModeMixin],
|
2019-10-29 07:20:54 +00:00
|
|
|
props: {
|
2020-03-22 10:24:36 +00:00
|
|
|
message: {
|
2020-01-09 07:36:40 +00:00
|
|
|
type: Object,
|
|
|
|
default: () => {},
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
},
|
2021-12-21 06:32:43 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
hasImageError: false,
|
|
|
|
};
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
computed: {
|
2020-04-10 11:12:37 +00:00
|
|
|
shouldDisplayAgentMessage() {
|
|
|
|
if (
|
|
|
|
this.contentType === 'input_select' &&
|
|
|
|
this.messageContentAttributes.submitted_values &&
|
|
|
|
!this.message.content
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-01-06 12:26:29 +00:00
|
|
|
if (!this.message.content) return false;
|
2020-04-10 11:12:37 +00:00
|
|
|
return true;
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
readableTime() {
|
|
|
|
const { created_at: createdAt = '' } = this.message;
|
2021-07-14 14:45:57 +00:00
|
|
|
return this.messageStamp(createdAt, 'LLL d yyyy, h:mm a');
|
2020-03-22 10:24:36 +00:00
|
|
|
},
|
|
|
|
messageType() {
|
|
|
|
const { message_type: type = 1 } = this.message;
|
|
|
|
return type;
|
|
|
|
},
|
|
|
|
contentType() {
|
|
|
|
const { content_type: type = '' } = this.message;
|
|
|
|
return type;
|
|
|
|
},
|
|
|
|
agentName() {
|
|
|
|
if (this.message.message_type === MESSAGE_TYPE.TEMPLATE) {
|
|
|
|
return 'Bot';
|
|
|
|
}
|
2020-08-01 13:00:47 +00:00
|
|
|
if (this.message.sender) {
|
|
|
|
return this.message.sender.available_name || this.message.sender.name;
|
|
|
|
}
|
|
|
|
return 'Bot';
|
2020-03-22 10:24:36 +00:00
|
|
|
},
|
|
|
|
avatarUrl() {
|
2020-04-10 11:12:37 +00:00
|
|
|
// eslint-disable-next-line
|
2020-05-02 04:17:36 +00:00
|
|
|
const BotImage = require('dashboard/assets/images/chatwoot_bot.png');
|
2020-05-09 16:32:43 +00:00
|
|
|
const displayImage = this.useInboxAvatarForBot
|
|
|
|
? this.inboxAvatarUrl
|
|
|
|
: BotImage;
|
|
|
|
|
2020-03-22 10:24:36 +00:00
|
|
|
if (this.message.message_type === MESSAGE_TYPE.TEMPLATE) {
|
2020-05-09 16:32:43 +00:00
|
|
|
return displayImage;
|
2020-04-10 11:12:37 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 16:32:43 +00:00
|
|
|
return this.message.sender
|
|
|
|
? this.message.sender.avatar_url
|
|
|
|
: displayImage;
|
2020-04-10 11:12:37 +00:00
|
|
|
},
|
|
|
|
hasRecordedResponse() {
|
|
|
|
return (
|
|
|
|
this.messageContentAttributes.submitted_email ||
|
|
|
|
(this.messageContentAttributes.submitted_values &&
|
2021-06-25 06:30:49 +00:00
|
|
|
!['form', 'input_csat'].includes(this.contentType))
|
2020-04-10 11:12:37 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
responseMessage() {
|
|
|
|
if (this.messageContentAttributes.submitted_email) {
|
|
|
|
return { content: this.messageContentAttributes.submitted_email };
|
2020-03-22 10:24:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 11:12:37 +00:00
|
|
|
if (this.messageContentAttributes.submitted_values) {
|
|
|
|
if (this.contentType === 'input_select') {
|
2021-11-19 10:39:20 +00:00
|
|
|
const [
|
|
|
|
selectionOption = {},
|
|
|
|
] = this.messageContentAttributes.submitted_values;
|
2020-04-10 11:12:37 +00:00
|
|
|
return { content: selectionOption.title || selectionOption.value };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return '';
|
2020-01-09 07:36:40 +00:00
|
|
|
},
|
2020-05-17 17:19:45 +00:00
|
|
|
isASubmittedForm() {
|
|
|
|
return isASubmittedFormMessage(this.message);
|
|
|
|
},
|
|
|
|
submittedFormValues() {
|
|
|
|
return this.messageContentAttributes.submitted_values.map(
|
|
|
|
submittedValue => ({
|
|
|
|
id: submittedValue.name,
|
|
|
|
content: submittedValue.value,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
},
|
2021-01-06 12:26:29 +00:00
|
|
|
wrapClass() {
|
|
|
|
return {
|
|
|
|
'has-text': this.shouldDisplayAgentMessage,
|
|
|
|
};
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
},
|
2021-12-21 06:32:43 +00:00
|
|
|
watch: {
|
|
|
|
message() {
|
|
|
|
this.hasImageError = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.hasImageError = false;
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onImageLoadError() {
|
|
|
|
this.hasImageError = true;
|
|
|
|
},
|
|
|
|
},
|
2019-10-29 07:20:54 +00:00
|
|
|
};
|
|
|
|
</script>
|