import type { CancelSeriesResult, CreateRepeatingScheduleInput, CreateScheduledMessageInput, CreateScheduledSeriesInput, ListScheduledMessagesQuery, Paginated, RescheduleMessageInput, ScheduledMessage, ScheduledMessageSeries } from '../../types'; import type { HttpClient } from '../../http'; /** * Scheduled messages: a send with a time, and optionally a condition checked * immediately before it goes out. * * ### What the condition is for * * A drip is easy to start and awkward to stop. Schedule five messages over two * weeks, your lead converts after the third, and the last two still go out -- * now addressed to a customer, as a pitch. Cancelling them means somebody * noticing in time. * * So each occurrence re-reads the contact a moment before sending and stands * down if they no longer match. Keep a `stage` custom field on your contacts, * condition the series on `stage equal to Lead`, and set `stage` to `Customer` * when they convert: the rest of the sequence cancels itself. No cancellation * call, no scheduled-message ids to track. * * ```ts * const nurture = await crm.scheduledMessages.createSeries({ * title: 'Lead nurture', * channel: channelId, * contact: { id: contactId }, * timezone: 'Asia/Kolkata', * starts_at: '2026-10-13T10:00:00', * conditions: { * conditions: [ * { field_id: 'stage', field_type: 'dropdown', condition: 'equal to', value: 'Lead' }, * ], * }, * on_condition_fail: 'cancel_series', * steps: [ * { after: { value: 0, unit: 'days' }, content: intro }, * { after: { value: 3, unit: 'days' }, content: caseStudy }, * { after: { value: 6, unit: 'days' }, content: pricing }, * ], * }); * * // Later, when the lead converts -- this is the whole of "stop the drip": * await crm.contacts.update(contactId, { custom_field_hash: { stage: 'Customer' } }); * ``` * * ### Two things that will catch you out * * **Templates, not free text.** WhatsApp only allows free-form messages within * 24 hours of the contact's last inbound message, and a drip is by construction * outside that window from the second message onward. Every step but the first * has to be an approved template or the provider refuses it; `create` rejects * free text past the window rather than letting you discover it on day four. * * **A series is expanded, not recurring.** `createSeries` writes one row per * message straight away, so you can list them, move one, or cancel one without * touching the others. There is no rule being evaluated later and nothing to * recompute -- which is also why `until` has to be a real end rather than * "forever". * * Scoping: scheduled messages belong to an account the same way contacts do -- * reads match the caller or the account they act for, writes land on the * caller's own. */ export declare class ScheduledMessages { private readonly http; constructor(http: HttpClient); /** * `GET /v1/audience/scheduled-messages` -- offset paginated, soonest first * among `pending`, newest first among the rest. `search` matches the title. * * Narrow it with `contact` for one person's queue, `series` for one drip's * occurrences, or `status` to answer "what is still waiting" (`pending`) * versus "what stood down and why" (`skipped`). * * Scope: `messages:read`. */ list(query?: Partial): Promise>; /** * `GET /v1/audience/scheduled-messages/:id` -- one occurrence, with its * `result` if it has reached a terminal status. * * Scope: `messages:read`. */ get(id: string): Promise; /** * `POST /v1/audience/scheduled-messages` -- 201 with the created occurrence. * * One message, one time. `series` on the response is `null` and `occurrence` * is `1`. * * ```ts * await crm.scheduledMessages.create({ * title: 'Pricing follow-up', * channel: channelId, * contact: { id: contactId }, * timezone: 'Asia/Kolkata', * scheduled_at: '2026-10-15T10:00:00', // 10:00 IST * content: { type: 'text', text: { body: 'Following up on the pricing.' } }, * conditions: { * conditions: [ * { field_id: 'stage', field_type: 'dropdown', condition: 'equal to', value: 'Lead' }, * ], * }, * }); * ``` * * `on_condition_fail` defaults to `skip` here, which for a single message is * the only reading that means anything -- there is no series to cancel. * * 422 if `scheduled_at` is in the past, if `timezone` is not an IANA zone, if * the condition names a field type the comparison cannot apply to, or if the * message is free text and the send falls outside the channel's reply window. * * Scope: `messages:write`. */ create(input: CreateScheduledMessageInput): Promise; /** * `POST /v1/audience/scheduled-messages/series` -- 201 with the series and * every occurrence it expanded into. * * For a sequence whose steps carry different copy. `after` is measured from * `starts_at`, not from the previous step, so changing one delay leaves the * others where they were. * * ```ts * const series = await crm.scheduledMessages.createSeries({ * title: 'Lead nurture -- 2 weeks', * channel: channelId, * contact: { id: contactId }, * timezone: 'Asia/Kolkata', * starts_at: '2026-10-13T10:00:00', * conditions: { conditions: [stillALead] }, * steps: [ * { after: { value: 0, unit: 'days' }, content: intro }, * { after: { value: 3, unit: 'days' }, content: caseStudy }, * { after: { value: 6, unit: 'days' }, content: pricing }, * { after: { value: 9, unit: 'days' }, content: demo }, * { after: { value: 12, unit: 'days' }, content: lastCall }, * ], * }); * * series.occurrences.length; // 5 * ``` * * A step may carry its own `conditions`, which are checked **in addition to** * the series' -- both have to pass. Leave them out to inherit. * * `on_condition_fail` defaults to `cancel_series`. * * Scope: `messages:write`. */ createSeries(input: CreateScheduledSeriesInput): Promise; /** * `POST /v1/audience/scheduled-messages/series` -- the same route, for the * case where every occurrence sends the same message. * * ```ts * await crm.scheduledMessages.createRepeating({ * title: 'Weekly check-in', * channel: channelId, * contact: { id: contactId }, * timezone: 'Asia/Kolkata', * starts_at: '2026-10-13T10:00:00', * repeat: { every: 3, unit: 'days', until: '2026-10-27T10:00:00' }, * content: nudgeTemplate, * conditions: { conditions: [stillALead] }, * }); * ``` * * `until` is inclusive and has to be a real end: the expansion is written as * rows, so an open-ended cadence has nothing to expand into. The result is the * same `ScheduledMessageSeries` as `createSeries` -- once created, a repeating * schedule and a stepped one are indistinguishable. * * 422 if the expansion would exceed 365 occurrences. * * Scope: `messages:write`. */ createRepeating(input: CreateRepeatingScheduleInput): Promise; /** * `PATCH /v1/audience/scheduled-messages/:id` -- moves one occurrence. * * Only a `pending` one. Rescheduling something already `sent`, `skipped` or * `cancelled` is a 409 rather than a silent no-op -- legacy answered * `{ success: true }` either way, which made a failed reschedule look like a * successful one. * * Moving one occurrence does not move the rest of its series. * * ```ts * await crm.scheduledMessages.reschedule(id, { scheduled_at: '2026-10-16T14:00:00' }); * ``` * * Scope: `messages:write`. */ reschedule(id: string, input: RescheduleMessageInput): Promise; /** * `DELETE /v1/audience/scheduled-messages/:id` -- 200 with the cancelled row. * * The row is kept rather than deleted, at `status: 'cancelled'`, so a schedule * that did not send still shows why. Use `cancelSeries` to stop a whole drip; * this stops one message and leaves the others queued. * * Scope: `messages:write`. */ cancel(id: string): Promise; /** * `DELETE /v1/audience/scheduled-messages/series/:series` -- 200 with the * number of occurrences stood down. * * Cancels every `pending` occurrence; anything already sent is untouched and * not counted. Idempotent -- a second call cancels nothing and answers `0`. * * Usually you do not need this. If the series carries a condition, changing * the contact so it no longer matches is the better way to stop a drip: it * leaves the reason on the record, and it works for every contact in the same * sequence rather than one series at a time. * * Scope: `messages:write`. */ cancelSeries(series: string): Promise; /** * `POST /v1/audience/scheduled-messages/:id/send-now` -- 200 with the row. * * Brings a `pending` occurrence forward to immediately. The condition is still * checked, because the condition is the point -- a send-now on a contact who * no longer matches comes back `skipped`, not `sent`. * * It does not duplicate: the occurrence is moved, not copied, so the original * time no longer fires. Legacy's equivalent scheduled a second job without * cancelling the first and delivered the message twice. * * Scope: `messages:write`. */ sendNow(id: string): Promise; }