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"
|
|
|
|
:class="wrapClass"
|
|
|
|
>
|
2020-04-17 15:45:20 +00:00
|
|
|
<div v-for="attachment in message.attachments" :key="attachment.id">
|
|
|
|
<file-bubble
|
|
|
|
v-if="attachment.file_type !== 'image'"
|
|
|
|
:url="attachment.data_url"
|
|
|
|
/>
|
|
|
|
<image-bubble
|
|
|
|
v-else
|
|
|
|
:url="attachment.data_url"
|
|
|
|
:thumb="attachment.thumb_url"
|
|
|
|
:readable-time="readableTime"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-04-10 11:12:37 +00:00
|
|
|
</div>
|
|
|
|
<p v-if="message.showAvatar || hasRecordedResponse" class="agent-name">
|
|
|
|
{{ 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';
|
2020-05-17 17:19:45 +00:00
|
|
|
import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper';
|
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
|
|
|
},
|
2020-05-09 16:32:43 +00:00
|
|
|
mixins: [timeMixin, configMixin],
|
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
|
|
|
},
|
|
|
|
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-04-17 15:45:20 +00:00
|
|
|
hasAttachments() {
|
|
|
|
return !!(
|
|
|
|
this.message.attachments && this.message.attachments.length > 0
|
|
|
|
);
|
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;
|
|
|
|
},
|
|
|
|
messageContentAttributes() {
|
|
|
|
const { content_attributes: attribute = {} } = this.message;
|
|
|
|
return attribute;
|
2020-01-09 07:36:40 +00:00
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
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') {
|
|
|
|
const [
|
|
|
|
selectionOption = {},
|
|
|
|
] = this.messageContentAttributes.submitted_values;
|
|
|
|
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
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
2020-04-10 11:12:37 +00:00
|
|
|
<style lang="scss">
|
2019-10-29 07:20:54 +00:00
|
|
|
@import '~widget/assets/scss/variables.scss';
|
2020-03-22 10:24:36 +00:00
|
|
|
|
2019-11-27 06:15:33 +00:00
|
|
|
.conversation-wrap {
|
|
|
|
.agent-message {
|
2019-12-15 18:23:04 +00:00
|
|
|
align-items: flex-end;
|
2019-11-27 06:15:33 +00:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
margin: 0 0 $space-micro $space-small;
|
|
|
|
max-width: 88%;
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2019-11-27 06:15:33 +00:00
|
|
|
.avatar-wrap {
|
2019-12-15 18:23:04 +00:00
|
|
|
height: $space-medium;
|
|
|
|
width: $space-medium;
|
2020-03-07 18:09:41 +00:00
|
|
|
flex-shrink: 0;
|
2019-12-15 18:23:04 +00:00
|
|
|
|
|
|
|
.user-thumbnail-box {
|
|
|
|
margin-top: -$space-large;
|
|
|
|
}
|
2019-11-27 06:15:33 +00:00
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
|
2019-11-27 06:15:33 +00:00
|
|
|
.message-wrap {
|
|
|
|
flex-grow: 1;
|
2019-12-15 18:23:04 +00:00
|
|
|
flex-shrink: 0;
|
2019-11-27 06:15:33 +00:00
|
|
|
margin-left: $space-small;
|
2019-12-15 18:23:04 +00:00
|
|
|
max-width: 90%;
|
2019-10-29 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-15 18:23:04 +00:00
|
|
|
|
|
|
|
.agent-name {
|
|
|
|
color: $color-body;
|
2020-01-17 08:06:05 +00:00
|
|
|
font-size: $font-size-small;
|
2019-12-15 18:23:04 +00:00
|
|
|
font-weight: $font-weight-medium;
|
2020-01-17 08:06:05 +00:00
|
|
|
margin: $space-small 0;
|
|
|
|
padding-left: $space-micro;
|
2019-12-15 18:23:04 +00:00
|
|
|
}
|
2020-03-22 10:24:36 +00:00
|
|
|
|
|
|
|
.has-attachment {
|
|
|
|
padding: 0;
|
|
|
|
overflow: hidden;
|
2021-01-06 12:26:29 +00:00
|
|
|
|
|
|
|
&.has-text {
|
|
|
|
margin-top: $space-smaller;
|
|
|
|
}
|
2020-03-22 10:24:36 +00:00
|
|
|
}
|
2020-05-02 04:17:36 +00:00
|
|
|
|
|
|
|
.agent-message-wrap {
|
|
|
|
+ .agent-message-wrap {
|
|
|
|
margin-top: $space-micro;
|
|
|
|
|
|
|
|
.agent-message .chat-bubble {
|
|
|
|
border-top-left-radius: $space-smaller;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ .user-message-wrap {
|
|
|
|
margin-top: $space-normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.has-response + .user-message-wrap {
|
|
|
|
margin-top: $space-micro;
|
|
|
|
.chat-bubble {
|
|
|
|
border-top-right-radius: $space-smaller;
|
|
|
|
}
|
|
|
|
}
|
2020-05-17 17:19:45 +00:00
|
|
|
|
|
|
|
&.has-response + .agent-message-wrap {
|
|
|
|
margin-top: $space-normal;
|
|
|
|
}
|
2020-05-02 04:17:36 +00:00
|
|
|
}
|
2020-03-22 10:24:36 +00:00
|
|
|
}
|
|
|
|
</style>
|