Some checks failed
Lock Threads / action (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot EE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot EE docker images / merge (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Publish Chatwoot CE docker images / build (linux/arm64, ubuntu-22.04-arm) (push) Has been cancelled
Publish Chatwoot CE docker images / merge (push) Has been cancelled
Run Chatwoot CE spec / lint-backend (push) Has been cancelled
Run Chatwoot CE spec / lint-frontend (push) Has been cancelled
Run Chatwoot CE spec / frontend-tests (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (0, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (1, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (10, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (11, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (12, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (13, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (14, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (15, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (2, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (3, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (4, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (5, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (6, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (7, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (8, 16) (push) Has been cancelled
Run Chatwoot CE spec / backend-tests (9, 16) (push) Has been cancelled
Run Linux nightly installer / nightly (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
## 新增功能
### 1. 新增消息类型
- 添加 search_image (17) 和 product_list (18) content_type
- 支持图片搜索和商品列表消息展示
### 2. 图片上传功能
- 添加 ImageUploadButton 组件,支持图片上传到 Mall API
- 上传后发送 search_image 类型消息,图片 URL 存储在 content_attributes
- 支持图片文件验证(类型、大小)
### 3. Webhook 推送优化
- 修改 webhook_listener.rb,允许 search_image 类型即使 content 为空也推送 webhook
- 解决 search_image 消息不触发 webhook 的问题
### 4. 前端组件
- 新增 SearchImage.vue 组件(widget 和 dashboard)
- 新增 ProductList.vue、Logistics.vue、OrderDetail.vue、OrderList.vue 组件
- 更新 Message.vue 路由逻辑支持新的 content_type
- 更新 UserMessage.vue 支持 search_image 消息显示
### 5. API 层修改
- widget/messages_controller.rb: 允许 content_attributes 参数
- widget/base_controller.rb: 使用前端传入的 content_attributes
- widget/conversation API: 支持 contentAttributes 参数传递
- conversation actions 和 helpers: 完整的 content_attributes 数据流
### 6. Widget 测试页面优化
- 重写 /widget_tests 页面,支持游客/用户模式切换
- 登录流程:使用 reset() + setUser(),不刷新页面
- 退出流程:使用 reset() + 刷新页面
- 添加详细的日志输出和状态显示
## 技术细节
### Message Model
```ruby
enum content_type: {
# ...existing types...
search_image: 17,
product_list: 18
}
```
### Webhook Listener
```ruby
# Allow search_image webhook even if content is blank
return if message.content.blank? && message.content_type != 'search_image'
```
### Widget Upload Flow
```
用户选择图片
→ 上传到 Mall API
→ 获取图片 URL
→ 发送消息: { content: '', content_type: 'search_image', content_attributes: { url: '...' } }
```
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
263 lines
7.8 KiB
Vue
Executable File
263 lines
7.8 KiB
Vue
Executable File
<script>
|
|
import UserMessage from 'widget/components/UserMessage.vue';
|
|
import AgentMessageBubble from 'widget/components/AgentMessageBubble.vue';
|
|
import MessageReplyButton from 'widget/components/MessageReplyButton.vue';
|
|
import { messageStamp } from 'shared/helpers/timeHelper';
|
|
import ImageBubble from 'widget/components/ImageBubble.vue';
|
|
import VideoBubble from 'widget/components/VideoBubble.vue';
|
|
import FileBubble from 'widget/components/FileBubble.vue';
|
|
import Avatar from 'dashboard/components-next/avatar/Avatar.vue';
|
|
import { MESSAGE_TYPE } from 'widget/helpers/constants';
|
|
import configMixin from '../mixins/configMixin';
|
|
import messageMixin from '../mixins/messageMixin';
|
|
import { isASubmittedFormMessage } from 'shared/helpers/MessageTypeHelper';
|
|
import ReplyToChip from 'widget/components/ReplyToChip.vue';
|
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
|
import { emitter } from 'shared/helpers/mitt';
|
|
|
|
export default {
|
|
name: 'AgentMessage',
|
|
components: {
|
|
AgentMessageBubble,
|
|
ImageBubble,
|
|
VideoBubble,
|
|
Avatar,
|
|
UserMessage,
|
|
FileBubble,
|
|
MessageReplyButton,
|
|
ReplyToChip,
|
|
},
|
|
mixins: [configMixin, messageMixin],
|
|
props: {
|
|
message: {
|
|
type: Object,
|
|
default: () => {},
|
|
},
|
|
replyTo: {
|
|
type: Object,
|
|
default: () => {},
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
hasImageError: false,
|
|
hasVideoError: false,
|
|
};
|
|
},
|
|
computed: {
|
|
shouldDisplayAgentMessage() {
|
|
if (
|
|
this.contentType === 'input_select' &&
|
|
this.messageContentAttributes.submitted_values &&
|
|
!this.message.content
|
|
) {
|
|
return false;
|
|
}
|
|
// Table, order_list, order_detail, logistics and product_list messages can have empty content, so check content_type as well
|
|
if (this.contentType === 'data_table' || this.contentType === 'order_list' || this.contentType === 'order_detail' || this.contentType === 'logistics' || this.contentType === 'product_list') {
|
|
return true;
|
|
}
|
|
return this.message.content;
|
|
},
|
|
readableTime() {
|
|
const { created_at: createdAt = '' } = this.message;
|
|
return messageStamp(createdAt, 'LLL d yyyy, h:mm a');
|
|
},
|
|
messageType() {
|
|
const { message_type: type = 1 } = this.message;
|
|
return type;
|
|
},
|
|
contentType() {
|
|
const { content_type: type = '' } = this.message;
|
|
return type;
|
|
},
|
|
agentName() {
|
|
if (this.message.sender) {
|
|
return this.message.sender.available_name || this.message.sender.name;
|
|
}
|
|
|
|
if (this.useInboxAvatarForBot) {
|
|
return this.channelConfig.websiteName;
|
|
}
|
|
|
|
return this.$t('UNREAD_VIEW.BOT');
|
|
},
|
|
avatarUrl() {
|
|
const displayImage = this.useInboxAvatarForBot
|
|
? this.inboxAvatarUrl
|
|
: '/assets/images/chatwoot_bot.png';
|
|
|
|
if (this.message.message_type === MESSAGE_TYPE.TEMPLATE) {
|
|
return displayImage;
|
|
}
|
|
|
|
return this.message.sender
|
|
? this.message.sender.avatar_url
|
|
: displayImage;
|
|
},
|
|
hasRecordedResponse() {
|
|
return (
|
|
this.messageContentAttributes.submitted_email ||
|
|
(this.messageContentAttributes.submitted_values &&
|
|
!['form', 'input_csat'].includes(this.contentType))
|
|
);
|
|
},
|
|
responseMessage() {
|
|
if (this.messageContentAttributes.submitted_email) {
|
|
return { content: this.messageContentAttributes.submitted_email };
|
|
}
|
|
|
|
if (this.messageContentAttributes.submitted_values) {
|
|
if (this.contentType === 'input_select') {
|
|
const [selectionOption = {}] =
|
|
this.messageContentAttributes.submitted_values;
|
|
return { content: selectionOption.title || selectionOption.value };
|
|
}
|
|
}
|
|
return '';
|
|
},
|
|
isASubmittedForm() {
|
|
return isASubmittedFormMessage(this.message);
|
|
},
|
|
submittedFormValues() {
|
|
return this.messageContentAttributes.submitted_values.map(
|
|
submittedValue => ({
|
|
id: submittedValue.name,
|
|
content: submittedValue.value,
|
|
})
|
|
);
|
|
},
|
|
wrapClass() {
|
|
return {
|
|
'has-text': this.shouldDisplayAgentMessage,
|
|
};
|
|
},
|
|
hasReplyTo() {
|
|
return this.replyTo && (this.replyTo.content || this.replyTo.attachments);
|
|
},
|
|
},
|
|
watch: {
|
|
message() {
|
|
this.hasImageError = false;
|
|
this.hasVideoError = false;
|
|
},
|
|
},
|
|
mounted() {
|
|
this.hasImageError = false;
|
|
this.hasVideoError = false;
|
|
},
|
|
methods: {
|
|
onImageLoadError() {
|
|
this.hasImageError = true;
|
|
},
|
|
onVideoLoadError() {
|
|
this.hasVideoError = true;
|
|
},
|
|
toggleReply() {
|
|
emitter.emit(BUS_EVENTS.TOGGLE_REPLY_TO_MESSAGE, this.message);
|
|
},
|
|
},
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div
|
|
class="agent-message-wrap group"
|
|
:class="{
|
|
'has-response': hasRecordedResponse || isASubmittedForm,
|
|
}"
|
|
>
|
|
<div v-if="!isASubmittedForm" class="agent-message">
|
|
<div class="avatar-wrap" style="display: none;">
|
|
<div class="user-thumbnail-box">
|
|
<Avatar
|
|
v-if="message.showAvatar || hasRecordedResponse"
|
|
:src="avatarUrl"
|
|
:size="24"
|
|
:name="agentName"
|
|
rounded-full
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div class="message-wrap">
|
|
<div v-if="hasReplyTo" class="flex mt-2 mb-1 text-xs">
|
|
<ReplyToChip :reply-to="replyTo" />
|
|
</div>
|
|
<div class="flex w-full gap-1">
|
|
<div
|
|
class="space-y-2 max-w-full"
|
|
:class="{
|
|
'w-full':
|
|
contentType === 'form' &&
|
|
!messageContentAttributes?.submitted_values,
|
|
}"
|
|
>
|
|
<AgentMessageBubble
|
|
v-if="shouldDisplayAgentMessage"
|
|
:content-type="contentType"
|
|
:message-content-attributes="messageContentAttributes"
|
|
:message-id="message.id"
|
|
:message-type="messageType"
|
|
:message="message.content"
|
|
/>
|
|
<div
|
|
v-if="hasAttachments"
|
|
class="space-y-2 chat-bubble has-attachment agent bg-n-background dark:bg-n-solid-3"
|
|
:class="wrapClass"
|
|
>
|
|
<div
|
|
v-for="attachment in message.attachments"
|
|
:key="attachment.id"
|
|
>
|
|
<ImageBubble
|
|
v-if="attachment.file_type === 'image' && !hasImageError"
|
|
:url="attachment.data_url"
|
|
:thumb="attachment.data_url"
|
|
:readable-time="readableTime"
|
|
@error="onImageLoadError"
|
|
/>
|
|
|
|
<VideoBubble
|
|
v-if="attachment.file_type === 'video' && !hasVideoError"
|
|
:url="attachment.data_url"
|
|
:readable-time="readableTime"
|
|
@error="onVideoLoadError"
|
|
/>
|
|
|
|
<audio
|
|
v-else-if="attachment.file_type === 'audio'"
|
|
controls
|
|
class="h-10 dark:invert"
|
|
>
|
|
<source :src="attachment.data_url" />
|
|
</audio>
|
|
<FileBubble v-else :url="attachment.data_url" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="flex flex-col justify-end">
|
|
<MessageReplyButton
|
|
class="transition-opacity delay-75 opacity-0 group-hover:opacity-100 sm:opacity-0"
|
|
@click="toggleReply"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<p
|
|
v-if="message.showAvatar || hasRecordedResponse"
|
|
v-dompurify-html="agentName"
|
|
class="agent-name text-n-slate-11"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<UserMessage v-if="hasRecordedResponse" :message="responseMessage" />
|
|
<div v-if="isASubmittedForm">
|
|
<UserMessage
|
|
v-for="submittedValue in submittedFormValues"
|
|
:key="submittedValue.id"
|
|
:message="submittedValue"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</template>
|