37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { http } from './client'
|
|
import type { Conversation, Customer, Message, SendMessagePayload } from '@/types'
|
|
|
|
export type ConversationListItem = Conversation & { customer: Customer }
|
|
|
|
export interface ConversationQuery {
|
|
filter?: string
|
|
channel?: string
|
|
keyword?: string
|
|
userId?: string
|
|
}
|
|
|
|
/** GET /api/conversations */
|
|
export function getConversations(query: ConversationQuery = {}) {
|
|
return http.get<{ list: ConversationListItem[]; total: number }>('/api/conversations', { ...query })
|
|
}
|
|
|
|
/** GET /api/conversations/:id */
|
|
export function getConversation(id: string) {
|
|
return http.get<{ conversation: Conversation; customer: Customer }>(`/api/conversations/${id}`)
|
|
}
|
|
|
|
/** GET /api/conversations/:id/messages */
|
|
export function getMessages(id: string) {
|
|
return http.get<Message[]>(`/api/conversations/${id}/messages`)
|
|
}
|
|
|
|
/** POST /api/conversations/:id/messages */
|
|
export function sendMessage(id: string, payload: SendMessagePayload & { translatedText?: string }) {
|
|
return http.post<Message>(`/api/conversations/${id}/messages`, payload)
|
|
}
|
|
|
|
/** PATCH /api/conversations/:id(标记已读/分配/状态) */
|
|
export function updateConversation(id: string, payload: { assigneeId?: string | null; markRead?: boolean; status?: string }) {
|
|
return http.patch<Conversation>(`/api/conversations/${id}`, payload)
|
|
}
|