///
import { Contact, WebhookContact, InteractiveHeader, TemplateComponent, MarkAsRead, Message as WhatsappMessageObject, FlowMode, FlowAction, FlowActionPayload, FlowIdentifier } from './messages.types';
import { UploadMediaResult, SendMessageResult } from './sendRequestHelper.types';
import { FreeFormObject, FreeFormObjectMap } from './utils/misc';
import { PubSubEvent } from './utils/pubSub';
import { RecipientTarget, RecipientIdentity } from './recipient';
import { TemplatesApi } from './management/templates';
import { UsernameApi } from './management/username';
import { BusinessProfileApi } from './management/businessProfile';
import { BlockUsersApi } from './management/blockUsers';
export interface GenericMessage {
from?: string;
from_user_id?: string;
from_parent_user_id?: string;
name: string | undefined;
id: string;
timestamp: string;
type: K;
data: FreeFormObject;
contact?: WebhookContact;
replyTarget?: RecipientTarget;
identity?: RecipientIdentity;
}
export type AllPossibleMessages = {
[K in keyof FreeFormObjectMap]: GenericMessage;
}[keyof FreeFormObjectMap];
export type Message = AllPossibleMessages;
export type MessageEventCallback = (message: Message) => void;
export type SpecificEventCallback = (message: GenericMessage) => void;
export type BaseOptionType = {
recipient?: string;
context?: WhatsappMessageObject['context'];
};
export interface SendFlowOptions extends BaseOptionType {
header?: InteractiveHeader;
body: string;
footer?: string;
mode?: FlowMode;
flowToken?: string;
flowAction?: FlowAction;
flowActionPayload?: FlowActionPayload;
}
export interface Bot {
on(event: 'message', cb: MessageEventCallback): string;
on(event: K, cb: SpecificEventCallback): string;
unsubscribe: (token: string) => string | boolean;
sendText: (to: string | RecipientTarget, text: string, options?: BaseOptionType & {
preview_url?: boolean;
}) => Promise;
sendMessage: (to: string | RecipientTarget, text: string, options?: BaseOptionType & {
preview_url?: boolean;
}) => Promise;
sendImage: (to: string | RecipientTarget, urlOrObjectId: string, options?: BaseOptionType & {
caption?: string;
}) => Promise;
sendDocument: (to: string | RecipientTarget, urlOrObjectId: string, options?: BaseOptionType & {
caption?: string;
filename?: string;
}) => Promise;
sendAudio: (to: string | RecipientTarget, urlOrObjectId: string, options?: BaseOptionType) => Promise;
sendVideo: (to: string | RecipientTarget, urlOrObjectId: string, options?: BaseOptionType & {
caption?: string;
}) => Promise;
sendSticker: (to: string | RecipientTarget, urlOrObjectId: string, options?: BaseOptionType) => Promise;
sendLocation: (to: string | RecipientTarget, latitude: number, longitude: number, options?: BaseOptionType & {
name?: string;
address?: string;
}) => Promise;
sendTemplate: (to: string | RecipientTarget, name: string, languageCode: string, components?: TemplateComponent[], options?: BaseOptionType) => Promise;
sendContacts: (to: string | RecipientTarget, contacts: Contact[], options?: BaseOptionType) => Promise;
sendReplyButtons: (to: string | RecipientTarget, bodyText: string, buttons: {
[id: string]: string | number;
}, options?: BaseOptionType & {
footerText?: string;
header?: InteractiveHeader;
}) => Promise;
sendList: (to: string | RecipientTarget, buttonName: string, bodyText: string, sections: {
[sectionTitle: string]: {
id: string | number;
title: string | number;
description?: string;
}[];
}, options?: BaseOptionType & {
footerText?: string;
header?: InteractiveHeader;
}) => Promise;
sendCTAUrl: (to: string | RecipientTarget, bodyText: string, display_text: string, url: `http://${string}` | `https://${string}`, options?: BaseOptionType & {
footerText?: string;
header?: InteractiveHeader;
}) => Promise;
sendFlow: (to: string | RecipientTarget, flowIdOrName: string | FlowIdentifier, ctaText: string, options: SendFlowOptions) => Promise;
sendReaction: (to: string | RecipientTarget, messageId: string, emoji?: string, options?: BaseOptionType) => Promise;
sendRequestContactInfo: (to: string | RecipientTarget, bodyText: string, options?: BaseOptionType & {
footerText?: string;
header?: InteractiveHeader;
}) => Promise;
markAsRead: (message_id: string, statusOrTyping?: MarkAsRead['status'] | boolean, typing_indicator?: MarkAsRead['typing_indicator'] | boolean) => Promise;
uploadMedia: (filePath: string | URL | Buffer, mimeType?: string | null, filename?: string) => Promise;
templates: TemplatesApi;
username: UsernameApi;
profile: BusinessProfileApi;
blockUsers: BlockUsersApi;
}
export type ICreateBot = (fromPhoneNumberId: string, accessToken: string, options?: {
version?: string;
wabaId?: string;
appSecret?: string;
}) => Bot;