import { BaseClient } from "./base-client"; import { Instance, Settings, SendMessage, SendFileByUrl, SendFileByUpload, SendPoll, StateInstance, Reboot, Logout, QR, SendResponse, SendFileByUploadResponse, SetSettingsResponse, GetAuthorizationCode, SetProfilePicture, WaSettings, UploadFile, SendLocation, SendContact, ForwardMessages, ForwardMessagesResponse, QueueMessage, ClearMessagesQueue, ReadChatResponse, ReadChat, CheckWhatsapp, CheckWhatsappResponse, GetAvatarResponse, GetAvatar, Contact, ContactInfo, ArchiveChat, UnarchiveChat, SetDisappearingChat, SetDisappearingChatResponse, CreateGroupResponse, CreateGroup, UpdateGroupName, UpdateGroupNameResponse, GetGroupData, GroupData, AddGroupParticipant, AddGroupParticipantResponse, RemoveGroupParticipant, RemoveGroupParticipantResponse, SetGroupAdmin, SetGroupAdminResponse, RemoveAdminResponse, RemoveAdmin, SetGroupPicture, SetGroupPictureResponse, LeaveGroup, LeaveGroupResponse, GetMessage, JournalResponse, GetChatHistory, IncomingJournalResponse, OutgoingJournalResponse, DownloadFileResponse, DownloadFileRequest, DeleteNotificationResponse, ReceiveNotificationResponse, DeleteMessageRequest, EditMessageRequest, EditMessageResponse, DeleteStatus, GetIncomingStatusesParams, GetOutgoingStatusesParams, GetStatusStatistic, GetStatusStatisticResponse, IncomingStatusMessage, OutgoingStatusMessage, SendMediaStatus, SendMediaStatusResponse, SendTextStatus, SendTextStatusResponse, SendVoiceStatus, SendVoiceStatusResponse, AddContact, EditContact, DeleteContact, AddContactResponse, DeleteContactResponse, EditContactResponse } from "../types"; /** * Client for direct interaction with GREEN-API's WhatsApp gateway. * Provides methods for sending messages, managing instances, and handling files. * For more information about the methods, refer to https://green-api.com/en/docs * * @example * ```typescript * const client = new GreenApiClient({ * idInstance: 12345, * apiTokenInstance: "your-token" * }); * * await client.sendMessage({ * chatId: "1234567890@c.us", * message: "Hello from GREEN-API!" * }); * ``` */ export declare class GreenApiClient extends BaseClient { /** * Creates a GREEN-API client instance. * * @param instance - Configuration containing idInstance and apiTokenInstance */ constructor(instance: Instance); /** * Validates that a phone number is a positive integer with correct length. * * @param phoneNumber - The phone number to validate * @throws Error if validation fails */ private validatePhoneNumber; /** * Sends a text message to a WhatsApp chat. * * @param message - Message data containing chat ID and text * @returns Promise resolving to send response with message ID * * @example * ```typescript * await client.sendMessage({ * chatId: "1234567890@c.us", * message: "Hello!", * quotedMessageId: "12345" // Optional: reply to a message * }); * ``` */ sendMessage(message: SendMessage): Promise; /** * Sends a file from a URL to a WhatsApp chat. * * @param message - Message data containing chat ID and file URL * @returns Promise resolving to send response * * @example * ```typescript * await client.sendFileByUrl({ * chatId: "1234567890@c.us", * file: { * url: "https://example.com/file.pdf", * fileName: "document.pdf" * }, * caption: "Check this file" // Optional * }); * ``` */ sendFileByUrl(message: SendFileByUrl): Promise; /** * Sends a file from local data to a WhatsApp chat. * * @param message - Message data containing chat ID and file data * @returns Promise resolving to send response with file URL * * @example * ```typescript * await client.sendFileByUpload({ * chatId: "1234567890@c.us", * file: { * data: fileBlob, * fileName: "image.jpg" * }, * caption: "Check this image" * }); * ``` */ sendFileByUpload(message: SendFileByUpload): Promise; /** * Creates a poll in a WhatsApp chat. * * @param message - Poll data with question and options * @returns Promise resolving to send response * * @example * ```typescript * await client.sendPoll({ * chatId: "1234567890@c.us", * message: "What's your favorite color?", * options: [{ optionName: "Red" }, { optionName: "Blue" }, { optionName: "Green" }], * multipleAnswers: false * }); * ``` */ sendPoll(message: SendPoll): Promise; /** * Forwards messages from one chat to another. * * @param request - Forward request with source and target chat IDs * @returns Promise resolving to forward response * * @example * ```typescript * await client.forwardMessages({ * chatId: "1234567890@c.us", // Destination chat * chatIdFrom: "9876543210@c.us", // Source chat * messages: ["message-id-1", "message-id-2"] * }); * ``` */ forwardMessages(request: ForwardMessages): Promise; /** * Sends a location to a WhatsApp chat. * * @param message - Location data with coordinates * @returns Promise resolving to send response * * @example * ```typescript * await client.sendLocation({ * chatId: "1234567890@c.us", * latitude: 51.5074, * longitude: -0.1278, * nameLocation: "London", * address: "London, UK" * }); * ``` */ sendLocation(message: SendLocation): Promise; /** * Sends a contact card to a WhatsApp chat. * * @param message - Contact data * @returns Promise resolving to send response * * @example * ```typescript * await client.sendContact({ * chatId: "1234567890@c.us", * contact: { * phoneContact: 1234567890, * firstName: "John", * lastName: "Doe" * } * }); * ``` */ sendContact(message: SendContact): Promise; /** * Uploads a file to GREEN-API servers. * * @param file - File to upload * @param customFileName - Optional custom name for the file * @returns Promise resolving to upload response with file URL */ uploadFile(file: Blob | File, customFileName?: string): Promise; /** * Reboots the GREEN-API instance. * * @returns Promise resolving to reboot status */ reboot(): Promise; /** * Logs out from the GREEN-API instance. * * @returns Promise resolving to logout status */ logout(): Promise; /** * Gets the current state of the GREEN-API instance. * * @returns Promise resolving to instance state */ getStateInstance(): Promise; /** * Gets the QR code for GREEN-API instance authentication. * * @returns Promise resolving to QR code data */ getQR(): Promise; /** * Gets current instance settings. * * @returns Promise resolving to settings object */ getSettings(): Promise; /** * Updates instance settings. * * @param settings - New settings to apply * @returns Promise resolving to settings update response */ setSettings(settings: Settings): Promise; /** * Gets WhatsApp-specific settings. * * @returns Promise resolving to WhatsApp settings */ getWaSettings(): Promise; /** * Sets the profile picture for the WhatsApp account. * * @param file - Image file to use as profile picture * @returns Promise resolving to profile picture update response */ setProfilePicture(file: Blob | File): Promise; /** * Gets authorization code for a phone number. * * @param phoneNumber - Phone number to get code for * @returns Promise resolving to authorization code response * @throws {Error} If phone number is invalid */ getAuthorizationCode(phoneNumber: number): Promise; /** * Gets the list of messages in the sending queue. * Messages are stored for 24 hours and will be sent immediately after phone authorization. * The sending speed is regulated by the Message Sending Interval parameter. * * @returns Promise resolving to an array of queued messages * * @example * ```typescript * const queuedMessages = await client.showMessagesQueue(); * console.log(queuedMessages); * ``` */ showMessagesQueue(): Promise; /** * Clears the queue of messages waiting to be sent. * Important when switching phone numbers to prevent sending queued messages with the new number. * * @returns Promise resolving to queue clearing status * * @example * ```typescript * const result = await client.clearMessagesQueue(); * if (result.isCleared) { * console.log('Queue successfully cleared'); * } * ``` */ clearMessagesQueue(): Promise; /** * Marks messages in a chat as read. * For this to work, "Receive webhooks on incoming messages and files" setting must be enabled. * Note: Only messages received after enabling the setting can be marked as read. * * @param params - Parameters specifying which messages to mark as read * @returns Promise resolving to read status * * @example * ```typescript * // Mark all messages in chat as read * const result = await client.readChat({ * chatId: "1234567890@c.us" * }); * * // Mark specific message as read * const result = await client.readChat({ * chatId: "1234567890@c.us", * idMessage: "B275A7AA0D6EF89BB9245169BDF174E6" * }); * ``` */ readChat(params: ReadChat): Promise; /** * Checks WhatsApp account availability on a phone number. * * @param params - Parameters containing the phone number to check * @returns Promise resolving to WhatsApp availability status * @throws {Error} If phone number is invalid * * @example * ```typescript * const result = await client.checkWhatsapp({ * phoneNumber: 11001234567 * }); * * if (result.existsWhatsapp) { * console.log('WhatsApp account exists'); * } * ``` */ checkWhatsapp(params: CheckWhatsapp): Promise; /** * Gets a user or group chat avatar. * * @param params - Parameters containing the chat ID * @returns Promise resolving to avatar information */ getAvatar(params: GetAvatar): Promise; /** * Gets a list of the current account contacts. * Note: Contact information updates can take up to 5 minutes. * If an empty array is received, retry the method call. * * @returns Promise resolving to array of contacts */ getContacts(): Promise; /** * Gets detailed information about a contact. * Note: This method does not support group chats, use getGroupData for groups. * * @param params - Parameters containing the chat ID * @returns Promise resolving to contact information */ getContactInfo(params: GetAvatar): Promise; /** * Archives a chat. Chat must have at least one incoming message. * Note: "Receive webhooks on incoming messages and files" setting must be enabled. * * @param params - Parameters containing the chat ID to archive * @returns Promise resolving to void on success */ archiveChat(params: ArchiveChat): Promise; /** * Unarchives a chat. * * @param params - Parameters containing the chat ID to unarchive * @returns Promise resolving to void on success */ unarchiveChat(params: UnarchiveChat): Promise; /** * Changes settings of disappearing messages in chats. * Valid expiration times: 0 (off), 86400 (24h), 604800 (7d), 7776000 (90d) * * @param params - Parameters containing chat ID and message expiration time * @returns Promise resolving to chat disappearing message settings */ setDisappearingChat(params: SetDisappearingChat): Promise; /** * Edits a text message in a personal or group chat. * WhatsApp imposes the following restrictions: * - There is a 15-minute time limit for editing messages * - Editing a message won't send a new chat notification * - You can't edit photos, videos, or other types of media * * @param params - Parameters containing chat ID, message ID and new text * @returns Promise resolving to edited message ID * * @example * ```typescript * const result = await client.editMessage({ * chatId: "1234567890@c.us", * idMessage: "BAE5367237E13A87", * message: "Edited message text" * }); * console.log('Edited message ID:', result.idMessage); * ``` */ editMessage(params: EditMessageRequest): Promise; /** * Deletes a message from a chat. * * @param params - Parameters containing chat ID, message ID and deletion options * @returns Promise resolving to void on success * * @example * ```typescript * // Delete message for everyone * await client.deleteMessage({ * chatId: "1234567890@c.us", * idMessage: "BAE5F4886F6F2D05" * }); * * // Delete message only for sender * await client.deleteMessage({ * chatId: "1234567890@c.us", * idMessage: "BAE5F4886F6F2D05", * onlySenderDelete: true * }); * ``` */ deleteMessage(params: DeleteMessageRequest): Promise; /** * Creates a group chat. * Note: Limited to creating 1 group per 5 minutes to simulate human behavior. * * @param params - Parameters containing group name and participant IDs * @returns Promise resolving to group creation result */ createGroup(params: CreateGroup): Promise; /** * Changes a group chat name. * * @param params - Parameters containing group ID and new name * @returns Promise resolving to update status */ updateGroupName(params: UpdateGroupName): Promise; /** * Gets group chat data. * Note: groupInviteLink will be empty if user is not an admin or owner. * * @param params - Parameters containing group ID * @returns Promise resolving to group data */ getGroupData(params: GetGroupData): Promise; /** * Adds a participant to a group chat. * Note: Only group administrators can add members. * The participant's number should be saved in the phonebook for reliable addition. * * @param params - Parameters containing group ID and participant ID * @returns Promise resolving to addition status */ addGroupParticipant(params: AddGroupParticipant): Promise; /** * Removes a participant from a group chat. * * @param params - Parameters containing group ID and participant ID to remove * @returns Promise resolving to removal status */ removeGroupParticipant(params: RemoveGroupParticipant): Promise; /** * Sets a group chat participant as an administrator. * * @param params - Parameters containing group ID and participant ID to promote * @returns Promise resolving to admin status change result */ setGroupAdmin(params: SetGroupAdmin): Promise; /** * Removes administrator rights from a group chat participant. * * @param params - Parameters containing group ID and participant ID to demote * @returns Promise resolving to admin removal status */ removeAdmin(params: RemoveAdmin): Promise; /** * Sets a group chat picture. * * @param params - Parameters containing group ID and picture file (jpg) * @returns Promise resolving to picture update status */ setGroupPicture(params: SetGroupPicture): Promise; /** * Makes the current account leave a group chat. * * @param params - Parameters containing the group ID to leave * @returns Promise resolving to leave status */ leaveGroup(params: LeaveGroup): Promise; /** * Gets details of a specific message. * Note: To receive incoming webhooks, requires "Receive webhooks on incoming messages and files" setting to be enabled. * Note: To receive statuses of sent messsages, requires "Receive notifications about the statuses of sent messages" to be enabled. * Messages can take up to 2 minutes to appear in the journal. * * @param params - Parameters containing chat ID and message ID * @returns Promise resolving to message details */ getMessage(params: GetMessage): Promise; /** * Gets chat message history. * Note: Requires "Receive webhooks" setting to be enabled. * Messages can take up to 2 minutes to appear in history. * * @param params - Parameters containing chat ID and optional message count * @returns Promise resolving to array of messages */ getChatHistory(params: GetChatHistory): Promise; /** * Gets last incoming messages for the specified time period. * Default is 24 hours (1440 minutes). * Note: Requires "Receive webhooks" setting to be enabled. * Messages can take up to 2 minutes to appear in history. * * @param minutes - Optional time period in minutes * @returns Promise resolving to array of incoming messages */ lastIncomingMessages(minutes?: number): Promise; /** * Gets last outgoing messages for the specified time period. * Default is 24 hours (1440 minutes). * Note: Requires "Receive webhooks" setting to be enabled. * Messages can take up to 2 minutes to appear in history. * * @param minutes - Optional time period in minutes * @returns Promise resolving to array of outgoing messages */ lastOutgoingMessages(minutes?: number): Promise; /** * Receives one incoming notification from the notification queue. * The method waits for a notification for the specified timeout period (default 5 seconds). * After receiving a notification, you need to delete it using deleteNotification method. * Notifications are stored in the queue for 24 hours and sent in FIFO order. * * @param timeout - Optional timeout in seconds (5-60, default 5) * @returns Promise resolving to notification data with receipt ID, or null if no notification is available * * @example * ```typescript * const notification = await client.receiveNotification(30); * if (notification) { * // Process notification * // Then delete it from queue * await client.deleteNotification(notification.receiptId); * } * ``` */ receiveNotification(timeout?: number): Promise; /** * Deletes an incoming notification from the notification queue. * After calling this method, the notification is considered processed and permanently deleted. * * @param receiptId - Receipt ID of the notification to delete * @returns Promise resolving to deletion result * * @example * ```typescript * const result = await client.deleteNotification(1234567); * console.log(result.result); // true if successfully deleted * ``` */ deleteNotification(receiptId: number): Promise; /** * Downloads a file from a message. * Files are stored for a limited time by WhatsApp. * * @param params - Parameters containing chat ID and message ID * @returns Promise resolving to download URL * * @example * ```typescript * const file = await client.downloadFile({ * chatId: "1234567890@c.us", * idMessage: "A322F800D3F12CD4858CC947DAFB77A2" * }); * console.log(file.downloadUrl); * ``` */ downloadFile(params: DownloadFileRequest): Promise; /** * Sends a text status update to WhatsApp (Beta feature). * The status will be added to the queue and kept for 24 hours until the instance is authorized. * For recipients to see the status, both parties must save each other's numbers in their contact lists. * * @param params - Text status parameters including message, styling, and recipient list * @returns Promise resolving to status send response with message ID * * @example * ```typescript * await client.sendTextStatus({ * message: "I use Green-API to send this Status!", * backgroundColor: "#228B22", // Use any color except white * font: "SERIF", * participants: ["70000001234@c.us"] // Optional: limit visibility to specific contacts * }); * ``` */ sendTextStatus(params: SendTextStatus): Promise; /** * Sends a voice status update to WhatsApp (Beta feature). * The status will be added to the queue and kept for 24 hours until the instance is authorized. * Recommended audio format is MP3, and audio longer than one minute will be cut. * For recipients to see the status, both parties must save each other's numbers in their contact lists. * * @param params - Voice status parameters including file URL, name, styling, and recipient list * @returns Promise resolving to status send response with message ID * * @example * ```typescript * await client.sendVoiceStatus({ * urlFile: "https://my.site.com/audio/voice.mp3", * fileName: "voice.mp3", * backgroundColor: "#228B22", * participants: ["70000001234@c.us"] // Optional: limit visibility to specific contacts * }); * ``` */ sendVoiceStatus(params: SendVoiceStatus): Promise; /** * Sends a picture or video status update to WhatsApp (Beta feature). * The status will be added to the queue and kept for 24 hours until the instance is authorized. * Videos longer than one minute will be cut, and the recommended image aspect ratio is 9:16 (vertical). * For recipients to see the status, both parties must save each other's numbers in their contact lists. * * @param params - Media status parameters including file URL, name, caption, and recipient list * @returns Promise resolving to status send response with message ID * * @example * ```typescript * await client.sendMediaStatus({ * urlFile: "https://my.site.com/img/picture.png", * fileName: "picture.png", * caption: "Check this out!", * participants: ["70000001234@c.us"] // Optional: limit visibility to specific contacts * }); * ``` */ sendMediaStatus(params: SendMediaStatus): Promise; /** * Deletes a previously sent status (Beta feature). * * @param params - Parameters containing the ID of the status to delete * @returns Promise resolving to void on successful deletion * * @example * ```typescript * await client.deleteStatus({ * idMessage: "BAE5F4886F6F2D05" * }); * ``` */ deleteStatus(params: DeleteStatus): Promise; /** * Gets statistics for a previously sent status (Beta feature). * Returns an array of recipients with sent/delivered/read statuses. * Statistics on statuses are stored for 30 days from the date of their receipt. * Requires the "Receive webhooks on sent messages statuses" setting to be enabled. * * @param params - Parameters containing the ID of the status to get statistics for * @returns Promise resolving to an array of status statistics * * @example * ```typescript * const statistics = await client.getStatusStatistic({ * idMessage: "BAE5F4886F6F2D05" * }); * * statistics.forEach(stat => { * console.log(`${stat.participant}: ${stat.status} at ${new Date(stat.timestamp * 1000)}`); * }); * ``` */ getStatusStatistic(params: GetStatusStatistic): Promise; /** * Gets incoming status messages from contacts (Beta feature). * Returns statuses that were received by the current WhatsApp account. * By default, returns incoming statuses for the last 24 hours (1440 minutes). * Statuses can only be received from numbers in the contact list and are stored for 30 days. * * @param params - Optional parameters to specify time period in minutes * @returns Promise resolving to an array of incoming status messages * * @example * ```typescript * // Get statuses from last 24 hours (default) * const statuses = await client.getIncomingStatuses(); * * // Get statuses from last hour * const recentStatuses = await client.getIncomingStatuses({ minutes: 60 }); * * statuses.forEach(status => { * if (status.typeMessage === "extendedTextMessage") { * console.log(`Text status from ${status.senderName}: ${status.textMessage}`); * } else { * console.log(`Media status from ${status.senderName}: ${status.downloadUrl}`); * } * }); * ``` */ getIncomingStatuses(params?: GetIncomingStatusesParams): Promise; /** * Gets outgoing status messages sent by the current account (Beta feature). * By default, returns outgoing statuses for the last 24 hours (1440 minutes). * Requires the "Receive webhooks on sent messages statuses" setting to be enabled. * Statuses are stored in journals for 30 days from the date of their sending. * * @param params - Optional parameters to specify time period in minutes * @returns Promise resolving to an array of outgoing status messages * * @example * ```typescript * // Get statuses from last 24 hours (default) * const statuses = await client.getOutgoingStatuses(); * * // Get statuses from last hour * const recentStatuses = await client.getOutgoingStatuses({ minutes: 60 }); * * statuses.forEach(status => { * if (status.typeMessage === "extendedTextMessage") { * console.log(`Text status: ${status.textMessage} - ${status.statusMessage}`); * } else { * console.log(`Media status: ${status.downloadUrl} - ${status.statusMessage}`); * } * }); * ``` */ getOutgoingStatuses(params?: GetOutgoingStatusesParams): Promise; /** * Adds contact. * * @param params - Contact data containing chat ID and name * @returns Promise resolving to add contact response * * @example * ```typescript * await client.addContact({ * chatId: "1234567890@c.us", * firstName: "John", * lastName: "Doe" * }); * ``` */ addContact(params: AddContact): Promise; /** * Edits contact. * * @param params - Contact data containing chat ID and name * @returns Promise resolving to edit contact response * * @example * ```typescript * await client.editContact({ * chatId: "1234567890@c.us", * firstName: "John", * lastName: "Doe" * }); * ``` */ editContact(params: EditContact): Promise; /** * Deletes contact. * * @param params - Contact data containing chat ID * @returns Promise resolving to delete contact response * * @example * ```typescript * await client.deleteContact({ * chatId: "1234567890@c.us" * }); * ``` */ deleteContact(params: DeleteContact): Promise; }