import type { AssignBotPayload, BulkTransferResult, Chat, ChatActionPayload, ChatActionResult, ChatBlockUpdate, ChatList, ChatSession, CtwaReferral, ListChatsPayload, Message, MessageDeleteResult, SendMediaPayload, SendMessagePayload, UpdateChatPayload, UpdateChatResult } from '../types/inbox'; import { InboxClient, type InboxClientOptions } from './client'; /** The chat list and the thirteen actions that change one. */ export declare class InboxChats { private readonly client; constructor(client: InboxClient); /** * One page of the inbox, ordered by last activity. * * `contact.list` · scope `contacts:read` * * The reply's `filter` is the filter that was *applied* -- a team member * without the unassigned permission asking for `all` is narrowed to `me` -- and * `nextPage` is the cursor for the page after this one, or `null` at the end. */ list(payload?: ListChatsPayload): Promise; /** * One chat, and a subscription to it: messages and state changes for this * thread reach the socket from here on without asking again. * * `contact.fetch` · scope `contacts:read` */ get(id: string): Promise; /** Any action, for callers holding a payload they built elsewhere. */ act(payload: ChatActionPayload): Promise; /** Trashes the chat. It leaves every inbox view; the contact row stays. */ delete(chat: string): Promise; /** Assigns the chat to one member and flags it unread for them. */ transfer(chat: string, member: string): Promise; archive(chat: string): Promise; unarchive(chat: string): Promise; /** Flips one or more block flags. Flags left out keep their current value. */ block(chat: string, update: ChatBlockUpdate): Promise; /** Clears the unread counter and the by-hand unread flag. */ markAsRead(chat: string): Promise; markAsUnread(chat: string): Promise; /** Detaches the flow and holds automation for `chat_metadata.pause_duration`. */ pauseAutomation(chat: string): Promise; resumeAutomation(chat: string): Promise; /** Closes the chat and detaches the flow, leaving the assignment alone. */ close(chat: string): Promise; /** Marks the chat done, unassigns it and detaches the flow. */ done(chat: string, isEnded?: boolean): Promise; /** Re-arms the automation pause with a new duration, in seconds. */ pauseTimer(chat: string, duration: number): Promise; /** Replaces the chat's tags outright. */ updateTags(chat: string, tags: string[]): Promise; /** * Moves every chat held by one member -- or the unassigned queue -- to another * member or a team. Capped at 500 chats per call; each moved chat is broadcast * individually as a `transfer`. */ bulkTransfer(payload: Omit, 'action'>): Promise; /** The narrower action set, answering with the metadata alone. */ update(payload: UpdateChatPayload): Promise; /** * Attaches a flow to the chat, or hands the chat to the bot server to place. * * `contact.bot_assign` · scope `contacts:write` */ assignBot(payload: AssignBotPayload): Promise<{ success: boolean; id: string; }>; private single; } /** Reading, sending and removing messages in one thread. */ export declare class InboxMessages { private readonly client; constructor(client: InboxClient); /** * One page of a thread, oldest-first, and a subscription to it. * * `message.list` · scope `messages:read` * * Pass the `id` of the oldest message you hold as `last_message_id` to walk * backwards through the history. */ list(id: string, options?: { limit?: number; last_message_id?: string; }): Promise[]>; /** One message by its provider id -- a `wamid`, not the document id. */ get(messageId: string): Promise>; /** * Sends a message and gets the bubble to draw back immediately. * * `message.send` · scope `messages:write` * * The returned message carries a queue id in `message_id`, not a provider id: * nothing has been written yet. The stored row arrives moments later as a * `message.received` push, with the provider's id in its place -- correlate on * the queue id you got back here, not on the final `message_id`. * * Sending by hand also takes the conversation off its bot, which arrives as a * `chat.action` with `action: 'pause_automation'`. */ send(payload: SendMessagePayload): Promise>; /** * Sends media, uploading it first if you hand over a file. * * `message.send` · scope `messages:write` * * Two ways in. With a `link` -- from `crm.inboxMedia.upload()`, or any publicly * fetchable URL -- this is `send()` with the content assembled for you: * * ```ts * const link = await crm.inboxMedia.upload(file, { kind: 'image' }); * await inbox.messages.sendMedia({ channel, contact, kind: 'image', link, caption: 'Your order' }); * ``` * * With a `file`, it uploads and sends in one call -- which needs an uploader, * because a socket cannot presign. Pass `uploadMedia` when constructing the * `Inbox`: * * ```ts * const inbox = new Inbox({ url, clientId, token, uploadMedia: crm.inboxMedia.upload.bind(crm.inboxMedia) }); * await inbox.messages.sendMedia({ channel, contact, kind: 'image', file, caption: 'Your order' }); * ``` * * The link is what gets stored on the message, and it does not expire, so the * thread still renders the media months later. * * `filename` is worth setting on a `document`: it is what the recipient sees in * their chat, where a bare key would otherwise appear. */ sendMedia(payload: SendMediaPayload): Promise>; /** Uploads a file through the hook the client was given, or explains its absence. */ private resolve; /** Removes one message from a thread, for everyone with it open. */ delete(contactId: string, messageId: string): Promise; /** * Re-fetches media whose first download failed. Inbound media only -- an * outbound attachment was ours to begin with. * * `message.retry_download` · scope `messages:write` */ retryDownload(messageId: string): Promise>; } /** * The live-chat inbox. * * ```ts * const inbox = new Inbox({ url: 'https://inbox.example.com', clientId, token }); * await inbox.ready(); * * const { contacts } = await inbox.chats.list({ filter: { assignment: 'me', unread: 'unread' } }); * inbox.on('message.received', (message) => append(message)); * ``` */ export declare class Inbox extends InboxClient { readonly chats: InboxChats; readonly messages: InboxMessages; constructor(options: InboxClientOptions); /** * Where a lead came from: the click-to-WhatsApp ad payloads on one contact. * * `ctwa.list` · scope `contacts:read` */ referrals(contactId: string, limit?: number): Promise; /** * A contact's reply windows, one per channel they have written from. Read these * to tell whether a free-form reply is still allowed on a channel or whether * the agent has to start from a template. * * `chat_session.list` · scope `contacts:read` */ sessions(contactId: string, channel?: string): Promise; /** Round-trips the payload. Useful for checking the connection is live. */ ping(payload: T): Promise; }