2019-10-29 07:20:54 +00:00
|
|
|
<template>
|
|
|
|
<div class="agent-message">
|
|
|
|
<div class="avatar-wrap">
|
2019-12-15 18:23:04 +00:00
|
|
|
<thumbnail
|
2020-03-22 10:24:36 +00:00
|
|
|
v-if="message.showAvatar"
|
2019-12-15 18:23:04 +00:00
|
|
|
:src="avatarUrl"
|
|
|
|
size="24px"
|
|
|
|
:username="agentName"
|
|
|
|
/>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
<div class="message-wrap">
|
2020-01-09 07:36:40 +00:00
|
|
|
<AgentMessageBubble
|
2020-03-22 10:24:36 +00:00
|
|
|
v-if="showTextBubble"
|
2020-01-09 07:36:40 +00:00
|
|
|
:content-type="contentType"
|
|
|
|
:message-content-attributes="messageContentAttributes"
|
2020-03-22 10:24:36 +00:00
|
|
|
:message-id="message.id"
|
2020-01-09 07:36:40 +00:00
|
|
|
:message-type="messageType"
|
2020-03-22 10:24:36 +00:00
|
|
|
:message="message.content"
|
2020-01-09 07:36:40 +00:00
|
|
|
/>
|
2020-03-30 06:45:06 +00:00
|
|
|
<div v-if="hasImage" class="chat-bubble has-attachment agent">
|
2020-03-22 10:24:36 +00:00
|
|
|
<image-bubble
|
|
|
|
:url="message.attachment.data_url"
|
2020-03-30 06:45:06 +00:00
|
|
|
:thumb="message.attachment.thumb_url"
|
2020-03-22 10:24:36 +00:00
|
|
|
:readable-time="readableTime"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<p v-if="message.showAvatar" class="agent-name">
|
2019-12-15 18:23:04 +00:00
|
|
|
{{ agentName }}
|
|
|
|
</p>
|
2019-10-29 07:20:54 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
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';
|
|
|
|
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,
|
2019-12-15 18:23:04 +00:00
|
|
|
Thumbnail,
|
2020-03-22 10:24:36 +00:00
|
|
|
ImageBubble,
|
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-03-30 06:45:06 +00:00
|
|
|
hasImage() {
|
|
|
|
const { attachment = {} } = this.message;
|
|
|
|
const { file_type: fileType } = attachment;
|
|
|
|
return fileType === 'image';
|
|
|
|
},
|
2020-03-22 10:24:36 +00:00
|
|
|
showTextBubble() {
|
|
|
|
const { message } = this;
|
2020-03-30 06:45:06 +00:00
|
|
|
return !!message.content;
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.message.sender ? this.message.sender.name : '';
|
|
|
|
},
|
|
|
|
avatarUrl() {
|
|
|
|
if (this.message.message_type === MESSAGE_TYPE.TEMPLATE) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
return require('dashboard/assets/images/chatwoot_bot.png');
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.message.sender ? this.message.sender.avatar_url : '';
|
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-03-22 10:24:36 +00:00
|
|
|
<style lang="scss" scoped>
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<style lang="scss">
|
|
|
|
@import '~widget/assets/scss/variables.scss';
|
|
|
|
|
|
|
|
.conversation-wrap {
|
|
|
|
.agent-message {
|
|
|
|
+ .agent-message {
|
|
|
|
margin-bottom: $space-micro;
|
|
|
|
|
|
|
|
.chat-bubble {
|
|
|
|
border-top-left-radius: $space-smaller;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ .user-message {
|
|
|
|
margin-top: $space-normal;
|
|
|
|
}
|
|
|
|
}
|
2019-10-29 07:20:54 +00:00
|
|
|
}
|
|
|
|
</style>
|