feat(history): add multi-account and WhatsApp foundation
This commit is contained in:
@@ -52,8 +52,30 @@ export function getTelegramLoginState(channelId: string) {
|
||||
)
|
||||
}
|
||||
|
||||
export function syncTelegramChannel(channelId: string) {
|
||||
return http.post<{ chats: number; messages: number }>(`/api/channels/${channelId}/sync`)
|
||||
export function startWhatsAppLogin(phone: string, name?: string) {
|
||||
return http.post<ChannelConnection>('/api/channels/whatsapp/start', {
|
||||
phone,
|
||||
name,
|
||||
acceptedUnofficialRisk: true,
|
||||
})
|
||||
}
|
||||
|
||||
export function getWhatsAppLoginState(channelId: string) {
|
||||
return http.post<{
|
||||
status: string
|
||||
connectionState?: string
|
||||
pairingCode?: string
|
||||
qrDataUrl?: string
|
||||
channel: ChannelConnection
|
||||
}>(`/api/channels/whatsapp/${channelId}/state`)
|
||||
}
|
||||
|
||||
export function setDefaultChannel(channelId: string) {
|
||||
return http.post<ChannelConnection>(`/api/channels/${channelId}/default`)
|
||||
}
|
||||
|
||||
export function syncChannel(channelId: string, options: { full?: boolean } = {}) {
|
||||
return http.post<{ chats: number; messages: number }>(`/api/channels/${channelId}/sync`, options)
|
||||
}
|
||||
|
||||
/** POST /api/channels/test */
|
||||
@@ -75,3 +97,81 @@ export function deleteChannel(id: string) {
|
||||
export function getChannelLogs(id: string) {
|
||||
return http.get<ChannelSyncLog[]>(`/api/channels/${id}/logs`)
|
||||
}
|
||||
|
||||
export function getWhatsAppContacts(
|
||||
channelId: string,
|
||||
query: { query?: string; cursor?: string; limit?: number } = {},
|
||||
) {
|
||||
return http.get<{
|
||||
items: Array<{ id: string; name: string; phone: string }>
|
||||
nextCursor: string | null
|
||||
total: number
|
||||
}>(`/api/channels/${channelId}/whatsapp/contacts`, query)
|
||||
}
|
||||
|
||||
export function updateWhatsAppProxy(channelId: string, url: string) {
|
||||
return http.put<ChannelConnection>(`/api/channels/${channelId}/whatsapp/proxy`, {
|
||||
url,
|
||||
test: true,
|
||||
})
|
||||
}
|
||||
|
||||
export function updateWhatsAppProfile(
|
||||
channelId: string,
|
||||
payload: { name?: string; status?: string },
|
||||
) {
|
||||
return http.patch<ChannelConnection>(`/api/channels/${channelId}/whatsapp/profile`, payload)
|
||||
}
|
||||
|
||||
export function updateWhatsAppProfilePicture(
|
||||
channelId: string,
|
||||
payload: { name: string; mimeType: string; base64: string },
|
||||
) {
|
||||
return http.post<ChannelConnection>(
|
||||
`/api/channels/${channelId}/whatsapp/profile/picture`,
|
||||
payload,
|
||||
)
|
||||
}
|
||||
|
||||
export function reauthorizeWhatsApp(channelId: string) {
|
||||
return http.post<ChannelConnection>(`/api/channels/${channelId}/whatsapp/reauthorize`)
|
||||
}
|
||||
|
||||
export function getWhatsAppDevices(channelId: string) {
|
||||
return http.get<Array<{
|
||||
id: string
|
||||
name: string
|
||||
platform: string
|
||||
current: boolean
|
||||
status: string
|
||||
connectedAt?: string
|
||||
}>>(`/api/channels/${channelId}/whatsapp/devices`)
|
||||
}
|
||||
|
||||
export function terminateWhatsAppDevice(channelId: string, deviceId: string) {
|
||||
return http.del<{ success: boolean; deviceId: string }>(
|
||||
`/api/channels/${channelId}/whatsapp/devices/${encodeURIComponent(deviceId)}`,
|
||||
)
|
||||
}
|
||||
|
||||
export function getWhatsAppGatewayMetrics() {
|
||||
return http.get<{
|
||||
accounts: { total: number; connected: number; disconnected: number }
|
||||
outbound: { queued: number; dead: number; sent: number; riskBackoff: number; averageLatencyMs: number }
|
||||
webhooks: { queued: number; dead: number; delivered: number }
|
||||
alerts: Array<{ severity: string; code: string; accountId: string; message: string }>
|
||||
}>('/api/channels/whatsapp/metrics')
|
||||
}
|
||||
|
||||
export function createWhatsAppBackup(channelId: string) {
|
||||
return http.get<{ version: number; accountId: string; createdAt: string; blob: string }>(
|
||||
`/api/channels/${channelId}/whatsapp/backup`,
|
||||
)
|
||||
}
|
||||
|
||||
export function restoreWhatsAppBackup(channelId: string, blob: string) {
|
||||
return http.post<{ restored: boolean }>(
|
||||
`/api/channels/${channelId}/whatsapp/backup/restore`,
|
||||
{ blob },
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user