UNPKG

ws-cloud-api

Version:

WhatsApp Cloud API for NodeJS

236 lines (233 loc) 6.55 kB
import { I as InteractiveTypes, M as MessageTypes } from './ws-cloud-api.fba8aa2f.mjs'; interface SimpleText { text: string; } interface MetaDocumentMedia { id: string; link?: never; caption?: string; filename?: string; } interface HostedDocumentMedia { id?: never; link: string; caption?: string; filename?: string; } type HeaderDocumentMedia = MetaDocumentMedia | HostedDocumentMedia; interface MetaImageMedia { id: string; link?: never; caption?: string; } interface HostedImageMedia { id?: never; link: string; caption?: string; } type HeaderImageMedia = MetaImageMedia | HostedImageMedia; interface MetaHostedVideoMedia { id: string; link?: never; caption?: string; } interface SelfHostedVideoMedia { id?: never; link: string; caption?: string; } type HeaderVideoMedia = MetaHostedVideoMedia | SelfHostedVideoMedia; interface Header { type: 'document' | 'image' | 'text' | 'video'; document?: HeaderDocumentMedia; image?: HeaderImageMedia; text?: string; video?: HeaderVideoMedia; } interface Row { id: string; title: string; description?: string; } interface ListSection { product_items?: never; rows: Row[]; title?: string; } type Section = ListSection; interface Button { title: string; id: string; } interface ReplyButton { type: 'reply'; reply: Button; } interface Action { button: string; buttons: ReplyButton[]; sections: Section[]; } interface FlowAction { name: 'flow'; parameters: FlowActionsParameters; } interface FlowActionsParameters { mode?: 'draft' | 'published'; flow_message_version: '3'; flow_action?: 'navigate' | 'data_exchange'; flow_token: string; flow_id: string; flow_cta: string; flow_action_payload?: FlowActionPayload; } interface FlowActionPayload { screen: string; data?: Record<string, string>; } type Interactive = ButtonInteractive | ListInteractive | CTAButtonInteractive | FlowInteractive; interface ButtonInteractive { type: InteractiveTypes.Button; body: SimpleText; footer?: SimpleText; header?: Header; action: Pick<Action, 'buttons'>; } interface CTAButtonInteractive { type: InteractiveTypes.CTAButton; body: SimpleText; footer?: SimpleText; header?: Header; action: { name: InteractiveTypes.CTAButton; parameters: { display_text: string; url: string; }; }; } interface ListInteractive { type: InteractiveTypes.List; body: SimpleText; footer?: SimpleText; header?: Header; action: Pick<Action, 'button' | 'sections'>; } interface FlowInteractive { type: InteractiveTypes.Flow; body: SimpleText; footer?: SimpleText; header?: Header; action: FlowAction; } interface TemplateLanguage { code: string; policy: 'deterministic'; } type TemplateComponent = TemplateComponentBase | TemplateComponentButton; interface TemplateComponentBase { type: 'body' | 'header' | 'button'; parameters?: TemplateParameter[]; } interface TemplateComponentButton extends TemplateComponentBase { type: 'button'; sub_type: 'quick_reply' | 'url' | 'catalog'; parameters: TemplateParameter[]; index: `${number}`; } type TemplateHeaderParameter = TemplateParameterImage | TemplateParameterDocument | TemplateParameterVideo; type TemplateBodyParameter = TemplateParameterText | TemplateParameterCurrency | TemplateParameterDateTime | TemplateNamedParameter; type TemplateParameter = TemplateBodyParameter | TemplateHeaderParameter; interface TemplateNamedParameter { type: 'text'; parameter_name: string; text: string; } interface TemplateParameterText { type: 'text'; text: string; } interface TemplateParameterCurrency { type: 'currency'; currency: { code: string; amount_1000: number; fallback_value: string; }; } interface TemplateParameterDateTime { type: 'date_time'; date_time: { fallback_value: string; }; } interface TemplateParameterImage { type: 'image'; image: HeaderImageMedia; } interface TemplateParameterDocument { type: 'document'; document: HeaderDocumentMedia; } interface TemplateParameterVideo { type: 'video'; video: HeaderVideoMedia; } interface TemplateBody { type: MessageTypes.Template; [MessageTypes.Template]: { name: string; language: TemplateLanguage; components?: TemplateComponent[]; }; } interface TextBody { type: MessageTypes.Text; [MessageTypes.Text]: { body: string; preview_url?: boolean | undefined; }; } interface ImageBody { type: MessageTypes.Image; [MessageTypes.Image]: { link: string; }; } interface VideoBody { type: MessageTypes.Video; [MessageTypes.Video]: { link: string; }; } interface AudioBody { type: MessageTypes.Audio; [MessageTypes.Audio]: { link: string; }; } interface DocumentBody { type: MessageTypes.Document; [MessageTypes.Document]: { link: string; }; } type MediaBody = ImageBody | VideoBody | AudioBody | DocumentBody; interface InteractiveBody { type: MessageTypes.Interactive; [MessageTypes.Interactive]: Interactive; } type WSBody = InteractiveBody | TextBody | MediaBody | TemplateBody; interface MessageResponse { messaging_product: 'whatsapp'; contacts: MessageContact[]; messages: MessageInfo[]; } interface MessageContact { input: string; wa_id: string; } interface MessageInfo { id: string; } export type { Action as A, Button as B, CTAButtonInteractive as C, DocumentBody as D, MessageInfo as E, FlowAction as F, HeaderDocumentMedia as H, Interactive as I, ListInteractive as L, MediaBody as M, ReplyButton as R, TemplateLanguage as T, VideoBody as V, WSBody as W, HeaderImageMedia as a, HeaderVideoMedia as b, FlowActionsParameters as c, FlowActionPayload as d, ButtonInteractive as e, FlowInteractive as f, TemplateComponent as g, TemplateComponentBase as h, TemplateComponentButton as i, TemplateHeaderParameter as j, TemplateBodyParameter as k, TemplateParameter as l, TemplateNamedParameter as m, TemplateParameterText as n, TemplateParameterCurrency as o, TemplateParameterDateTime as p, TemplateParameterImage as q, TemplateParameterDocument as r, TemplateParameterVideo as s, TemplateBody as t, TextBody as u, ImageBody as v, AudioBody as w, InteractiveBody as x, MessageResponse as y, MessageContact as z };