bootdesk/chat-sdk

WhatsAppAdapter
in package
implements Adapter, AdapterHasMessagingWindow, HandlesBatchedWebhooks, HandlesMessageCosts, HandlesReactions, HandlesSlashCommands, HandlesStatuses, HasAuthorInfo, MustRehydrateAttachments, RequiresAsyncResponse

Table of Contents

Interfaces

Adapter
AdapterHasMessagingWindow
HandlesBatchedWebhooks
HandlesMessageCosts
HandlesReactions
HandlesSlashCommands
HandlesStatuses
HasAuthorInfo
MustRehydrateAttachments
RequiresAsyncResponse
Marker interface for adapters that expect a quick 200 ACK and should always defer message processing to async execution.

Properties

$accessToken  : string
$apiUrl  : string
$botUserId  : string|null
$emojiResolver  : EmojiResolver
$fileUploadConverter  : FileUploadConverter
$formatConverter  : WhatsAppFormatConverter
$httpClient  : ClientInterface
$phoneNumberId  : string
$psrFactory  : Psr17Factory|null
$state  : StateAdapter|null
$webhookVerifier  : WhatsAppWebhookVerifier|null

Methods

__construct()  : mixed
addReaction()  : void
channelIdFromThreadId()  : string
createResponse()  : ResponseInterface|null
decodeThreadId()  : mixed
deleteMessage()  : void
disconnect()  : void
editMessage()  : SentMessage
encodeThreadId()  : string
fetchChannelInfo()  : ChannelInfo|null
fetchMedia()  : StreamInterface
fetchMessages()  : FetchResult
fetchThread()  : ThreadInfo
getAuthorInfo()  : Author
getBotUserId()  : string|null
getFormatConverter()  : FormatConverter|null
getMessagingWindowSeconds()  : int|null
getName()  : string
getTrackingKey()  : string
Return a stable tracking key for the conversation from a thread ID.
getUser()  : UserInfo|null
initialize()  : void
openDM()  : string|null
parseBatchedWebhook()  : array<string|int, WebhookEvent>
Parse ALL events from a potentially-batched webhook payload.
parseMessageCost()  : Money, raw: mixed, originId: ?string}|null
parseReaction()  : Author, emoji: string, rawEmoji: string, added: bool, threadId: string, messageId: string, userId: string, raw: mixed, originId: ?string}|null
parseSlashCommand()  : Author, command: string, text: string, userId: string, isBot: bool, isMe: bool, channelId: string, triggerId: ?string, raw: mixed}|null
parseStatus()  : array{type: "delivered"|"read"|"failed", messageIds: string[], threadId: string, userId: string, raw: mixed, timestamp: ?int, originId: ?string}|null
parseWebhook()  : Message
postMessage()  : SentMessage
rehydrateAttachment()  : Attachment
removeReaction()  : void
startTyping()  : void
stream()  : SentMessage|null
verifyWebhook()  : ResponseInterface|null
addRecipientParam()  : array<string|int, mixed>
apiCall()  : array<string|int, mixed>
buildMessageParams()  : array<string|int, mixed>
createAuthor()  : Author
extractAttachments()  : array<string|int, Attachment>
parseInboundMessage()  : Message
buildCtaUrlInteractive()  : array<string|int, mixed>
sendCardMessage()  : SentMessage

Properties

$apiUrl read-only

protected string $apiUrl = 'https://graph.facebook.com/v21.0'

$psrFactory read-only

protected Psr17Factory|null $psrFactory = null

Methods

__construct()

public __construct(string $accessToken, ClientInterface $httpClient, string $phoneNumberId[, string|null $appSecret = null ][, string|null $verifyToken = null ][, string $apiUrl = 'https://graph.facebook.com/v21.0' ][, Psr17Factory|null $psrFactory = null ][, FileUploadConverter|null $fileUploadConverter = null ][, EmojiResolver|null $emojiResolver = null ]) : mixed
Parameters
$accessToken : string
$httpClient : ClientInterface
$phoneNumberId : string
$appSecret : string|null = null
$verifyToken : string|null = null
$apiUrl : string = 'https://graph.facebook.com/v21.0'
$psrFactory : Psr17Factory|null = null
$fileUploadConverter : FileUploadConverter|null = null
$emojiResolver : EmojiResolver|null = null

addReaction()

public addReaction(string $threadId, string $messageId, string $emoji) : void
Parameters
$threadId : string
$messageId : string
$emoji : string

channelIdFromThreadId()

public channelIdFromThreadId(string $threadId) : string
Parameters
$threadId : string
Return values
string

createResponse()

public createResponse() : ResponseInterface|null
Return values
ResponseInterface|null

decodeThreadId()

public decodeThreadId(string $threadId) : mixed
Parameters
$threadId : string

deleteMessage()

public deleteMessage(string $threadId, string $messageId) : void
Parameters
$threadId : string
$messageId : string

encodeThreadId()

public encodeThreadId(mixed $platformData) : string
Parameters
$platformData : mixed
Return values
string

getBotUserId()

public getBotUserId() : string|null
Return values
string|null

getMessagingWindowSeconds()

public getMessagingWindowSeconds() : int|null
Return values
int|null

getTrackingKey()

Return a stable tracking key for the conversation from a thread ID.

public getTrackingKey(string $threadId) : string

Used as the storage key for the last-seen timestamp.

Parameters
$threadId : string
Return values
string

openDM()

public openDM(string $userId) : string|null
Parameters
$userId : string
Return values
string|null

parseBatchedWebhook()

Parse ALL events from a potentially-batched webhook payload.

public parseBatchedWebhook(ServerRequestInterface $request) : array<string|int, WebhookEvent>

Unlike the individual parseXxx() methods which return on the first match, this method iterates every entry/event and returns all of them for the Chat to dispatch individually.

Parameters
$request : ServerRequestInterface
Return values
array<string|int, WebhookEvent>

parseMessageCost()

public parseMessageCost(ServerRequestInterface $request) : Money, raw: mixed, originId: ?string}|null
Parameters
$request : ServerRequestInterface
Return values
Money, raw: mixed, originId: ?string}|null

parseReaction()

public parseReaction(ServerRequestInterface $request) : Author, emoji: string, rawEmoji: string, added: bool, threadId: string, messageId: string, userId: string, raw: mixed, originId: ?string}|null
Parameters
$request : ServerRequestInterface
Return values
Author, emoji: string, rawEmoji: string, added: bool, threadId: string, messageId: string, userId: string, raw: mixed, originId: ?string}|null

parseSlashCommand()

public parseSlashCommand(ServerRequestInterface $request) : Author, command: string, text: string, userId: string, isBot: bool, isMe: bool, channelId: string, triggerId: ?string, raw: mixed}|null
Parameters
$request : ServerRequestInterface
Return values
Author, command: string, text: string, userId: string, isBot: bool, isMe: bool, channelId: string, triggerId: ?string, raw: mixed}|null

parseStatus()

public parseStatus(ServerRequestInterface $request) : array{type: "delivered"|"read"|"failed", messageIds: string[], threadId: string, userId: string, raw: mixed, timestamp: ?int, originId: ?string}|null
Parameters
$request : ServerRequestInterface
Return values
array{type: "delivered"|"read"|"failed", messageIds: string[], threadId: string, userId: string, raw: mixed, timestamp: ?int, originId: ?string}|null

parseWebhook()

public parseWebhook(ServerRequestInterface $request) : Message
Parameters
$request : ServerRequestInterface
Return values
Message

removeReaction()

public removeReaction(string $threadId, string $messageId, string $emoji) : void
Parameters
$threadId : string
$messageId : string
$emoji : string

startTyping()

public startTyping(string $threadId) : void
Parameters
$threadId : string

stream()

public stream(string $threadId, iterable<string|int, mixed> $textStream[, array<string|int, mixed> $options = [] ]) : SentMessage|null
Parameters
$threadId : string
$textStream : iterable<string|int, mixed>
$options : array<string|int, mixed> = []
Return values
SentMessage|null

verifyWebhook()

public verifyWebhook(ServerRequestInterface $request) : ResponseInterface|null
Parameters
$request : ServerRequestInterface
Return values
ResponseInterface|null

addRecipientParam()

protected addRecipientParam(array<string|int, mixed> $params, string $userWaId) : array<string|int, mixed>
Parameters
$params : array<string|int, mixed>
$userWaId : string
Return values
array<string|int, mixed>

apiCall()

protected apiCall(string $endpoint[, array<string|int, mixed> $params = [] ][, string $method = 'POST' ][, string|null $overrideUrl = null ][, bool $returnStream = false ]) : array<string|int, mixed>
Parameters
$endpoint : string
$params : array<string|int, mixed> = []
$method : string = 'POST'
$overrideUrl : string|null = null
$returnStream : bool = false
Return values
array<string|int, mixed>

createAuthor()

protected createAuthor(string $userId, array<string, mixed>|null $contact) : Author
Parameters
$userId : string
$contact : array<string, mixed>|null
Return values
Author

extractAttachments()

protected extractAttachments(array<string|int, mixed> $msg) : array<string|int, Attachment>
Parameters
$msg : array<string|int, mixed>
Return values
array<string|int, Attachment>

parseInboundMessage()

protected parseInboundMessage(array<string|int, mixed> $msg, array<string|int, mixed>|null $contact, string $phoneNumberId, string $rawBody[, string|null $originId = null ]) : Message
Parameters
$msg : array<string|int, mixed>
$contact : array<string|int, mixed>|null
$phoneNumberId : string
$rawBody : string
$originId : string|null = null
Return values
Message

buildCtaUrlInteractive()

private buildCtaUrlInteractive(Card $card) : array<string|int, mixed>
Parameters
$card : Card
Return values
array<string|int, mixed>
On this page

Search results