@akson/chatsuite-sdk
Version:
Production-ready TypeScript SDK for ChatSuite - WhatsApp automation with built-in session management, message queuing, webhook server, and database sync
1,856 lines (1,845 loc) • 85.7 kB
text/typescript
import { AxiosInstance, AxiosRequestConfig } from 'axios';
import { EventEmitter } from 'events';
interface ApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
message?: string;
}
interface PaginatedResponse<T> extends ApiResponse<T[]> {
count: number;
total: number;
limit: number;
offset: number;
}
interface AuthConfig {
apiToken: string;
baseUrl?: string;
timeout?: number;
maxRetries?: number;
}
interface Session {
_id?: string;
tel: string;
name: string;
state: SessionState;
ready: boolean;
initializing?: boolean;
qr?: string;
environment?: string;
autoRestart?: boolean;
createdAt?: string;
updatedAt?: string;
}
declare enum SessionState {
DISCONNECTED = "DISCONNECTED",
INITIALIZING = "INITIALIZING",
CONNECTED = "CONNECTED",
CONNECTING = "CONNECTING"
}
interface CreateSessionRequest {
tel: string;
name: string;
autoRestart?: boolean;
clientUrl?: string;
onMessageHook?: string;
}
interface UpdateSessionRequest {
name?: string;
autoRestart?: boolean;
clientUrl?: string;
onMessageHook?: string;
}
interface Message {
_id?: string;
id: MessageId;
type: MessageType;
body?: string;
timestamp: number;
from: string;
to: string;
media?: MessageMedia;
status?: number;
hasReaction?: boolean;
reactions?: MessageReaction[];
}
interface MessageId {
remoteJid: string;
fromMe: boolean;
id: string;
}
declare enum MessageType {
CHAT = "chat",
IMAGE = "image",
VIDEO = "video",
AUDIO = "audio",
DOCUMENT = "document",
STICKER = "sticker",
LOCATION = "location",
CONTACT_CARD = "contact_card",
CONTACT_CARD_MULTI = "contact_card_multi",
REVOKED = "revoked",
ORDER = "order",
PRODUCT = "product",
PAYMENT = "payment",
BUTTONS = "buttons",
LIST = "list",
BUTTONS_RESPONSE = "buttons_response",
LIST_RESPONSE = "list_response",
POLL = "poll"
}
interface MessageMedia {
url?: string;
mimetype?: string;
filename?: string;
filesize?: number;
height?: number;
width?: number;
caption?: string;
}
interface MessageReaction {
key: MessageId;
text: string;
timestamp: number;
}
interface SendMessageRequest {
tel: string;
to: string;
text?: string;
media?: string;
mimetype?: string;
filename?: string;
caption?: string;
options?: MessageOptions;
}
interface MessageOptions {
quotedMessageId?: string;
mentions?: string[];
sendSeen?: boolean;
linkPreview?: boolean;
}
interface ListMessagesParams {
tel?: string;
chatId?: string;
fromDate?: string;
toDate?: string;
hasMedia?: boolean;
limit?: number;
offset?: number;
}
interface Contact {
id: string;
name?: string;
notify?: string;
imgUrl?: string;
status?: string;
isBusiness?: boolean;
isEnterprise?: boolean;
isMyContact?: boolean;
isUser?: boolean;
}
interface ContactsResponse {
success: boolean;
count: number;
contacts: Contact[];
}
interface Group {
id: string;
name: string;
desc?: string;
owner?: string;
subject: string;
creation?: number;
participants: GroupParticipant[];
admins: string[];
isCommunity?: boolean;
isLocked?: boolean;
isAnnounce?: boolean;
}
interface GroupParticipant {
id: string;
admin?: 'admin' | 'superadmin' | null;
}
interface CreateGroupRequest {
tel: string;
name: string;
participants: string[];
}
interface UpdateGroupRequest {
subject?: string;
desc?: string;
locked?: boolean;
announce?: boolean;
}
interface Status$1 {
id: string;
from: string;
timestamp: number;
type: 'text' | 'image' | 'video';
content?: string;
media?: string;
caption?: string;
backgroundColor?: string;
font?: number;
isForwarded?: boolean;
duration?: number;
views?: string[];
expiration?: number;
}
interface StatusUpdate {
tel: string;
type: 'text' | 'image' | 'video';
content?: string;
media?: string;
caption?: string;
backgroundColor?: string;
font?: number;
duration?: number;
}
interface Webhook {
_id: string;
sessionId: string;
tel: string;
name: string;
url: string;
events: string[];
headers?: Record<string, string>;
active: boolean;
retryConfig: {
maxAttempts: number;
backoffMultiplier: number;
initialDelay: number;
};
statistics: {
totalCalls: number;
successfulCalls: number;
failedCalls: number;
lastCallAt?: string;
lastSuccessAt?: string;
lastFailureAt?: string;
lastError?: string;
averageResponseTime?: number;
};
createdAt: string;
updatedAt: string;
}
interface CreateWebhookRequest {
tel: string;
name: string;
url: string;
events: string[];
headers?: Record<string, string>;
retryConfig?: {
maxAttempts: number;
backoffMultiplier: number;
initialDelay: number;
};
}
interface UpdateWebhookRequest {
tel: string;
webhookId: string;
name?: string;
url?: string;
events?: string[];
headers?: Record<string, string>;
active?: boolean;
retryConfig?: {
maxAttempts: number;
backoffMultiplier: number;
initialDelay: number;
};
}
interface WebhookTestResult {
success: boolean;
status?: number;
statusText?: string;
responseTime?: number;
headers?: Record<string, any>;
error?: string;
details?: any;
}
interface WebhookConfig {
id?: string;
url: string;
events: WebhookEvent[];
active?: boolean;
headers?: Record<string, string>;
secret?: string;
}
declare enum WebhookEvent {
MESSAGE_RECEIVED = "message.received",
MESSAGE_SENT = "message.sent",
MESSAGE_DELIVERED = "message.delivered",
MESSAGE_READ = "message.read",
MESSAGE_DELETED = "message.deleted",
SESSION_CONNECTED = "session.connected",
SESSION_DISCONNECTED = "session.disconnected",
SESSION_QR = "session.qr",
CONTACT_UPDATED = "contact.updated",
GROUP_UPDATED = "group.updated",
GROUP_PARTICIPANTS_UPDATED = "group.participants.updated",
PRESENCE_UPDATED = "presence.updated"
}
interface BusinessProfile {
id: string;
name?: string;
category?: string;
description?: string;
email?: string;
website?: string[];
address?: string;
hours?: BusinessHours[];
}
interface BusinessHours {
day: string;
open: string;
close: string;
}
interface Product$1 {
id: string;
name: string;
description?: string;
price: string;
currency: string;
isHidden?: boolean;
url?: string;
retailerId?: string;
imageUrl?: string;
}
interface Catalog {
products: Product$1[];
paging?: {
cursors: {
before: string;
after: string;
};
};
}
interface InteractiveMessage {
type: 'button' | 'list';
header?: {
type: 'text' | 'image' | 'video' | 'document';
text?: string;
media?: string;
};
body: {
text: string;
};
footer?: {
text: string;
};
action: ButtonAction | ListAction;
}
interface ButtonAction {
buttons: Button[];
}
interface Button {
type: 'reply' | 'url' | 'call';
reply?: {
id: string;
title: string;
};
url?: {
displayText: string;
url: string;
};
call?: {
displayText: string;
phoneNumber: string;
};
}
interface ListAction {
button: string;
sections: ListSection[];
}
interface ListSection {
title?: string;
rows: ListRow[];
}
interface ListRow {
id: string;
title: string;
description?: string;
}
interface Poll {
name: string;
options: string[];
selectableCount?: number;
}
interface PollVote {
pollMessageId: string;
optionNames: string[];
}
interface PresenceUpdate {
tel: string;
chatId: string;
presence: 'available' | 'composing' | 'recording' | 'paused';
}
interface PrivacySettings {
lastSeen?: 'all' | 'contacts' | 'contact_blacklist' | 'none';
online?: 'all' | 'match_last_seen';
profilePhoto?: 'all' | 'contacts' | 'contact_blacklist' | 'none';
status?: 'all' | 'contacts' | 'contact_blacklist' | 'none';
readReceipts?: 'all' | 'none';
groupAdd?: 'all' | 'contacts' | 'contact_blacklist';
disappearingDuration?: number;
}
interface ApiError extends Error {
status?: number;
code?: string;
details?: any;
}
interface ClientOptions extends AuthConfig {
retryConfig?: {
retries?: number;
retryDelay?: number;
retryCondition?: (error: any) => boolean;
};
headers?: Record<string, string>;
}
declare class BaseClient {
protected axiosInstance: AxiosInstance;
protected apiToken: string;
protected baseUrl: string;
constructor(options: ClientOptions);
private setupRetryInterceptor;
private handleError;
protected get<T>(path: string, config?: AxiosRequestConfig): Promise<T>;
protected post<T>(path: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
protected put<T>(path: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
protected delete<T>(path: string, config?: AxiosRequestConfig): Promise<T>;
protected patch<T>(path: string, data?: any, config?: AxiosRequestConfig): Promise<T>;
/**
* Update the API token
*/
setApiToken(token: string): void;
/**
* Get the current base URL
*/
getBaseUrl(): string;
}
declare class Sessions {
private client;
constructor(client: BaseClient);
/**
* List all sessions
* @param environment - Filter by environment (optional)
*/
list(environment?: string): Promise<{
sessions: Session[];
count: number;
}>;
/**
* Get session details
* @param tel - Phone number
*/
get(tel: string): Promise<Session>;
/**
* Create a new session
* @param data - Session creation data
*/
create(data: CreateSessionRequest): Promise<Session>;
/**
* Update session details
* @param tel - Phone number
* @param data - Update data
*/
update(tel: string, data: UpdateSessionRequest): Promise<Session>;
/**
* Initialize session (start connection and generate QR code)
* @param tel - Phone number
*/
initialize(tel: string): Promise<{
message: string;
}>;
/**
* Reset session (disconnect and clear auth)
* @param tel - Phone number
*/
reset(tel: string): Promise<{
message: string;
}>;
/**
* Delete session permanently
* @param tel - Phone number
*/
delete(tel: string): Promise<{
message: string;
}>;
/**
* Poll for session status (useful for checking QR code availability)
* @param tel - Phone number
* @param maxAttempts - Maximum polling attempts
* @param interval - Polling interval in milliseconds
*/
pollForQR(tel: string, maxAttempts?: number, interval?: number): Promise<Session>;
/**
* Wait for session to be ready (connected)
* @param tel - Phone number
* @param maxAttempts - Maximum polling attempts
* @param interval - Polling interval in milliseconds
*/
waitForReady(tel: string, maxAttempts?: number, interval?: number): Promise<Session>;
}
declare class Messages {
private client;
constructor(client: BaseClient);
/**
* Send a text or media message
* @param data - Message data
*/
send(data: SendMessageRequest): Promise<Message>;
/**
* Send a text message (convenience method)
* @param tel - Sender phone number
* @param to - Recipient ID
* @param text - Message text
* @param options - Additional options
*/
sendText(tel: string, to: string, text: string, options?: SendMessageRequest['options']): Promise<Message>;
/**
* Send a media message (convenience method)
* @param tel - Sender phone number
* @param to - Recipient ID
* @param media - Base64 encoded media
* @param mimetype - Media MIME type
* @param filename - Media filename
* @param caption - Optional caption
*/
sendMedia(tel: string, to: string, media: string, mimetype: string, filename: string, caption?: string): Promise<Message>;
/**
* Send an interactive message (buttons or list)
* @param tel - Sender phone number
* @param to - Recipient ID
* @param interactive - Interactive message data
*/
sendInteractive(tel: string, to: string, interactive: InteractiveMessage): Promise<Message>;
/**
* Send a poll
* @param tel - Sender phone number
* @param to - Recipient ID
* @param poll - Poll data
*/
sendPoll(tel: string, to: string, poll: Poll): Promise<Message>;
/**
* Vote on a poll
* @param tel - Voter phone number
* @param vote - Vote data
*/
votePoll(tel: string, vote: PollVote): Promise<{
success: boolean;
}>;
/**
* List messages with filtering and pagination
* @param params - Query parameters
*/
list(params?: ListMessagesParams): Promise<{
messages: Message[];
count: number;
total: number;
}>;
/**
* Get a single message by ID
* @param id - Message database ID
*/
get(id: string): Promise<Message>;
/**
* Download media from a message
* @param id - Message database ID
*/
downloadMedia(id: string): Promise<{
data: string;
mimetype: string;
filename: string;
}>;
/**
* Delete a message
* @param tel - Phone number
* @param messageId - WhatsApp message ID
* @param forEveryone - Delete for everyone
*/
delete(tel: string, messageId: string, forEveryone?: boolean): Promise<{
success: boolean;
}>;
/**
* React to a message
* @param tel - Phone number
* @param messageId - Message to react to
* @param emoji - Emoji reaction
*/
react(tel: string, messageId: string, emoji: string): Promise<{
success: boolean;
}>;
/**
* Remove a reaction from a message
* @param tel - Phone number
* @param messageId - Message to remove reaction from
*/
removeReaction(tel: string, messageId: string): Promise<{
success: boolean;
}>;
/**
* Get reactions for a message
* @param messageId - Message ID to get reactions for
*/
getReactions(messageId: string): Promise<{
success: boolean;
data: Array<{
emoji: string;
from: string;
timestamp: number;
}>;
}>;
/**
* Edit a message
* @param tel - Phone number
* @param messageId - Message to edit
* @param newText - New message text
*/
edit(tel: string, messageId: string, newText: string): Promise<{
success: boolean;
}>;
/**
* Pin a message
* @param tel - Phone number
* @param messageId - Message to pin
* @param duration - Pin duration in seconds (0 = forever)
*/
pin(tel: string, messageId: string, duration?: number): Promise<{
success: boolean;
}>;
/**
* Unpin a message
* @param tel - Phone number
* @param messageId - Message to unpin
*/
unpin(tel: string, messageId: string): Promise<{
success: boolean;
}>;
/**
* Star a message
* @param tel - Phone number
* @param messageId - Message to star
*/
star(tel: string, messageId: string): Promise<{
success: boolean;
}>;
/**
* Unstar a message
* @param tel - Phone number
* @param messageId - Message to unstar
*/
unstar(tel: string, messageId: string): Promise<{
success: boolean;
}>;
/**
* Forward messages
* @param tel - Phone number
* @param to - Recipient IDs
* @param messageIds - Messages to forward
*/
forward(tel: string, to: string[], messageIds: string[]): Promise<{
success: boolean;
count: number;
}>;
/**
* Send typing indicator
* @param tel - Phone number
* @param to - Chat ID
* @param typing - true for typing, false for paused
*/
sendTyping(tel: string, to: string, typing?: boolean): Promise<{
success: boolean;
}>;
/**
* Mark messages as read
* @param tel - Phone number
* @param messageIds - Message IDs to mark as read
*/
markRead(tel: string, messageIds: string[]): Promise<{
success: boolean;
}>;
/**
* Send voice note
* @param tel - Phone number
* @param to - Recipient ID
* @param audioData - Base64 encoded audio data
* @param mimetype - Audio mimetype
* @param duration - Duration in seconds
*/
sendVoiceNote(tel: string, to: string, audioData: string, mimetype?: string, duration?: number): Promise<Message>;
/**
* Send location message
* @param tel - Phone number
* @param to - Recipient ID
* @param latitude - Latitude coordinate
* @param longitude - Longitude coordinate
* @param name - Location name
* @param address - Location address
*/
sendLocation(tel: string, to: string, latitude: number, longitude: number, name?: string, address?: string): Promise<Message>;
/**
* Send live location message
* @param tel - Phone number
* @param to - Recipient ID
* @param latitude - Latitude coordinate
* @param longitude - Longitude coordinate
* @param duration - Sharing duration in seconds
*/
sendLiveLocation(tel: string, to: string, latitude: number, longitude: number, duration?: number): Promise<Message>;
/**
* Send buttons message
* @param tel - Phone number
* @param to - Recipient ID
* @param text - Message text
* @param buttons - Array of buttons
* @param headerText - Optional header text
* @param footerText - Optional footer text
*/
sendButtons(tel: string, to: string, text: string, buttons: Array<{
id: string;
text: string;
type?: 'reply' | 'call' | 'url';
data?: string;
}>, headerText?: string, footerText?: string): Promise<Message>;
/**
* Send list message
* @param tel - Phone number
* @param to - Recipient ID
* @param title - List title
* @param buttonText - Button text
* @param sections - List sections
*/
sendList(tel: string, to: string, title: string, buttonText: string, sections: Array<{
title: string;
rows: Array<{
id: string;
title: string;
description?: string;
}>;
}>): Promise<Message>;
/**
* Send sticker message
* @param tel - Phone number
* @param to - Recipient ID
* @param stickerData - Base64 encoded sticker data (WebP format)
*/
sendSticker(tel: string, to: string, stickerData: string): Promise<Message>;
/**
* Send album/multiple media
* @param tel - Phone number
* @param to - Recipient ID
* @param media - Array of media items
* @param caption - Shared caption
*/
sendAlbum(tel: string, to: string, media: Array<{
data: string;
mimetype: string;
filename?: string;
caption?: string;
}>, caption?: string): Promise<Message>;
}
interface Chat {
_id: string;
id: any;
tel: string;
name: string;
isGroup: boolean;
unreadCount: number;
timestamp: number;
archived: boolean;
pinned: boolean;
profilePicUrl?: string;
isMuted: boolean;
lastMessage?: {
id: any;
body: string;
from: string;
timestamp: number;
type: string;
fromMe: boolean;
};
groupMetadata?: {
id: string;
subject: string;
desc?: string;
owner?: string;
participants: Array<{
id: string;
admin?: 'admin' | 'superadmin' | null;
}>;
};
participants?: string[];
description?: string;
createdAt: Date;
updatedAt: Date;
}
interface ChatFilters {
tel?: string;
groups?: boolean;
unreadOnly?: boolean;
archived?: boolean;
search?: string;
limit?: number;
offset?: number;
}
interface ChatsResponse {
success: boolean;
data: {
chats: Chat[];
total: number;
page: number;
limit: number;
};
}
interface ChatResponse {
success: boolean;
data: Chat;
}
declare class Chats {
private client;
constructor(client: BaseClient);
/**
* List all chats with optional filtering
* @param params - Query parameters for filtering
*/
list(params?: ChatFilters): Promise<ChatsResponse>;
/**
* Get a specific chat by ID
* @param tel - Phone number
* @param chatId - Chat ID
*/
get(tel: string, chatId: string): Promise<ChatResponse>;
/**
* Mark chat as read
* @param tel - Phone number
* @param chatId - Chat ID
*/
markAsRead(tel: string, chatId: string): Promise<{
success: boolean;
}>;
/**
* Send typing indicator to chat
* @param tel - Phone number
* @param chatId - Chat ID
*/
sendTyping(tel: string, chatId: string): Promise<{
success: boolean;
}>;
/**
* Archive or unarchive a chat
* @param tel - Phone number
* @param chatId - Chat ID
* @param archived - Archive status
*/
archive(tel: string, chatId: string, archived?: boolean): Promise<{
success: boolean;
}>;
/**
* Pin or unpin a chat
* @param tel - Phone number
* @param chatId - Chat ID
* @param pinned - Pin status
*/
pin(tel: string, chatId: string, pinned?: boolean): Promise<{
success: boolean;
}>;
/**
* Mute or unmute a chat
* @param tel - Phone number
* @param chatId - Chat ID
* @param muted - Mute status
*/
mute(tel: string, chatId: string, muted?: boolean): Promise<{
success: boolean;
}>;
/**
* Clear chat history
* @param tel - Phone number
* @param chatId - Chat ID
*/
clearHistory(tel: string, chatId: string): Promise<{
success: boolean;
}>;
/**
* Update multiple chat properties at once
* @param tel - Phone number
* @param chatId - Chat ID
* @param updates - Properties to update
*/
update(tel: string, chatId: string, updates: {
archived?: boolean;
pinned?: boolean;
muted?: boolean;
}): Promise<{
success: boolean;
}>;
/**
* Get group chats only
* @param tel - Phone number
* @param params - Additional query parameters
*/
getGroups(tel: string, params?: Omit<ChatFilters, 'tel' | 'groups'>): Promise<ChatsResponse>;
/**
* Get individual chats only
* @param tel - Phone number
* @param params - Additional query parameters
*/
getIndividual(tel: string, params?: Omit<ChatFilters, 'tel' | 'groups'>): Promise<ChatsResponse>;
/**
* Get unread chats only
* @param tel - Phone number
* @param params - Additional query parameters
*/
getUnread(tel: string, params?: Omit<ChatFilters, 'tel' | 'unreadOnly'>): Promise<ChatsResponse>;
/**
* Get archived chats
* @param tel - Phone number
* @param params - Additional query parameters
*/
getArchived(tel: string, params?: Omit<ChatFilters, 'tel' | 'archived'>): Promise<ChatsResponse>;
/**
* Search chats by name or content
* @param tel - Phone number
* @param query - Search query
* @param params - Additional query parameters
*/
search(tel: string, query: string, params?: Omit<ChatFilters, 'tel' | 'search'>): Promise<ChatsResponse>;
}
declare class Contacts {
private client;
constructor(client: BaseClient);
/**
* List all contacts
* @param tel - Phone number
* @param search - Optional search query
*/
list(tel: string, search?: string): Promise<Contact[]>;
/**
* Get contact details
* @param tel - Phone number
* @param contactId - Contact ID
*/
get(tel: string, contactId: string): Promise<Contact>;
/**
* Check if numbers are registered on WhatsApp
* @param tel - Phone number
* @param numbers - Array of phone numbers to check
*/
checkRegistered(tel: string, numbers: string[]): Promise<{
[number: string]: boolean;
}>;
/**
* Get contact profile picture
* @param tel - Phone number
* @param contactId - Contact ID
*/
getProfilePicture(tel: string, contactId: string): Promise<{
url: string;
}>;
/**
* Get contact status/about
* @param tel - Phone number
* @param contactId - Contact ID
*/
getStatus(tel: string, contactId: string): Promise<{
status: string;
}>;
/**
* Block a contact
* @param tel - Phone number
* @param contactId - Contact ID to block
*/
block(tel: string, contactId: string): Promise<{
success: boolean;
}>;
/**
* Unblock a contact
* @param tel - Phone number
* @param contactId - Contact ID to unblock
*/
unblock(tel: string, contactId: string): Promise<{
success: boolean;
}>;
/**
* Get blocked contacts
* @param tel - Phone number
*/
getBlocked(tel: string): Promise<string[]>;
/**
* Get business profile of a contact
* @param tel - Phone number
* @param contactId - Business contact ID
*/
getBusinessProfile(tel: string, contactId: string): Promise<any>;
}
declare class Groups {
private client;
constructor(client: BaseClient);
/**
* List all groups
* @param tel - Phone number
*/
list(tel: string): Promise<Group[]>;
/**
* Get group details
* @param tel - Phone number
* @param groupId - Group ID
*/
get(tel: string, groupId: string): Promise<Group>;
/**
* Create a new group
* @param data - Group creation data
*/
create(data: CreateGroupRequest): Promise<Group>;
/**
* Update group details
* @param tel - Phone number
* @param groupId - Group ID
* @param data - Update data
*/
update(tel: string, groupId: string, data: UpdateGroupRequest): Promise<{
success: boolean;
}>;
/**
* Leave a group
* @param tel - Phone number
* @param groupId - Group ID
*/
leave(tel: string, groupId: string): Promise<{
success: boolean;
}>;
/**
* Add participants to a group
* @param tel - Phone number
* @param groupId - Group ID
* @param participants - Array of participant IDs
*/
addParticipants(tel: string, groupId: string, participants: string[]): Promise<{
success: boolean;
added: string[];
failed: string[];
}>;
/**
* Remove participants from a group
* @param tel - Phone number
* @param groupId - Group ID
* @param participants - Array of participant IDs
*/
removeParticipants(tel: string, groupId: string, participants: string[]): Promise<{
success: boolean;
}>;
/**
* Promote participants to admin
* @param tel - Phone number
* @param groupId - Group ID
* @param participants - Array of participant IDs
*/
promoteParticipants(tel: string, groupId: string, participants: string[]): Promise<{
success: boolean;
}>;
/**
* Demote participants from admin
* @param tel - Phone number
* @param groupId - Group ID
* @param participants - Array of participant IDs
*/
demoteParticipants(tel: string, groupId: string, participants: string[]): Promise<{
success: boolean;
}>;
/**
* Get group invite link
* @param tel - Phone number
* @param groupId - Group ID
*/
getInviteLink(tel: string, groupId: string): Promise<{
code: string;
url: string;
}>;
/**
* Revoke group invite link
* @param tel - Phone number
* @param groupId - Group ID
*/
revokeInviteLink(tel: string, groupId: string): Promise<{
code: string;
url: string;
}>;
/**
* Accept group invite
* @param tel - Phone number
* @param inviteCode - Invite code
*/
acceptInvite(tel: string, inviteCode: string): Promise<{
groupId: string;
}>;
/**
* Set group profile picture
* @param tel - Phone number
* @param groupId - Group ID
* @param image - Base64 encoded image
*/
setProfilePicture(tel: string, groupId: string, image: string): Promise<{
success: boolean;
}>;
/**
* Remove group profile picture
* @param tel - Phone number
* @param groupId - Group ID
*/
removeProfilePicture(tel: string, groupId: string): Promise<{
success: boolean;
}>;
/**
* Get group members who have read a message
* @param tel - Phone number
* @param groupId - Group ID
* @param messageId - Message ID
*/
getMessageReaders(tel: string, groupId: string, messageId: string): Promise<string[]>;
/**
* Toggle group settings
* @param tel - Phone number
* @param groupId - Group ID
* @param setting - Setting to toggle
* @param value - New value
*/
toggleSetting(tel: string, groupId: string, setting: 'announce' | 'restrict' | 'locked', value: boolean): Promise<{
success: boolean;
}>;
}
declare class Status {
private client;
constructor(client: BaseClient);
/**
* Get all status updates
* @param tel - Phone number
*/
list(tel: string): Promise<Status$1[]>;
/**
* Get status updates from a specific contact
* @param tel - Phone number
* @param contactId - Contact ID
*/
getContactStatus(tel: string, contactId: string): Promise<Status$1[]>;
/**
* Post a new status update
* @param data - Status update data
*/
post(data: StatusUpdate): Promise<{
id: string;
}>;
/**
* Post a text status
* @param tel - Phone number
* @param content - Status text
* @param backgroundColor - Background color (hex)
* @param font - Font style (0-5)
*/
postText(tel: string, content: string, backgroundColor?: string, font?: number): Promise<{
id: string;
}>;
/**
* Post an image status
* @param tel - Phone number
* @param media - Base64 encoded image
* @param caption - Optional caption
*/
postImage(tel: string, media: string, caption?: string): Promise<{
id: string;
}>;
/**
* Post a video status
* @param tel - Phone number
* @param media - Base64 encoded video
* @param caption - Optional caption
*/
postVideo(tel: string, media: string, caption?: string): Promise<{
id: string;
}>;
/**
* Delete a status update
* @param tel - Phone number
* @param statusId - Status ID to delete
*/
delete(tel: string, statusId: string): Promise<{
success: boolean;
}>;
/**
* Mark status as seen
* @param tel - Phone number
* @param statusId - Status ID
*/
markSeen(tel: string, statusId: string): Promise<{
success: boolean;
}>;
/**
* Get status privacy settings
* @param tel - Phone number
*/
getPrivacySettings(tel: string): Promise<{
blacklist: string[];
whitelist: string[];
mode: 'all' | 'contacts' | 'contact_blacklist' | 'selected';
}>;
/**
* Update status privacy settings
* @param tel - Phone number
* @param settings - Privacy settings
*/
updatePrivacySettings(tel: string, settings: {
mode?: 'all' | 'contacts' | 'contact_blacklist' | 'selected';
blacklist?: string[];
whitelist?: string[];
}): Promise<{
success: boolean;
}>;
/**
* Download status media
* @param tel - Phone number
* @param statusId - Status ID
*/
downloadMedia(tel: string, statusId: string): Promise<{
data: string;
mimetype: string;
filename: string;
}>;
/**
* Get who viewed a status
* @param tel - Phone number
* @param statusId - Status ID
*/
getViewers(tel: string, statusId: string): Promise<string[]>;
}
declare class Webhooks {
private client;
constructor(client: BaseClient);
/**
* Get all webhooks for a session
* @param tel - Phone number
*/
list(tel: string): Promise<Webhook[]>;
/**
* Get webhook details
* @param tel - Phone number
* @param webhookId - Webhook ID
*/
get(tel: string, webhookId: string): Promise<Webhook>;
/**
* Create a new webhook for a session
* @param tel - Phone number
* @param data - Webhook creation data
*/
create(tel: string, data: Omit<CreateWebhookRequest, 'tel'>): Promise<Webhook & {
secret: string;
}>;
/**
* Update webhook details
* @param tel - Phone number
* @param webhookId - Webhook ID
* @param data - Update data
*/
update(tel: string, webhookId: string, data: Omit<UpdateWebhookRequest, 'tel' | 'webhookId'>): Promise<Webhook>;
/**
* Delete a webhook
* @param tel - Phone number
* @param webhookId - Webhook ID
*/
delete(tel: string, webhookId: string): Promise<{
message: string;
}>;
/**
* Test a webhook
* @param tel - Phone number
* @param webhookId - Webhook ID
*/
test(tel: string, webhookId: string): Promise<WebhookTestResult>;
/**
* Rotate webhook secret
* @param tel - Phone number
* @param webhookId - Webhook ID
*/
rotateSecret(tel: string, webhookId: string): Promise<{
id: string;
name: string;
secret: string;
}>;
/**
* Get webhook logs and statistics
* @param tel - Phone number
* @param webhookId - Webhook ID
*/
getLogs(tel: string, webhookId: string): Promise<{
name: string;
url: string;
statistics: Webhook['statistics'];
}>;
/**
* Toggle webhook active status
* @param tel - Phone number
* @param webhookId - Webhook ID
* @param active - Active status
*/
toggleActive(tel: string, webhookId: string, active: boolean): Promise<Webhook>;
/**
* Bulk create webhooks for multiple events
* @param tel - Phone number
* @param url - Webhook URL
* @param events - Array of events to subscribe to
* @param options - Optional webhook configuration
*/
createForEvents(tel: string, url: string, events: string[], options?: {
name?: string;
headers?: Record<string, string>;
retryConfig?: {
maxAttempts: number;
backoffMultiplier: number;
initialDelay: number;
};
}): Promise<Webhook & {
secret: string;
}>;
/**
* Quick setup for message events
* @param tel - Phone number
* @param url - Webhook URL
* @param name - Optional webhook name
*/
setupMessageWebhook(tel: string, url: string, name?: string): Promise<Webhook & {
secret: string;
}>;
/**
* Quick setup for session events
* @param tel - Phone number
* @param url - Webhook URL
* @param name - Optional webhook name
*/
setupSessionWebhook(tel: string, url: string, name?: string): Promise<Webhook & {
secret: string;
}>;
}
interface User {
_id: string;
name: string;
email: string;
role: 'super_admin' | 'owner' | 'employee';
provider: 'credentials' | 'oauth';
active: boolean;
lastLogin?: Date;
createdAt: Date;
updatedAt: Date;
}
interface Token {
_id: string;
token: string;
name: string;
userId: string;
sessionId?: string;
permissions: string[];
allowedPhoneNumbers: string[];
active: boolean;
expiresAt?: Date;
lastUsed?: Date;
usageCount: number;
createdAt: Date;
updatedAt: Date;
}
interface CreateUserRequest {
name: string;
email: string;
role: 'super_admin' | 'owner' | 'employee';
provider: 'credentials' | 'oauth';
password?: string;
}
interface UpdateUserRequest {
name?: string;
role?: 'super_admin' | 'owner' | 'employee';
active?: boolean;
}
interface CreateTokenRequest {
name: string;
userId: string;
sessionId?: string;
permissions: string[];
allowedPhoneNumbers?: string[];
expiresAt?: string;
}
interface UpdateTokenRequest {
name?: string;
permissions?: string[];
allowedPhoneNumbers?: string[];
active?: boolean;
expiresAt?: string;
}
interface UsersResponse {
success: boolean;
data: {
users: User[];
total: number;
page: number;
limit: number;
};
}
interface UserResponse {
success: boolean;
data: User;
}
interface TokensResponse {
success: boolean;
data: {
tokens: Token[];
total: number;
page: number;
limit: number;
};
}
interface TokenResponse {
success: boolean;
data: Token;
}
interface TokenCreationResponse {
success: boolean;
data: Token & {
token: string;
};
}
declare class Admin {
private client;
constructor(client: BaseClient);
/**
* List all users
* @param params - Query parameters for filtering and pagination
*/
listUsers(params?: {
search?: string;
role?: string;
active?: boolean;
limit?: number;
offset?: number;
}): Promise<UsersResponse>;
/**
* Get a specific user by ID
* @param userId - User ID
*/
getUser(userId: string): Promise<UserResponse>;
/**
* Create a new user
* @param userData - User creation data
*/
createUser(userData: CreateUserRequest): Promise<UserResponse>;
/**
* Update an existing user
* @param userId - User ID
* @param updates - User update data
*/
updateUser(userId: string, updates: UpdateUserRequest): Promise<UserResponse>;
/**
* Deactivate a user
* @param userId - User ID
*/
deactivateUser(userId: string): Promise<{
success: boolean;
}>;
/**
* Delete a user permanently
* @param userId - User ID
*/
deleteUser(userId: string): Promise<{
success: boolean;
}>;
/**
* List all API tokens
* @param params - Query parameters for filtering and pagination
*/
listTokens(params?: {
search?: string;
userId?: string;
sessionId?: string;
active?: boolean;
limit?: number;
offset?: number;
}): Promise<TokensResponse>;
/**
* Get a specific token by ID
* @param tokenId - Token ID
*/
getToken(tokenId: string): Promise<TokenResponse>;
/**
* Create a new API token
* @param tokenData - Token creation data
*/
createToken(tokenData: CreateTokenRequest): Promise<TokenCreationResponse>;
/**
* Update an existing token
* @param tokenId - Token ID
* @param updates - Token update data
*/
updateToken(tokenId: string, updates: UpdateTokenRequest): Promise<TokenResponse>;
/**
* Revoke a token (set inactive)
* @param tokenId - Token ID
*/
revokeToken(tokenId: string): Promise<{
success: boolean;
}>;
/**
* Rotate a token (generate new token value)
* @param tokenId - Token ID
*/
rotateToken(tokenId: string): Promise<TokenCreationResponse>;
/**
* Delete a token permanently
* @param tokenId - Token ID
*/
deleteToken(tokenId: string): Promise<{
success: boolean;
}>;
/**
* Assign users to a session
* @param tel - Session phone number
* @param userIds - Array of user IDs to assign
*/
assignUsersToSession(tel: string, userIds: string[]): Promise<{
success: boolean;
}>;
/**
* Assign tokens to a session
* @param tel - Session phone number
* @param tokenIds - Array of token IDs to assign
*/
assignTokensToSession(tel: string, tokenIds: string[]): Promise<{
success: boolean;
}>;
/**
* Get system analytics
* @param period - Time period ('day', 'week', 'month')
*/
getSystemAnalytics(period?: 'day' | 'week' | 'month'): Promise<{
success: boolean;
data: {
users: {
total: number;
active: number;
new: number;
};
tokens: {
total: number;
active: number;
usage: number;
};
sessions: {
total: number;
connected: number;
active: number;
};
messages: {
sent: number;
received: number;
total: number;
};
};
}>;
/**
* Get user analytics
* @param userId - User ID
* @param period - Time period
*/
getUserAnalytics(userId: string, period?: 'day' | 'week' | 'month'): Promise<{
success: boolean;
data: {
tokens: number;
sessions: number;
messages: number;
lastActive: string;
usage: Array<{
date: string;
requests: number;
}>;
};
}>;
/**
* Get token analytics
* @param tokenId - Token ID
* @param period - Time period
*/
getTokenAnalytics(tokenId: string, period?: 'day' | 'week' | 'month'): Promise<{
success: boolean;
data: {
usage: number;
endpoints: Record<string, number>;
errors: number;
lastUsed: string;
usage_history: Array<{
date: string;
requests: number;
}>;
};
}>;
}
interface Product {
_id: string;
tel: string;
productId: string;
title: string;
description?: string;
price?: string;
currency?: string;
imageUrl?: string;
category?: string;
visibility: 'visible' | 'hidden';
inStock: boolean;
inventory?: number;
sku?: string;
metadata?: Record<string, any>;
createdAt: Date;
updatedAt: Date;
}
interface Order {
_id: string;
tel: string;
orderId: string;
customerId: string;
status: 'pending' | 'confirmed' | 'processing' | 'shipped' | 'delivered' | 'cancelled';
items: Array<{
productId: string;
title: string;
quantity: number;
price: string;
currency: string;
}>;
total: {
amount: string;
currency: string;
};
shipping?: {
address: string;
city: string;
state: string;
postalCode: string;
country: string;
};
payment?: {
method: string;
status: 'pending' | 'paid' | 'failed' | 'refunded';
transactionId?: string;
};
notes?: string;
createdAt: Date;
updatedAt: Date;
}
interface Cart {
_id: string;
tel: string;
customerId: string;
items: Array<{
productId: string;
title: string;
quantity: number;
price: string;
currency: string;
}>;
total: {
amount: string;
currency: string;
};
expiresAt?: Date;
createdAt: Date;
updatedAt: Date;
}
interface CreateProductRequest {
tel: string;
title: string;
description?: string;
price: string;
currency: string;
imageUrl?: string;
category?: string;
visibility?: 'visible' | 'hidden';
inStock?: boolean;
inventory?: number;
sku?: string;
metadata?: Record<string, any>;
}
interface UpdateProductRequest {
title?: string;
description?: string;
price?: string;
currency?: string;
imageUrl?: string;
category?: string;
visibility?: 'visible' | 'hidden';
inStock?: boolean;
inventory?: number;
sku?: string;
metadata?: Record<string, any>;
}
interface ProductsResponse {
success: boolean;
data: {
products: Product[];
total: number;
page: number;
limit: number;
};
}
interface ProductResponse {
success: boolean;
data: Product;
}
interface OrdersResponse {
success: boolean;
data: {
orders: Order[];
total: number;
page: number;
limit: number;
};
}
interface OrderResponse {
success: boolean;
data: Order;
}
interface CartResponse {
success: boolean;
data: Cart;
}
declare class Business {
private client;
constructor(client: BaseClient);
/**
* List all products for a session
* @param tel - Phone number
* @param params - Query parameters for filtering and pagination
*/
listProducts(tel: string, params?: {
category?: string;
visibility?: 'visible' | 'hidden';
inStock?: boolean;
search?: string;
limit?: number;
offset?: number;
}): Promise<ProductsResponse>;
/**
* Get a specific product by ID
* @param tel - Phone number
* @param productId - Product ID
*/
getProduct(tel: string, productId: string): Promise<ProductResponse>;
/**
* Create a new product
* @param productData - Product creation data
*/
createProduct(productData: CreateProductRequest): Promise<ProductResponse>;
/**
* Update an existing product
* @param tel - Phone number
* @param productId - Product ID
* @param updates - Product update data
*/
updateProduct(tel: string, productId: string, updates: UpdateProductRequest): Promise<ProductResponse>;
/**
* Delete a product
* @param tel - Phone number
* @param productId - Product ID
*/
deleteProduct(tel: string, productId: string): Promise<{
success: boolean;
}>;
/**
* Update product inventory
* @param tel - Phone number
* @param productId - Product ID
* @param inventory - New inventory count
* @param inStock - Stock status
*/
updateInventory(tel: string, productId: string, inventory: number, inStock?: boolean): Promise<ProductResponse>;
/**
* List all orders for a session
* @param tel - Phone number
* @param params - Query parameters for filtering and pagination
*/
listOrders(tel: string, params?: {
status?: string;
customerId?: string;
fromDate?: string;
toDate?: string;
limit?: number;
offset?: number;
}): Promise<OrdersResponse>;
/**
* Get a specific order by ID
* @param tel - Phone number
* @param orderId - Order ID
*/
getOrder(tel: string, orderId: string): Promise<OrderResponse>;
/**
* Confirm an order
* @param tel - Phone number
* @param orderId - Order ID
* @param notes - Optional confirmation notes
*/
confirmOrder(tel: string, orderId: string, notes?: string): Promise<OrderResponse>;
/**
* Update order status
* @param tel - Phone number
* @param orderId - Order ID
* @param status - New order status
* @param notes - Optional status update notes
*/
updateOrderStatus(tel: string, orderId: string, status: 'pending' | 'confirmed' | 'processing' | 'shipped' | 'delivered' | 'cancelled', notes?: string): Promise<OrderResponse>;
/**
* Cancel an order
* @param tel - Phone number
* @param orderId - Order ID
* @param reason - Cancellation reason
*/
cancelOrder(tel: string, orderId: string, reason?: string): Promise<OrderResponse>;
/**
* Create a new shopping cart for a customer
* @param tel - Phone number
* @param customerId - Customer ID
* @param expirationHours - Cart expiration in hours (default: 24)
*/
createCart(tel: string, customerId: string, expirationHours?: number): Promise<CartResponse>;
/**
* Get a customer's cart
* @param tel - Phone number
* @param customerId - Customer ID
*/
getCart(tel: string, customerId: string): Promise<CartResponse>;
/**
* Add item to cart
* @param tel - Phone number
* @param customerId - Customer ID
* @param productId - Product ID to add
* @param quantity - Quantity to add
*/
addToCart(tel: string, customerId: string, productId: string, quantity?: number): Promise<CartResponse>;
/**
* Update item quantity in cart
* @param tel - Phone number
* @param customerId - Customer ID
* @param productId - Product ID to update
* @param quantity - New quantity
*/
updateCartItem(tel: string, customerId: string, productId: string, quantity: number): Promise<CartResponse>;
/**
* Remove item from cart
* @param tel - Phone number
* @param customerId - Customer ID
* @param productId - Product ID to remove
*/
removeFromCart(tel: string, customerId: string, productId: string): Promise<CartResponse>;
/**
* Clear entire cart
* @param tel - Phone number
* @param customerId - Customer ID
*/
clearCart(tel: string, customerId: string): Promise<{
success: boolean;
}>;
/**
* Convert cart to order
* @param tel - Phone number
* @param customerId - Customer ID
* @param shipping - Shipping informati