@botonic/core
Version:
Runtime and APIs for Botonic bots: actions, context, messaging, and integration hooks used by the **current** framework line.
179 lines (178 loc) • 8.08 kB
TypeScript
import type { RatingType, WebchatOutputRatingButton } from '@botonic/shared';
import { BotMessageMetadata } from '@botonic/shared';
import { BotonicButtonContent, BotonicCarouselElement, TypingEventName } from '@botonic/shared';
import { WebchatClientSettings } from '@botonic/shared';
import { WhatsappButtonListSection, WhatsappHeaderType, WhatsappMediaCarouselCard, WhatsappProductCarouselCard, WhatsappProductListSection, WhatsappTemplateComponent } from '@botonic/shared';
import { BotServerMessageAudio, BotServerMessageButtonMessage, BotServerMessageCarousel, BotServerMessageCustom, BotServerMessageDocument, BotServerMessageImage, BotServerMessageLocation, BotServerMessageRating, BotServerMessageText, BotServerMessageTypingEvent, BotServerMessageVideo, BotServerMessageWebchatClientSettings, BotServerMessageWhatsappButtonList, BotServerMessageWhatsappCatalog, BotServerMessageWhatsappCTAUrlButton, BotServerMessageWhatsappMediaCarousel, BotServerMessageWhatsappProduct, BotServerMessageWhatsappProductCarousel, BotServerMessageWhatsappProductList, BotServerMessageWhatsappTemplate } from './bot-server-message';
import { BotonicContext } from './botonic-context';
interface WebviewButtonParams {
title: string;
webview: string;
params?: Record<string, string>;
}
export declare class BotServerMessageFactory {
static createText({ text, payload, metadata, }: {
text: string;
payload?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageText;
static createAudio({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
attachmentUrl: string;
attachmentContent?: string;
caption?: string;
fileInfo?: Record<string, unknown>;
metadata?: BotMessageMetadata;
}): BotServerMessageAudio;
static createImage({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
attachmentUrl: string;
attachmentContent?: string;
caption?: string;
fileInfo?: Record<string, unknown>;
metadata?: BotMessageMetadata;
}): BotServerMessageImage;
static createVideo({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
attachmentUrl: string;
attachmentContent?: string;
caption?: string;
fileInfo?: Record<string, unknown>;
metadata?: BotMessageMetadata;
}): BotServerMessageVideo;
static createDocument({ attachmentUrl, attachmentContent, caption, fileInfo, metadata, }: {
attachmentUrl: string;
attachmentContent?: string;
caption?: string;
fileInfo?: Record<string, unknown>;
metadata?: BotMessageMetadata;
}): BotServerMessageDocument;
static createLocation({ latitude, longitude, title, address, metadata, }: {
latitude: number;
longitude: number;
title?: string;
address?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageLocation;
static createButtonMessage({ text, buttons, metadata, }: {
text: string;
buttons: BotonicButtonContent[];
metadata?: BotMessageMetadata;
}): BotServerMessageButtonMessage;
static createCarousel({ elements, text, metadata, }: {
elements: BotonicCarouselElement[];
text?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageCarousel;
static createCustom({ name, props, metadata, }: {
name: string;
props: Record<string, unknown>;
metadata?: BotMessageMetadata;
}): BotServerMessageCustom;
static createRating({ text, type, buttons, sendButtonText, openListButtonText, metadata, }: {
text: string;
type: RatingType;
buttons: WebchatOutputRatingButton[];
sendButtonText?: string;
openListButtonText?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageRating;
static createTypingEvent({ eventName, metadata, }: {
eventName: TypingEventName;
metadata?: BotMessageMetadata;
}): BotServerMessageTypingEvent;
/** Payload type `webchat_client_settings` for Hubtype `send_messages` (v2 bots). */
static createWebchatClientSettings({ settings, metadata, }: {
settings: Partial<WebchatClientSettings> | WebchatClientSettings;
metadata?: BotMessageMetadata;
}): BotServerMessageWebchatClientSettings;
/**
* Creates a postback button that sends a payload when clicked
*/
static createPostbackButton({ title, payload, }: {
title: string;
payload: string;
}): BotonicButtonContent;
/**
* Creates a URL button that opens a link in the browser
*/
static createUrlButton({ title, url, }: {
title: string;
url: string;
}): BotonicButtonContent;
/**
* Creates a webview button that opens a URL in a webview.
* Uses `settings.STATIC_URL` (Lambda settings), not `process.env`.
*/
static createWebviewButton(webviewButtonParams: WebviewButtonParams, botonicContext: BotonicContext): BotonicButtonContent;
/**
* Helper method to create a carousel element
* This simplifies carousel element creation
*/
static createCarouselElement({ title, subtitle, image, buttons, }: {
title: string;
subtitle: string;
image: string;
buttons: BotonicButtonContent[];
}): BotonicCarouselElement;
static createWhatsappButtonList({ header, body, footer, button, sections, metadata, }: {
header?: string;
body: string;
footer?: string;
button: string;
sections: WhatsappButtonListSection[];
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappButtonList;
static createWhatsappCTAUrlButton({ headerType, header, headerImage, headerDocument, headerVideo, body, url, displayText, footer, metadata, }: {
headerType?: WhatsappHeaderType;
header?: string;
headerImage?: string;
headerDocument?: string;
headerVideo?: string;
body: string;
url: string;
displayText: string;
footer?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappCTAUrlButton;
static createWhatsappCatalog({ body, footer, thumbnailProductId, metadata, }: {
body: string;
footer?: string;
thumbnailProductId?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappCatalog;
static createWhatsappProduct({ body, catalogId, productId, footer, metadata, }: {
body: string;
catalogId: string;
productId: string;
footer?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappProduct;
static createWhatsappProductList({ header, body, footer, catalogId, sections, metadata, }: {
body: string;
catalogId: string;
header: string;
sections: WhatsappProductListSection[];
footer?: string;
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappProductList;
static createWhatsappProductCarousel({ templateName, templateLanguage, cards, bodyParameters, metadata, }: {
templateName: string;
templateLanguage: string;
cards: WhatsappProductCarouselCard[];
bodyParameters?: Record<string, any>[];
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappProductCarousel;
static createWhatsappMediaCarousel({ templateName, templateLanguage, cards, bodyParameters, metadata, }: {
templateName: string;
templateLanguage: string;
cards: WhatsappMediaCarouselCard[];
bodyParameters?: Record<string, any>[];
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappMediaCarousel;
static createWhatsappTemplate({ name, namespace, languageCode, components, metadata, }: {
name: string;
namespace: string;
languageCode: string;
components: WhatsappTemplateComponent[];
metadata?: BotMessageMetadata;
}): BotServerMessageWhatsappTemplate;
}
export {};