Hooks

useDocyrusInstantMessageComposer

Wires the native InstantMessageComposer to the Docyrus SMS and WhatsApp messaging API.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-instant-message-composer
Required Packages(2 packages)
pnpm add @tanstack/react-query @docyrus/api-client

A verbatim port of the web hook. It loads GET /v1/messaging/sms/accounts and GET /v1/messaging/whatsapp/accounts (only for the availableChannels), auto-selects the first account per channel, and sends through POST …/sms/accounts/{accountId}/send or …/whatsapp/accounts/{accountId}/send. WhatsApp supports text and pre-approved template messages. A QueryClientProvider must be mounted above it.

Usage

import { InstantMessageComposer } from '@/components/docyrus-native/instant-message-composer';
import { useDocyrusInstantMessageComposer } from '@/hooks/docyrus-native/use-docyrus-instant-message-composer';

const { composerProps } = useDocyrusInstantMessageComposer({ client, initialRecipients: ['+905551234567'] });

<InstantMessageComposer {...composerProps} />
// WhatsApp template
await send({ channel: 'whatsapp', type: 'template', templateName: 'order_shipped', templateLanguage: 'en_US', templateParams: ['#1042'] });

API Reference

UseDocyrusInstantMessageComposerOptions

OptionTypeDefaultDescription
clientRestApiClient-Authenticated REST client (required)
initialChannel'sms' | 'whatsapp''sms'Initial channel
availableChannelsReadonlyArray<InstantMessageChannel>['sms', 'whatsapp']Channels offered (and queried)
initialRecipientsstring[][]Initial recipients
initialBodystring''Initial body
initialSmsAccountId / initialWhatsAppAccountIdstringfirst accountAccounts to preselect
resetOnSendSuccessbooleantrueClear recipients / body / attachments after a send
enabledbooleantrueToggle the queries
defaultFromstring-Default sender override
defaultPhoneNumberIdstring-Default Meta WhatsApp Cloud phone number id
listSmsAccountsEndpoint / listWhatsAppAccountsEndpointstring/v1/messaging/{sms,whatsapp}/accountsAccount endpoints
sendSmsEndpoint / sendWhatsAppEndpointstring…/accounts/{accountId}/sendSend endpoints

UseDocyrusInstantMessageComposerResult

FieldTypeDescription
composerPropsPick<InstantMessageComposerProps, …>channel, availableChannels, recipients, body, attachments + handlers, onSend, sending
channel / setChannelActive channel
smsAccounts / whatsAppAccountsDocyrusSmsAccount[] / DocyrusWhatsAppAccount[]Account DTOs
selectedSmsAccount / selectedWhatsAppAccount / selectedAccountIdSelection
setSelectedSmsAccountId / setSelectedWhatsAppAccountId(id: string) => voidChange the account
isLoadingAccounts / accountsError / refetchAccountsAccounts query state
recipients / body / attachments + settersComposer state
send(overrides?: DocyrusInstantMessageSendOverrides) => Promise<DocyrusInstantMessageSendResult>Send
isSending / sendError / lastSendResult / resetMutation state

Types

TypeDescription
DocyrusSmsAccount / DocyrusWhatsAppAccountAccount DTOs
DocyrusInstantMessageSendOverrideschannel, to, body, from, accountId, type, phoneNumberId, templateName, templateLanguage, templateParams
DocyrusInstantMessageSendResult{ messageId, provider, accepted, rejected }
WhatsAppMessageType'text' | 'template'

On this page