/** * Canned replies: message payloads an agent sends into a chat without retyping * them. * * Two kinds, and the difference is who gets the last word. A `CANNED` reply * sends every message it holds, exactly as stored, in order, the moment it is * picked -- so a three-message reply puts three messages on the contact's phone * from one keystroke. A `QUICK` reply drops its text into the agent's composer * to edit before sending, which is why it holds exactly one text message and * nothing else: there is one composer, and nowhere to put an image in it. * * Declared here rather than imported from `@crm/contracts` so the published * package has no private dependencies; kept in step with the zod schemas. */ import type { JsonObject, ListQuery } from './common'; import type { MessageContent } from './inbox'; export type CannedReplyType = 'CANNED' | 'QUICK'; /** * The channel shape the stored payload is written for -- a channel *type*, never * a channel id, so one reply works across every number on the account. * * `whatsapp` is the only value the panel offers today, and the reason is * `whatsapp_api` below: a stored message is a literal WhatsApp Cloud API message * object, so a reply is only sendable on a channel that speaks that shape. */ export type CannedReplyChannel = 'whatsapp' | 'sms' | 'email' | 'rcs' | 'webchat'; /** Most messages one reply may hold. A `CANNED` reply sends all of them. */ export declare const MAX_CANNED_REPLY_MESSAGES = 10; /** * The editor's own working copy of a message. * * Stored and returned verbatim, and never read by the server: it is the form * state a composer needs to reopen the message for editing -- which media type * was chosen, whether the upload was still local, the button rows before they * were flattened into an action. `whatsapp_api` is the authority on what gets * sent; this is the authority on what the edit screen shows. * * Optional. A reply created through the API without one is valid; an editor just * opens it in whatever state it can infer from `whatsapp_api`. */ export type CannedReplyDraft = JsonObject; /** * One message in a reply, as written by the current editor. * * `whatsapp_api` is the payload as the provider takes it -- the same object * `inbox.messages.send()` accepts as `content`. Only `type` is promised; by * convention the body sits under a key of the same name. * * Variable placeholders in a body are stored **literally**. Substitution happens * at the moment of sending, against the contact in front of the agent; there is * no contact when a reply is written. */ export interface CannedReplyMessageV2 { version: '2'; whatsapp_api: MessageContent; internal?: CannedReplyDraft; } /** * A message row written before the editor was rewritten. * * These carry a flat `type` plus a `components` array in template form, and are * returned exactly as stored -- synthesising a `whatsapp_api` for them would * mean inventing a payload nobody approved. Narrow with * `message.version === '2'` before reading `whatsapp_api`; everything else is one * of these. New writes are v2 only: there is no way to create one of these * through the API. */ export type CannedReplyMessageLegacy = JsonObject & { version?: undefined; }; export type CannedReplyMessage = CannedReplyMessageV2 | CannedReplyMessageLegacy; /** A message on the way *in* -- always v2, because that is all a write accepts. */ export interface CannedReplyMessageInput { /** Defaults to `'2'`. The only accepted value. */ version?: '2'; whatsapp_api: MessageContent; internal?: CannedReplyDraft; } export interface CreateCannedReplyInput { /** * What the agent types after `/`. Trimmed, 1..120 characters, unique per * account -- a duplicate is a 409, not a silent overwrite. */ name: string; type: CannedReplyType; /** Default `'whatsapp'`. */ channel?: CannedReplyChannel; /** 1..{@link MAX_CANNED_REPLY_MESSAGES}. A `QUICK` reply must hold exactly one, of type `text`. */ messages: CannedReplyMessageInput[]; } /** * Any subset of the create body. * * `messages` is replaced whole, never merged: a reply is an ordered sequence, and * there is no sensible way to patch element two of a list whose length is also * changing. Send the array you want stored. */ export type UpdateCannedReplyInput = Partial; /** * `search` matches the name, case-insensitively, anywhere in it; the term is * escaped, so `(` and `.` are searched for rather than compiled. `type` and * `channel` narrow the list -- the chat panel passes both, wanting the replies * usable on the channel of the chat that is open. */ export interface ListCannedRepliesQuery extends ListQuery { type?: CannedReplyType; channel?: CannedReplyChannel; } /** * A stored reply. * * `messages` comes back in full from every endpoint, list included. It is the * entire point of the record, and a picker that had to fetch each reply before it * could show what the reply says would make one request per keystroke. */ export interface CannedReply { id: string; name: string; type: CannedReplyType; channel: CannedReplyChannel; messages: CannedReplyMessage[]; createdAt: string; updatedAt: string; }