2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
2020-05-02 04:17:36 +00:00
|
|
|
<div
|
|
|
|
class="agent-message-wrap"
|
|
|
|
:class="{ 'has-response': hasRecordedResponse }"
|
|
|
|
>
|
2020-04-10 11:12:37 +00:00
|
|
|
<div class="agent-message">
|
|
|
|
<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
|
2020-04-17 15:45:20 +00:00
|
|
|
v-if="!hasAttachments && 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
|
|
|
/>
|
2020-04-17 15:45:20 +00:00
|
|
|
<div v-if="hasAttachments" class="chat-bubble has-attachment agent">
|
|
|
|
<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" />
|
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';
|
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-03-22 10:24:36 +00:00
|
|
|
mixins: [timeMixin],
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
return this.messageStamp(createdAt);
|
|
|
|
},
|
|
|
|
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-04-10 11:12:37 +00:00
|
|
|
return this.message.sender ? this.message.sender.name : '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-03-22 10:24:36 +00:00
|
|
|
if (this.message.message_type === MESSAGE_TYPE.TEMPLATE) {
|
2020-04-10 11:12:37 +00:00
|
|
|
return BotImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.message.sender ? this.message.sender.avatar_url : BotImage;
|
|
|
|
},
|
|
|
|
hasRecordedResponse() {
|
|
|
|
return (
|
|
|
|
this.messageContentAttributes.submitted_email ||
|
|
|
|
(this.messageContentAttributes.submitted_values &&
|
|
|
|
this.contentType !== 'form')
|
|
|
|
);
|
|
|
|
},
|
|
|
|
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
|
|
|
},
|
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;
|
|
|
|
}
|
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-03-22 10:24:36 +00:00
|
|
|
}
|
|
|
|
</style>
|