You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.7 KiB
JavaScript
45 lines
1.7 KiB
JavaScript
|
|
import { groupBy } from '@/utils/utils';
|
|
import { fetchJSON, postJSON } from '@/utils/request'
|
|
import { parseRenderMessageList } from '@/lib/msgUtils';
|
|
|
|
const API_HOST = 'https://p9axztuwd7x8a7.mycht.cn/whatsapp_callback';
|
|
|
|
export const fetchTemplates = async () => {
|
|
const data = await fetchJSON(`${API_HOST}/listtemplates`);
|
|
const canUseTemplates = (data?.result?.items || [])
|
|
.filter((_t) => _t.status !== 'REJECTED')
|
|
.map((ele) => ({ ...ele, components_origin: ele.components, components: groupBy(ele.components, (_c) => _c.type.toLowerCase()) }));
|
|
return canUseTemplates;
|
|
};
|
|
|
|
export const fetchConversationsList = async (params) => {
|
|
const { result: data } = await fetchJSON(`${API_HOST}/getconversations`, params);
|
|
const list = data.map((ele) => ({ ...ele, customer_name: ele.whatsapp_name.trim() }));
|
|
return list;
|
|
};
|
|
|
|
export const fetchMessages = async (params) => {
|
|
const { result } = await fetchJSON(`${API_HOST}/getcusmessages`, params);
|
|
return parseRenderMessageList(result);
|
|
}
|
|
|
|
export const fetchCustomerProfile = async (colisn) => {
|
|
const { result } = await fetchJSON(`${API_HOST}/getorderinfo`, { colisn });
|
|
const data = result?.[0] || {};
|
|
return data;
|
|
};
|
|
|
|
export const fetchOrderConversationsList = async (params) => {
|
|
const { errcode, result: data } = await fetchJSON(`${API_HOST}/getorderconversation`, params);
|
|
if (errcode !== 0) return [];
|
|
const list = data.map((ele) => ({ ...ele, customer_name: ele.whatsapp_name.trim() }));
|
|
return list;
|
|
};
|
|
|
|
export const fetchConversationItemClose = async (body) => {
|
|
const getParams = body ? new URLSearchParams(body).toString() : '';
|
|
const { result } = await fetchJSON(`${API_HOST}/closeconversation?${getParams}`);
|
|
return result;
|
|
};
|