meta-cloud-api
Version:
TypeScript wrapper for Meta's Cloud API
426 lines (416 loc) • 12.9 kB
TypeScript
import { I as InteractiveTypesEnum, C as ComponentTypesEnum, L as LanguagesEnum, P as ParametersTypesEnum, i as CurrencyCodesEnum, S as SubTypeEnum, B as ButtonPositionEnum, M as MessageTypesEnum } from './enums-BZd9T2ul.js';
import { a as BaseClass } from './base-CdGDdVEl.js';
import { a as GeneralRequestBody } from './request-vYMaEfk5.js';
interface ReactionParams {
messageId: string;
emoji: string;
to: string;
}
type DocumentMediaObject$2 = {
id?: string;
link?: string;
caption?: string;
filename?: string;
};
type ImageMediaObject$2 = {
id?: string;
link?: string;
caption?: string;
};
type VideoMediaObject$2 = {
id?: string;
link?: string;
caption?: string;
};
type ProductObject = {
product_retailer_id: string;
};
type SimpleTextObject$1 = {
text: string;
};
type RowObject = {
id: string;
title: string;
description?: string;
};
type MultiProductSectionObject = {
product_items: ProductObject[];
rows?: never;
title?: string;
};
type ListSectionObject = {
product_items?: never;
rows: RowObject[];
title?: string;
};
type SectionObject = MultiProductSectionObject | ListSectionObject;
type ButtonObject = {
title: string;
id: string;
};
type ReplyButtonObject = {
type: 'reply';
reply: ButtonObject;
};
type ActionObject = {
buttons?: ReplyButtonObject[];
catalog_id?: string;
product_retailer_id?: string;
sections?: SectionObject[];
};
type HeaderObject = {
type: 'document' | 'image' | 'text' | 'video';
document?: DocumentMediaObject$2;
image?: ImageMediaObject$2;
text?: string;
video?: VideoMediaObject$2;
};
type ButtonInteractiveObject = {
type: InteractiveTypesEnum.Button;
body: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: ActionObject;
};
type ListInteractiveObject = {
type: InteractiveTypesEnum.List;
body: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: ActionObject;
};
type ProductInteractiveObject = {
type: InteractiveTypesEnum.Product;
body?: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: ActionObject;
};
type ProductListInteractiveObject = {
type: InteractiveTypesEnum.ProductList;
body: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header: HeaderObject;
action: ActionObject;
};
type CtaUrlParameters = {
display_text: string;
url: string;
};
type CtaUrlActionObject = {
name: 'cta_url';
parameters: CtaUrlParameters;
};
type CtaUrlInteractiveObject = {
type: InteractiveTypesEnum.CtaUrl;
body?: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: CtaUrlActionObject;
};
type LocationRequestActionObject = {
name: 'send_location';
};
type LocationRequestInteractiveObject = {
type: InteractiveTypesEnum.LocationRequest;
body: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: LocationRequestActionObject;
};
type AddressValues = {
name?: string;
phone_number?: string;
in_pin_code?: string;
house_number?: string;
floor_number?: string;
tower_number?: string;
building_name?: string;
address?: string;
landmark_area?: string;
city?: string;
state?: string;
};
type SavedAddress = {
id: string;
value: AddressValues;
};
type ValidationErrors = {
[key in keyof AddressValues]?: string;
};
type AddressMessageParameters = {
country: string;
values?: AddressValues;
saved_addresses?: SavedAddress[];
validation_errors?: ValidationErrors;
};
type AddressMessageActionObject = {
name: 'address_message';
parameters: AddressMessageParameters;
};
type AddressMessageInteractiveObject = {
type: InteractiveTypesEnum.AddressMessage;
body: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: AddressMessageActionObject;
};
type FlowParameters = {
flow_message_version: string;
flow_id?: string;
flow_name?: string;
flow_cta: string;
mode?: 'draft' | 'published';
flow_token: string;
flow_action: 'navigate' | 'data_exchange';
flow_action_payload?: {
screen?: string;
data?: Record<string, string>;
};
};
type FlowActionObject = {
name: 'flow';
parameters: FlowParameters;
};
type FlowInteractiveObject = {
type: InteractiveTypesEnum.Flow;
body: SimpleTextObject$1;
footer?: SimpleTextObject$1;
header?: HeaderObject;
action: FlowActionObject;
};
type InteractiveObject = ButtonInteractiveObject | ListInteractiveObject | ProductInteractiveObject | ProductListInteractiveObject | CtaUrlInteractiveObject | LocationRequestInteractiveObject | AddressMessageInteractiveObject | FlowInteractiveObject;
type LocationObject = {
longitude: number;
latitude: number;
name?: string;
address?: string;
};
type AddressesObject = {
street?: string;
city?: string;
state?: string;
zip?: string;
country?: string;
country_code?: string;
type?: 'HOME' | 'WORK' | string;
};
type EmailObject = {
email?: string;
type?: 'HOME' | 'WORK' | string;
};
type NameObject = {
formatted_name: string;
first_name?: string;
last_name?: string;
middle_name?: string;
suffix?: string;
prefix?: string;
};
type OrgObject = {
company?: string;
department?: string;
title?: string;
};
type PhoneObject = {
phone?: 'PHONE_NUMBER';
type?: 'CELL' | 'MAIN' | 'IPHONE' | 'HOME' | 'WORK' | string;
wa_id?: string;
};
type URLObject = {
url?: string;
type?: 'HOME' | 'WORK' | string;
};
type ContactObject = {
addresses?: AddressesObject[];
birthday?: `${number}${number}${number}${number}-${number}${number}-${number}${number}`;
emails?: EmailObject[];
name: NameObject;
org?: OrgObject;
phones?: PhoneObject[];
urls?: URLObject[];
};
type MetaMediaObject = {
id: string;
link?: never;
};
type HostedMediaObject = {
id?: never;
link: string;
};
type AudioMediaObject = MetaMediaObject | HostedMediaObject;
type MetaDocumentMediaObject = MetaMediaObject & {
caption?: string;
filename?: string;
};
type HostedDocumentMediaObject = HostedMediaObject & {
caption?: string;
filename?: string;
};
type DocumentMediaObject$1 = MetaDocumentMediaObject | HostedDocumentMediaObject;
type MetaImageMediaObject = MetaMediaObject & {
caption?: string;
};
type HostedImageMediaObject = HostedMediaObject & {
caption?: string;
};
type ImageMediaObject$1 = MetaImageMediaObject | HostedImageMediaObject;
type MetaVideoMediaObject = MetaMediaObject & {
caption?: string;
};
type HostedVideoMediaObject = HostedMediaObject & {
caption?: string;
};
type VideoMediaObject$1 = MetaVideoMediaObject | HostedVideoMediaObject;
type StickerMediaObject = MetaMediaObject | HostedMediaObject;
type LanguageObject = {
policy: 'deterministic';
code: LanguagesEnum;
};
type ParametersObject<T extends ParametersTypesEnum> = {
type: T;
};
type SimpleTextObject = {
text: string;
};
type TextParametersObject = ParametersObject<ParametersTypesEnum.Text> & SimpleTextObject;
type CouponCodeParametersObject = ParametersObject<ParametersTypesEnum.CouponCode> & {
coupon_code: string;
};
type CurrencyObject = {
fallback_value: string;
code: CurrencyCodesEnum;
amount_1000: number;
};
type CurrencyParametersObject = ParametersObject<ParametersTypesEnum.Currency> & {
currency: CurrencyObject;
};
type DateTimeObject = {
fallback_value: string;
};
type DateTimeParametersObject = ParametersObject<ParametersTypesEnum.Currency> & {
date_time: DateTimeObject;
};
type DocumentMediaObject = {
id?: string;
link?: string;
caption?: string;
filename?: string;
};
type ImageMediaObject = {
id?: string;
link?: string;
caption?: string;
};
type VideoMediaObject = {
id?: string;
link?: string;
caption?: string;
};
type DocumentParametersObject = ParametersObject<ParametersTypesEnum.Document> & DocumentMediaObject;
type ImageParametersObject = ParametersObject<ParametersTypesEnum.Image> & ImageMediaObject;
type VideoParametersObject = ParametersObject<ParametersTypesEnum.Video> & VideoMediaObject;
type ComponentObject<T extends ComponentTypesEnum> = {
type: T;
parameters: (CurrencyParametersObject | DateTimeParametersObject | DocumentParametersObject | ImageParametersObject | TextParametersObject | VideoParametersObject | CouponCodeParametersObject)[];
};
type ButtonComponentObject = ComponentObject<ComponentTypesEnum.Button> & {
parameters?: (TextParametersObject | PayloadParametersObject)[];
sub_type: SubTypeEnum;
index: ButtonPositionEnum;
};
type PayloadParametersObject = ParametersObject<ParametersTypesEnum.Payload> & {
payload: string;
};
type MessageTemplateObject<T extends ComponentTypesEnum> = {
name: string;
language: LanguageObject;
components?: (ComponentObject<T> | ButtonComponentObject)[];
};
type TextObject = {
body: string;
preview_url?: boolean;
};
interface TextMessageParams extends MessageRequestParams<TextObject | string> {
previewUrl?: boolean;
}
type GeneralMessageBody = GeneralRequestBody & {
/**
* The Meta messaging product name.
* @default 'whatsapp'
*/
messaging_product: 'whatsapp';
};
type ConTextObject = {
message_id: string;
};
type MessageRequestBody<T extends MessageTypesEnum> = GeneralMessageBody & {
recipient_type?: string;
to: string;
context?: ConTextObject;
type?: T;
};
interface MessageRequestParams<T> {
body: T;
to: string;
replyMessageId?: string;
}
interface StatusParams {
status: string;
messageId: string;
typingIndicator?: {
type: string;
};
}
type MessagesResponse = GeneralMessageBody & {
contacts: [
{
input: string;
wa_id: string;
}
];
messages: [
{
id: string;
}
];
};
declare class MessagesClass extends BaseClass {
text(params: TextMessageParams): Promise<MessagesResponse>;
template(params: MessageRequestParams<MessageTemplateObject<ComponentTypesEnum>>): Promise<MessagesResponse>;
audio(params: MessageRequestParams<AudioMediaObject>): Promise<MessagesResponse>;
document(params: MessageRequestParams<DocumentMediaObject$1>): Promise<MessagesResponse>;
image(params: MessageRequestParams<ImageMediaObject$1>): Promise<MessagesResponse>;
video(params: MessageRequestParams<VideoMediaObject$1>): Promise<MessagesResponse>;
sticker(params: MessageRequestParams<StickerMediaObject>): Promise<MessagesResponse>;
contacts(params: MessageRequestParams<[ContactObject]>): Promise<MessagesResponse>;
location(params: MessageRequestParams<LocationObject>): Promise<MessagesResponse>;
interactive(params: MessageRequestParams<InteractiveObject>): Promise<MessagesResponse>;
interactiveList(params: MessageRequestParams<InteractiveObject & {
type: InteractiveTypesEnum.List;
}>): Promise<MessagesResponse>;
interactiveCtaUrl(params: MessageRequestParams<InteractiveObject & {
type: InteractiveTypesEnum.CtaUrl;
}>): Promise<MessagesResponse>;
interactiveLocationRequest(params: MessageRequestParams<InteractiveObject & {
type: InteractiveTypesEnum.LocationRequest;
}>): Promise<MessagesResponse>;
interactiveAddressMessage(params: MessageRequestParams<InteractiveObject & {
type: InteractiveTypesEnum.AddressMessage;
}>): Promise<MessagesResponse>;
interactiveReplyButtons(params: MessageRequestParams<InteractiveObject & {
type: InteractiveTypesEnum.Button;
}>): Promise<MessagesResponse>;
interactiveFlow(params: MessageRequestParams<InteractiveObject & {
type: InteractiveTypesEnum.Flow;
}>): Promise<MessagesResponse>;
reaction(params: ReactionParams): Promise<MessagesResponse>;
markAsRead(params: {
messageId: string;
}): Promise<MessagesResponse>;
showTypingIndicator(params: {
messageId: string;
}): Promise<MessagesResponse>;
status(params: StatusParams): Promise<MessagesResponse>;
}
export { type AudioMediaObject as A, type ContactObject as C, type DocumentMediaObject$1 as D, type ImageMediaObject$1 as I, type LocationObject as L, type MessageRequestParams as M, type NameObject as N, type ReactionParams as R, type StatusParams as S, type TextMessageParams as T, type VideoMediaObject$1 as V, type InteractiveObject as a, type MessagesResponse as b, type MessageTemplateObject as c, type StickerMediaObject as d, type TextObject as e, MessagesClass as f, type MessageRequestBody as g, type AddressesObject as h };