WA template
This commit is contained in:
parent
7a2e21ba61
commit
d272ae0bd3
12 changed files with 1359 additions and 5 deletions
|
|
@ -420,6 +420,126 @@ export type AdminUrmiOtpProject = UrmiOtpProject & {
|
|||
user: { id: string; name: string; email: string }
|
||||
}
|
||||
|
||||
export type AgentTemplateParameter = {
|
||||
name: string
|
||||
type: string
|
||||
required: boolean
|
||||
description: string
|
||||
example: string
|
||||
}
|
||||
|
||||
export type AgentMessageTemplate = {
|
||||
id: string
|
||||
slug: string
|
||||
name: string
|
||||
description: string
|
||||
header_text: string | null
|
||||
body_preview: string
|
||||
footer_text: string | null
|
||||
meta_template_name: string
|
||||
language: string
|
||||
category: string
|
||||
parameters: AgentTemplateParameter[]
|
||||
button_label: string | null
|
||||
button_url_base: string | null
|
||||
is_active: boolean
|
||||
subscribed: boolean
|
||||
}
|
||||
|
||||
export type AgentTemplateDocumentation = {
|
||||
template: AgentMessageTemplate
|
||||
api: {
|
||||
method: string
|
||||
path: string
|
||||
summary: string
|
||||
authentication: {
|
||||
type: string
|
||||
header: string
|
||||
format: string
|
||||
alternate_header?: string
|
||||
}
|
||||
parameters: Record<string, string>
|
||||
example: Record<string, string>
|
||||
response_example: Record<string, unknown>
|
||||
}
|
||||
notes: string[]
|
||||
}
|
||||
|
||||
export type AgentMessageApiDoc = {
|
||||
id: string
|
||||
method: string
|
||||
path: string
|
||||
title: string
|
||||
summary: string
|
||||
authentication: {
|
||||
type: string
|
||||
header: string
|
||||
format: string
|
||||
alternate_header?: string
|
||||
}
|
||||
request_body: Record<string, {
|
||||
type: string
|
||||
required: boolean
|
||||
description: string
|
||||
example: string
|
||||
}>
|
||||
responses: Record<string, { description: string; example?: Record<string, unknown> }>
|
||||
notes?: string[]
|
||||
available_templates?: Array<{ slug: string; name: string; meta_template_name: string }>
|
||||
}
|
||||
|
||||
export type AgentMessageSendResponse = {
|
||||
success: boolean
|
||||
template: string
|
||||
to: string
|
||||
customer_name: string
|
||||
report_id: string
|
||||
report_url: string | null
|
||||
wa_message_id: string | null
|
||||
dispatch_id: string
|
||||
}
|
||||
|
||||
export const agentTemplatesApi = {
|
||||
list: () => jsonRequest<AgentMessageTemplate[]>('/api/v1/agent-templates'),
|
||||
subscribe: (slug: string) =>
|
||||
jsonRequest<AgentMessageTemplate>(`/api/v1/agent-templates/${slug}/subscribe`, { method: 'POST' }),
|
||||
unsubscribe: (slug: string) =>
|
||||
jsonRequest<AgentMessageTemplate>(`/api/v1/agent-templates/${slug}/subscribe`, { method: 'DELETE' }),
|
||||
documentation: (slug: string) =>
|
||||
jsonRequest<AgentTemplateDocumentation>(`/api/v1/agent-templates/${slug}/docs`),
|
||||
testStatus: (slug: string) =>
|
||||
jsonRequest<{ template: string; allowed: boolean; retry_after?: string | null; last_tested_at?: string | null }>(
|
||||
`/api/v1/agent-templates/${slug}/test-status`,
|
||||
),
|
||||
test: (slug: string, payload: { to: string; customer_name: string; report_id?: string }) =>
|
||||
jsonRequest<AgentMessageSendResponse>(`/api/v1/agent-templates/${slug}/test`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
}),
|
||||
}
|
||||
|
||||
export const agentMessagesApi = {
|
||||
docs: () => jsonRequest<AgentMessageApiDoc>('/api/v1/agent/messages/docs/send'),
|
||||
send: (
|
||||
apiKey: string,
|
||||
payload: { template: string; to: string; customer_name: string; report_id?: string },
|
||||
) =>
|
||||
fetch(`${API_BASE_URL}/api/v1/agent/messages/send`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
}).then(async (response) => {
|
||||
if (!response.ok) {
|
||||
const body = await response.json().catch(() => null)
|
||||
throw new Error(typeof body?.detail === 'string' ? body.detail : 'Request failed')
|
||||
}
|
||||
return response.json() as Promise<AgentMessageSendResponse>
|
||||
}),
|
||||
}
|
||||
|
||||
export const urmiOtpApi = {
|
||||
listProjects: () => jsonRequest<UrmiOtpProject[]>('/api/v1/urmiotp/projects'),
|
||||
createProject: (payload: {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue