@open-wa/wa-automate-types-only
Version:
Types generated from the @open-wa/wa-automate package
1,049 lines • 102 kB
TypeScript
/// <reference types="node" />
import { Page } from 'puppeteer';
import { Chat, LiveLocationChangedEvent, ChatState, ChatMuteDuration, GroupChatCreationResponse, EphemeralDuration } from './model/chat';
import { BusinessProfile, Contact, NumberCheck } from './model/contact';
import { Message, MessageInfo, MessagePinDuration, PollData } from './model/message';
import { AxiosRequestConfig } from 'axios';
import { NewCommunityGroup, ParticipantChangedEventModel, GenericGroupChangeEvent, GroupMetadata } from './model/group-metadata';
import { ConfigObject, STATE, LicenseType, Webhook, EventPayload } from './model';
import PQueue, { DefaultAddOptions, Options } from 'p-queue';
import { HealthCheck, SessionInfo } from './model/sessionInfo';
import { ChatId, GroupChatId, Content, Base64, MessageId, ContactId, DataURL, AdvancedFile, GroupId } from './model/aliases';
import { CustomProduct, Order, Product } from './model/product';
import { Label } from './model/label';
import { Mp4StickerConversionProcessOptions, StickerMetadata } from './model/media';
import { SimpleListener } from './model/events';
import { AwaitMessagesOptions, Collection, CollectorFilter, CollectorOptions } from '../structures/Collector';
import { MessageCollector } from '../structures/MessageCollector';
import { Listener } from 'eventemitter2';
import PriorityQueue from 'p-queue/dist/priority-queue';
import { NextFunction, Request, Response } from 'express';
import { Call } from './model/call';
import { AdvancedButton, Button, LocationButtonBody, Section } from './model/button';
import { JsonObject } from 'type-fest';
import { ReactionEvent } from './model/reactions';
export declare enum namespace {
Chat = "Chat",
Msg = "Msg",
Contact = "Contact",
GroupMetadata = "GroupMetadata"
}
export declare class Client {
private _loadedModules;
private _registeredWebhooks;
private _registeredEvListeners;
private _webhookQueue;
private _createConfig;
private _sessionInfo;
private _listeners;
private _page;
private _currentlyBeingKilled;
private _refreshing;
private _loaded;
private _hostAccountNumber;
private _prio;
private _pageListeners;
private _registeredPageListeners;
private _onLogoutCallbacks;
private _queues;
private _autoEmojiSet;
private _autoEmojiQ;
private _onLogoutSet;
private _preprocIdempotencyCheck;
/**
* This is used to track if a listener is already used via webhook. Before, webhooks used to be set once per listener. Now a listener can be set via multiple webhooks, or revoked from a specific webhook.
* For this reason, listeners assigned to a webhook are only set once and map through all possible webhooks to and fire only if the specific listener is assigned.
*
* Note: This would be much simpler if eventMode was the default (and only) listener strategy.
*/
private _registeredWebhookListeners;
/**
* @ignore
* @param page [Page] [Puppeteer Page]{@link https://pptr.dev/#?product=Puppeteer&version=v2.1.1&show=api-class-page} running WA Web
*/
constructor(page: Page, createConfig: ConfigObject, sessionInfo: SessionInfo);
/**
* @private
*
* DO NOT USE THIS.
*
* Run all tasks to set up client AFTER init is fully completed
*/
loaded(): Promise<void>;
private registerAllSimpleListenersOnEv;
getSessionId(): string;
getPage(): Page;
private _setOnClose;
private _reInjectWapi;
private _reRegisterListeners;
/**
* A convinience method to download the [[DataURL]] of a file
* @param url The url
* @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
* @returns `Promise<DataURL>`
*/
download(url: string, optionsOverride?: any): Promise<DataURL>;
/**
* Grab the logger for this session/process
*/
logger(): any;
/**
* Refreshes the page and reinjects all necessary files. This may be useful for when trying to save memory
* This will attempt to re register all listeners EXCEPT onLiveLocation and onParticipantChanged
*/
refresh(): Promise<boolean>;
/**
* Get the session info
*
* @returns SessionInfo
*/
getSessionInfo(): SessionInfo;
/**
* Easily resize page on the fly. Useful if you're showing screenshots in a web-app.
*/
resizePage(width?: number, height?: number): Promise<boolean>;
/**
* Get the config which was used to set up the client. Sensitive details (like devTools username and password, and browserWSEndpoint) are scrubbed
*
* @returns SessionInfo
*/
getConfig(): ConfigObject;
private pup;
private responseWrap;
/**
* //////////////////////// LISTENERS
*/
removeListener(listener: SimpleListener): boolean;
removeAllListeners(): boolean;
/**
*
*/
private registerListener;
private registerPageEventListener;
/**
* It calls the JavaScript garbage collector
* @returns Nothing.
*/
gc(): Promise<void>;
/**
* Listens to a log out event
*
* @event
* @param fn callback
* @param priority A priority of -1 will mean the callback will be triggered after all the non -1 callbacks
* @fires `true`
*/
onLogout(fn: (loggedOut?: boolean) => any, priority?: number): Promise<boolean>;
/**
* Wait for the webhook queue to become idle. This is useful for ensuring webhooks are cleared before ending a process.
*/
waitWhQIdle(): Promise<true | void>;
/**
* Wait for all queues to be empty
*/
waitAllQEmpty(): Promise<true | void[]>;
/**
* If you have set `onAnyMessage` or `onMessage` with the second parameter (PQueue options) then you may want to inspect their respective PQueue's.
*/
getListenerQueues(): {
[key in SimpleListener]?: PQueue;
};
private preprocessMessage;
/**
* Listens to incoming messages
*
* @event
* @param fn callback
* @param queueOptions PQueue options. Set to `{}` for default PQueue.
* @fires [[Message]]
*/
onMessage(fn: (message: Message) => void, queueOptions?: Options<PriorityQueue, DefaultAddOptions>): Promise<Listener | boolean>;
/**
* Listens to all new messages
*
* @event
* @param fn callback
* @param queueOptions PQueue options. Set to `{}` for default PQueue.
* @fires [[Message]]
*/
onAnyMessage(fn: (message: Message) => void, queueOptions?: Options<PriorityQueue, DefaultAddOptions>): Promise<Listener | boolean>;
/**
*
* Listens to when a message is deleted by a recipient or the host account
* @event
* @param fn callback
* @fires [[Message]]
*/
onMessageDeleted(fn: (message: Message) => void): Promise<Listener | boolean>;
/**
* Listens to when a chat is deleted by the host account
* @event
* @param fn callback
* @fires [[Chat]]
*/
onChatDeleted(fn: (chat: Chat) => void): Promise<Listener | boolean>;
/**
* Listens to button message responses
* @event
* @param fn callback
* @fires [[Message]]
*/
onButton(fn: (message: Message) => void): Promise<Listener | boolean>;
/**
* Listens to poll vote events
* @event
* @param fn callback
* @fires [[PollData]]
*/
onPollVote(fn: (pollDate: PollData) => void): Promise<Listener | boolean>;
/**
* Listens to broadcast messages
* @event
* @param fn callback
* @fires [[Message]]
*/
onBroadcast(fn: (message: Message) => void): Promise<Listener | boolean>;
/**
* @deprecated
*
* Listens to battery changes
*
* :::caution
*
* This will most likely not work with multi-device mode (the only remaining mode) since the session is no longer connected to the phone but directly to WA servers.
*
* :::
*
* @event
* @param fn callback
* @fires number
*/
onBattery(fn: (battery: number) => void): Promise<Listener | boolean>;
/**
* Listens to when host device is plugged/unplugged
* @event
*
* @param fn callback
* @fires boolean true if plugged, false if unplugged
*/
onPlugged(fn: (plugged: boolean) => void): Promise<Listener | boolean>;
/**
* {@license:restricted@}
*
* Listens to when a contact posts a new story.
* @event
*
* @param fn callback
* @fires e.g
*
* ```javascript
* {
* from: '123456789@c.us'
* id: 'false_132234234234234@status.broadcast'
* }
* ```
*/
onStory(fn: (story: Message) => void): Promise<Listener | boolean>;
/**
* Listens to changes in state
*
* @event
* @fires STATE observable sream of states
*/
onStateChanged(fn: (state: STATE) => void): Promise<Listener | boolean>;
/**
* Listens to new incoming calls
* @event
* @returns Observable stream of call request objects
*/
onIncomingCall(fn: (call: Call) => void): Promise<Listener | boolean>;
/**
* Listens to changes on call state
* @event
* @returns Observable stream of call objects
*/
onCallState(fn: (call: Call) => void): Promise<Listener | boolean>;
/**
* Listens to label change events
*
* @event
* @param fn callback
* @fires [[Label]]
*/
onLabel(fn: (label: Label) => void): Promise<Listener | boolean>;
/**
*{@license:insiders@}
*
* Listens to new orders. Only works on business accounts
*/
onOrder(fn: (order: Order) => void): Promise<Listener | boolean>;
/**
*{@license:insiders@}
*
* Listens to new orders. Only works on business accounts
*/
onNewProduct(fn: (product: Product) => void): Promise<Listener | boolean>;
/**
* {@license:insiders@}
*
* Listens to reaction add and change events
*
* @event
* @param fn callback
* @fires [[ReactionEvent]]
*/
onReaction(fn: (reactionEvent: ReactionEvent) => void): Promise<Listener | boolean>;
/**
* {@license:insiders@}
*
* Listens to chat state, including when a specific user is recording and typing within a group chat.
*
* @event
*
* Here is an example of the fired object:
*
* @fires
* ```javascript
* {
* "chat": "00000000000-1111111111@g.us", //the chat in which this state is occuring
* "user": "22222222222@c.us", //the user that is causing this state
* "state": "composing, //can also be 'available', 'unavailable', 'recording' or 'composing'
* }
* ```
*/
onChatState(fn: (chatState: ChatState) => void): Promise<Listener | boolean>;
/**
* Listens to messages acknowledgement Changes
*
* @param fn callback function that handles a [[Message]] as the first and only parameter.
* @event
* @returns `true` if the callback was registered
*/
onAck(fn: (message: Message) => void): Promise<Listener | boolean>;
/**
* Listens to add and remove events on Groups on a global level. It is memory efficient and doesn't require a specific group id to listen to.
*
* @event
* @param fn callback function that handles a [[ParticipantChangedEventModel]] as the first and only parameter.
* @returns `true` if the callback was registered
*/
onGlobalParticipantsChanged(fn: (participantChangedEvent: ParticipantChangedEventModel) => void): Promise<Listener | boolean>;
/**
* Listents to group approval requests. Emits a message object. Use it with `message.isGroupApprovalRequest()` to check if it is a group approval request.
*
* @event
* @param fn callback function that handles a [[Message]] as the first and only parameter.
* @returns `true` if the callback was registered
*/
onGroupApprovalRequest(fn: (groupApprovalRequestMessage: Message) => void): Promise<Listener | boolean>;
/**
* Listens to all group (gp2) events. This can be useful if you want to catch when a group title, subject or picture is changed.
*
* @event
* @param fn callback function that handles a [[ParticipantChangedEventModel]] as the first and only parameter.
* @returns `true` if the callback was registered
*/
onGroupChange(fn: (genericGroupChangeEvent: GenericGroupChangeEvent) => void): Promise<Listener | boolean>;
/**
* Fires callback with Chat object every time the host phone is added to a group.
*
* @event
* @param fn callback function that handles a [[Chat]] (group chat) as the first and only parameter.
* @returns `true` if the callback was registered
*/
onAddedToGroup(fn: (chat: Chat) => any): Promise<Listener | boolean>;
/**
* {@license:insiders@}
*
* Fires callback with Chat object every time the host phone is removed to a group.
*
* @event
* @param fn callback function that handles a [[Chat]] (group chat) as the first and only parameter.
* @returns `true` if the callback was registered
*/
onRemovedFromGroup(fn: (chat: Chat) => any): Promise<Listener | boolean>;
/**
* {@license:insiders@}
*
* Fires callback with the relevant chat id every time the user clicks on a chat. This will only work in headful mode.
*
* @event
* @param fn callback function that handles a [[ChatId]] as the first and only parameter.
* @returns `true` if the callback was registered
*/
onChatOpened(fn: (chat: Chat) => any): Promise<Listener | boolean>;
/**
* {@license:insiders@}
*
* Fires callback with contact id when a new contact is added on the host phone.
*
* @event
* @param fn callback function that handles a [[Chat]] as the first and only parameter.
* @returns `true` if the callback was registered
*/
onContactAdded(fn: (chat: Chat) => any): Promise<Listener | boolean>;
/**
* @event
* Listens to add and remove events on Groups. This can no longer determine who commited the action and only reports the following events add, remove, promote, demote
* @param groupId group id: xxxxx-yyyy@c.us
* @param fn callback
* @returns Observable stream of participantChangedEvent
*/
onParticipantsChanged(groupId: GroupChatId, fn: (participantChangedEvent: ParticipantChangedEventModel) => void, legacy?: boolean): Promise<Listener | boolean>;
/**
* @event Listens to live locations from a chat that already has valid live locations
* @param chatId the chat from which you want to subscribes to live location updates
* @param fn callback that takes in a LiveLocationChangedEvent
* @returns boolean, if returns false then there were no valid live locations in the chat of chatId
* @emits `<LiveLocationChangedEvent>` LiveLocationChangedEvent
*/
onLiveLocation(chatId: ChatId, fn: (liveLocationChangedEvent: LiveLocationChangedEvent) => void): Promise<boolean>;
/**
* Use this simple command to test firing callback events.
*
* @param callbackToTest
* @param testData
* @returns `false` if the callback was not registered/does not exist
*/
testCallback(callbackToTest: SimpleListener, testData: any): Promise<boolean>;
/**
* Set presence to available or unavailable.
* @param available if true it will set your presence to 'online', false will set to unavailable (i.e no 'online' on recipients' phone);
*/
setPresence(available: boolean): Promise<boolean | void>;
/**
* set your about me
* @param newStatus String new profile status
*/
setMyStatus(newStatus: string): Promise<boolean | void>;
/**
* {@license:insiders@}
*
* Adds label from chat, message or contact. Only for business accounts.
* @param label: The desired text of the new label. id will be something simple like anhy nnumber from 1-10, name is the label of the label if that makes sense.
* @returns `false` if something went wrong, or the id (usually a number as a string) of the new label (for example `"58"`)
*/
createLabel(label: string): Promise<string | boolean>;
/**
* Adds label from chat, message or contact. Only for business accounts.
* @param label: either the id or the name of the label. id will be something simple like anhy nnumber from 1-10, name is the label of the label if that makes sense.
* @param id The Chat, message or contact id to which you want to add a label
*/
addLabel(label: string, chatId: ChatId): Promise<boolean>;
/**
* Returns all labels and the corresponding tagged items.
*/
getAllLabels(): Promise<Label[]>;
/**
* Removes label from chat, message or contact. Only for business accounts.
* @param label: either the id or the name of the label. id will be something simple like anhy nnumber from 1-10, name is the label of the label if that makes sense.
* @param id The Chat, message or contact id to which you want to add a label
*/
removeLabel(label: string, chatId: ChatId): Promise<boolean>;
/**
* Get an array of chats that match the label parameter. For example, if you want to get an array of chat objects that have the label "New customer".
*
* This method is case insenstive and only works on business host accounts.
*
* @label The label name
*/
getChatsByLabel(label: string): Promise<Chat[]>;
/**
* Send VCARD
*
* @param {string} chatId '000000000000@c.us'
* @param {string} vcard vcard as a string, you can send multiple contacts vcard also.
* @param {string} contactName The display name for the contact. Ignored on multiple vcards
* @param {string} contactNumber If supplied, this will be injected into the vcard (VERSION 3 ONLY FROM VCARDJS) with the WA id to make it show up with the correct buttons on WA. The format of this param should be including country code, without any other formating. e.g:
* `4477777777777`
* Ignored on multiple vcards
*/
sendVCard(chatId: ChatId, vcard: string, contactName?: string, contactNumber?: string): Promise<boolean>;
/**
* Set your profile name
*
* Please note, this does not work on business accounts!
*
* @param newName String new name to set for your profile
*/
setMyName(newName: string): Promise<boolean>;
/**
* Sets the chat state
* @param {ChatState|0|1|2} chatState The state you want to set for the chat. Can be TYPING (0), RECRDING (1) or PAUSED (2).
* @param {String} chatId
*/
setChatState(chatState: ChatState, chatId: ChatId): Promise<boolean>;
/**
* Returns the connection state
*/
getConnectionState(): Promise<STATE>;
/**
* Retreive an array of messages that are not yet sent to the recipient via the host account device (i.e no ticks)
*/
getUnsentMessages(): Promise<Message[]>;
/**
* Forces the session to update the connection state.
* @param killBeforeAttemptingToReconnect Setting this to true will force the session to drop the current socket connection before attempting to reconnect. This is useful if you want to force the session to reconnect immediately.
* @returns updated connection state
*/
forceUpdateConnectionState(killBeforeReconnect?: boolean): Promise<STATE>;
/**
* Returns a list of contact with whom the host number has an existing chat who are also not contacts.
*/
getChatWithNonContacts(): Promise<Contact[]>;
/**
* Shuts down the page and browser
* @returns true
*/
kill(reason?: string): Promise<boolean>;
/**
* This is a convinient method to click the `Use Here` button in the WA web session.
*
* Use this when [[STATE]] is `CONFLICT`. You can read more about managing state here:
*
* [[Detecting Logouts]]
*/
forceRefocus(): Promise<boolean>;
/**
* Check if the "Phone not Cconnected" message is showing in the browser. If it is showing, then this will return `true`.
*
* @returns `boolean`
*/
isPhoneDisconnected(): Promise<boolean>;
/**
* Runs a health check to help you determine if/when is an appropiate time to restart/refresh the session.
*/
healthCheck(): Promise<HealthCheck>;
/**
* Get the stats of the current process and the corresponding browser process.
*/
getProcessStats(): Promise<any>;
/**
* A list of participants in the chat who have their live location on. If the chat does not exist, or the chat does not have any contacts actively sharing their live locations, it will return false. If it's a chat with a single contact, there will be only 1 value in the array if the contact has their livelocation on.
* Please note. This should only be called once every 30 or so seconds. This forces the phone to grab the latest live location data for the number. This can be used in conjunction with onLiveLocation (this will trigger onLiveLocation).
* @param chatId string Id of the chat you want to force the phone to get the livelocation data for.
* @returns `Promise<LiveLocationChangedEvent []>` | boolean
*/
forceUpdateLiveLocation(chatId: ChatId): Promise<LiveLocationChangedEvent[] | boolean>;
/**
*
* @deprecated
*
* :::danger
*
* Buttons are broken for the foreseeable future. Please DO NOT get a license solely for access to buttons. They are no longer reliable due to recent changes at WA.
*
* :::
*
* Test the button commands on MD accounts with an insiders key. This is a temporary feature to help fix issue #2658
*/
testButtons(chatId: ChatId): Promise<any>;
private link;
/**
* Generate a license link
*/
getLicenseLink(params?: string): Promise<string>;
/**
*
* {@license:restricted@}
*
* Sends a text message to given chat
*
* A license is **NOT** required to send messages with existing chats/contacts. A license is only required for starting conversations with new numbers.
*
* @param to chat id: `xxxxx@c.us`
* @param content text message
*/
sendText(to: ChatId, content: Content): Promise<boolean | MessageId>;
/**
* Sends a text message to given chat that includes mentions.
* In order to use this method correctly you will need to send the text like this:
* "@4474747474747 how are you?"
* Basically, add a @ symbol before the number of the contact you want to mention.
*
* @param to chat id: `xxxxx@c.us`
* @param content text message
* @param hideTags Removes all tags within the message
* @param mentions You can optionally add an array of contact IDs to tag only specific people
*/
sendTextWithMentions(to: ChatId, content: Content, hideTags?: boolean, mentions?: ContactId[]): Promise<boolean | MessageId>;
/**
* NOTE: This is experimental, most accounts do not have access to this feature in their apps.
*
* Edit an existing message
*
* @param messageId The message ID to edit
* @param text The new text content
* @returns
*/
editMessage(messageId: MessageId, text: Content): Promise<boolean | MessageId>;
/**
* [UNTESTED - REQUIRES FEEDBACK]
* Sends a payment request message to given chat
*
* @param to chat id: `xxxxx@c.us`
* @param amount number the amount to request in 1000 format (e.g £10 => 10000)
* @param currency string The 3 letter currency code
* @param message string optional message to send with the payment request
*/
sendPaymentRequest(to: ChatId, amount: number, currency: string, message?: string): Promise<boolean | MessageId>;
/**
*
* @deprecated
*
* :::danger
*
* WA BIZ accounts CANNOT send buttons. This is a WA limitation. DO NOT get a license solely for access to buttons on wa business accounts.
* THIS IS NOT WORKING FOR GROUPS YET.
*
* BUTTONS ARE DEPRECATED FOR NOW. DO NOT GET A LICENSE TO USE BUTTONS.
*
* :::
*
* Send generic quick reply buttons. This is an insiders feature for MD accounts.
*
* @param {ChatId} to chat id
* @param {string | LocationButtonBody} body The body of the buttons message
* @param {Button[]} buttons Array of buttons - limit is 3!
* @param {string} title The title/header of the buttons message
* @param {string} footer The footer of the buttons message
*/
sendButtons(to: ChatId, body: string | LocationButtonBody, buttons: Button[], title?: string, footer?: string): Promise<boolean | MessageId>;
/**
* @deprecated
*
* :::danger
*
* Template messages (URL & CALL buttons) are broken for the foreseeable future. Please DO NOT get a license solely for access to URL or CALL buttons. They are no longer reliable due to recent changes at WA.
* WA BIZ accounts CANNOT send buttons. This is a WA limitation. DO NOT get a license solely for access to buttons on wa business accounts.
*
* THIS IS NOT WORKING FOR GROUPS YET.
*
* ADVANCED ARE DEPRECATED FOR NOW. DO NOT GET A LICENSE TO USE BUTTONS.
*
* :::
*
*
* Send advanced buttons with media body. This is an insiders feature for MD accounts.
*
* Body can be location, image, video or document. Buttons can be quick reply, url or call buttons.
*
* @param {ChatId} to chat id
* @param {string | LocationButtonBody} body The body of the buttons message
* @param {AdvancedButton[]} buttons Array of buttons - limit is 3!
* @param {string} title The title/header of the buttons message
* @param {string} footer The footer of the buttons message
* @param {string} filename Required if body is a file!!
*/
sendAdvancedButtons(to: ChatId, body: string | LocationButtonBody, buttons: AdvancedButton[], text: string, footer: string, filename: string): Promise<boolean | MessageId>;
/**
* Send a banner image
*
* Note this is a bit of hack on top of a location message. During testing it is shown to not work on iPhones.
*
* @param {ChatId} to
* @param {Base64} base64 base64 encoded jpeg
*/
sendBanner(to: ChatId, base64: Base64): Promise<boolean | MessageId>;
/**
*
* @deprecated
*
* :::danger
*
* It is not currently possible to send a listmessage to a group chat. This is a WA limitation.
* Please DO NOT get a license solely for access to list messages in group chats.
*
* LIST MESSAGES ARE DEPRECATED TILL FURTHER NOTICE
*
* :::
*
* Send a list message. This will not work when being sent from business accounts!
*
* @param {ChatId} to
* @param {Section[]} sections The Sections of rows for the list message
* @param {string} title The title of the list message
* @param {string} description The description of the list message
* @param {string} actionText The action text of the list message
*/
sendListMessage(to: ChatId, sections: Section[], title: string, description: string, actionText: string): Promise<boolean | MessageId>;
/**
* Sends a reply to given chat that includes mentions, replying to the provided replyMessageId.
* In order to use this method correctly you will need to send the text like this:
* "@4474747474747 how are you?"
* Basically, add a @ symbol before the number of the contact you want to mention.
* @param to chat id: `xxxxx@c.us`
* @param content text message
* @param replyMessageId id of message to reply to
* @param hideTags Removes all tags within the message
* @param mentions You can optionally add an array of contact IDs to tag only specific people
*/
sendReplyWithMentions(to: ChatId, content: Content, replyMessageId: MessageId, hideTags?: boolean, mentions?: ContactId[]): Promise<boolean | MessageId>;
/**
* {@license:insiders@}
*
* Tags everyone in the group with a message
*
* @param groupId group chat id: `xxxxx@g.us`
* @param content text message to add under all of the tags
* @param hideTags Removes all tags within the message
* @param formatting The formatting of the tags. Use @mention to indicate the actual tag. @default `@mention `
* @param messageBeforeTags set to `true` to show the message before all of the tags
* @returns `Promise<MessageId>`
*/
tagEveryone(groupId: GroupChatId, content: Content, hideTags?: boolean, formatting?: string, messageBeforeTags?: boolean): Promise<boolean | MessageId>;
/**
* Sends a link to a chat that includes a link preview.
* @param thumb The base 64 data of the image you want to use as the thunbnail. This should be no more than 200x200px. Note: Dont need data url on this param
* @param url The link you want to send
* @param title The title of the link
* @param description The long description of the link preview
* @param text The text you want to inslude in the message section. THIS HAS TO INCLUDE THE URL otherwise the url will be prepended to the text automatically.
* @param chatId The chat you want to send this message to.
* @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
* @param customSize [INSIDERS] Anchor the size of the thumbnail
*/
sendMessageWithThumb(thumb: string, url: string, title: string, description: string, text: Content, chatId: ChatId, quotedMsgId?: MessageId, customSize?: {
height: number;
width: number;
}): Promise<MessageId | boolean>;
/**
* Note: `address` and `url` are parameters available to insiders only.
*
* Sends a location message to given chat
* @param to chat id: `xxxxx@c.us`
* @param lat latitude: '51.5074'
* @param lng longitude: '0.1278'
* @param loc location text: 'LONDON!'
* @param address address text: '1 Regents Park!'
* @param url address text link: 'https://example.com'
*/
sendLocation(to: ChatId, lat: string, lng: string, loc: string, address?: string, url?: string): Promise<boolean | MessageId>;
/**
* Get the generated user agent, this is so you can send it to the decryption module.
* @returns String useragent of wa-web session
*/
getGeneratedUserAgent(userA?: string): Promise<string>;
/**
* Decrypts a media message.
* @param message This can be the serialized [[MessageId]] or the whole [[Message]] object. It is advised to just use the serialized message ID.
* @returns `Promise<[[DataURL]]>`
*/
decryptMedia(message: Message | MessageId): Promise<DataURL>;
/**
* Sends a image to given chat, with caption or not, using base64
* @param to chat id `xxxxx@c.us`
* @param file DataURL data:image/xxx;base64,xxx or the RELATIVE (should start with `./` or `../`) path of the file you want to send. With the latest version, you can now set this to a normal URL (for example [GET] `https://file-examples-com.github.io/uploads/2017/10/file_example_JPG_2500kB.jpg`).
* @param filename string xxxxx
* @param caption string xxxxx
* @param waitForKey boolean default: false set this to true if you want to wait for the id of the message. By default this is set to false as it will take a few seconds to retrieve to the key of the message and this waiting may not be desirable for the majority of users.
* @param hideTags boolean default: false [INSIDERS] set this to try silent tag someone in the caption
* @returns `Promise <boolean | string>` This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
*/
sendImage(to: ChatId, file: AdvancedFile, filename: string, caption: Content, quotedMsgId?: MessageId, waitForId?: boolean, ptt?: boolean, withoutPreview?: boolean, hideTags?: boolean, viewOnce?: boolean, requestConfig?: any): Promise<MessageId | boolean>;
/**
* Automatically sends a youtube link with the auto generated link preview. You can also add a custom message.
* @param chatId
* @param url string A youtube link.
* @param text string Custom text as body of the message, this needs to include the link or it will be appended after the link.
* @param thumbnail string Base64 of the jpeg/png which will be used to override the automatically generated thumbnail.
* @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
* @param customSize [INSIDERS] Anchor the size of the thumbnail
*/
sendYoutubeLink(to: ChatId, url: string, text?: Content, thumbnail?: Base64, quotedMsgId?: MessageId, customSize?: {
height: number;
width: number;
}): Promise<boolean | MessageId>;
/**
* Automatically sends a link with the auto generated link preview. You can also add a custom message.
* @param chatId
* @param url string A link.
* @param text string Custom text as body of the message, this needs to include the link or it will be appended after the link.
* @param thumbnail Base64 of the jpeg/png which will be used to override the automatically generated thumbnail.
* @param quotedMsgId [INSIDERS] Send this link preview message in response to a given quoted message
* @param customSize [INSIDERS] Anchor the size of the thumbnail
*/
sendLinkWithAutoPreview(to: ChatId, url: string, text?: Content, thumbnail?: Base64, quotedMsgId?: MessageId, customSize?: {
height: number;
width: number;
}): Promise<boolean | MessageId>;
/**
*
* Sends a reply to a given message. Please note, you need to have at least sent one normal message to a contact in order for this to work properly.
*
* @param to string chatid
* @param content string reply text
* @param quotedMsgId string the msg id to reply to.
* @param sendSeen boolean If set to true, the chat will 'blue tick' all messages before sending the reply
* @returns `Promise<MessageId | false>` false if didn't work, otherwise returns message id.
*/
reply(to: ChatId, content: Content, quotedMsgId: MessageId, sendSeen?: boolean): Promise<boolean | MessageId>;
/**
* {@license:insiders@}
*
* Check if a recipient has read receipts on.
*
* This will only work if you have chats sent back and forth between you and the contact 1-1.
*
* @param contactId The Id of the contact with which you have an existing conversation with messages already.
* @returns `Promise<string | boolean>` true or false or a string with an explaintaion of why it wasn't able to determine the read receipts.
*
*/
checkReadReceipts(contactId: ContactId): Promise<string | boolean>;
/**
* Sends a file to given chat, with caption or not, using base64. This is exactly the same as sendImage
*
* Please note that any file that resolves to mime-type `octet-stream` will, by default, resolve to an MP4 file.
*
* If you want a specific filetype, then explcitly select the correct mime-type from https://www.iana.org/assignments/media-types/media-types.xhtml
*
*
* @param to chat id `xxxxx@c.us`
* @param file DataURL data:image/xxx;base64,xxx or the RELATIVE (should start with `./` or `../`) path of the file you want to send. With the latest version, you can now set this to a normal URL (for example [GET] `https://file-examples-com.github.io/uploads/2017/10/file_example_JPG_2500kB.jpg`).
* @param filename string xxxxx
* @param caption string xxxxx With an [INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program) you can also tag people in groups with `@[number]`. For example if you want to mention the user with the number `44771234567`, just add `@44771234567` in the caption.
* @param quotedMsgId string true_0000000000@c.us_JHB2HB23HJ4B234HJB to send as a reply to a message
* @param waitForId boolean default: false set this to true if you want to wait for the id of the message. By default this is set to false as it will take a few seconds to retrieve to the key of the message and this waiting may not be desirable for the majority of users.
* @param ptt boolean default: false set this to true if you want to send the file as a push to talk file.
* @param withoutPreview boolean default: false set this to true if you want to send the file without a preview (i.e as a file). This is useful for preventing auto downloads on recipient devices.
* @param hideTags boolean default: false [INSIDERS] set this to try silent tag someone in the caption
* @returns `Promise <boolean | MessageId>` This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
*/
sendFile(to: ChatId, file: AdvancedFile, filename: string, caption: Content, quotedMsgId?: MessageId, waitForId?: boolean, ptt?: boolean, withoutPreview?: boolean, hideTags?: boolean, viewOnce?: boolean, requestConfig?: any): Promise<MessageId | boolean>;
/**
* {@license:insiders@}
*
* Checks whether or not the group id provided is known to be unsafe by the contributors of the library.
* @param groupChatId The group chat you want to deteremine is unsafe
* @returns `Promise <boolean | string>` This will either return a boolean indiciating whether this group chat id is considered unsafe or an error message as a string
*/
isGroupIdUnsafe(groupChatId: GroupChatId): Promise<string | boolean>;
/**
* Attempts to send a file as a voice note. Useful if you want to send an mp3 file.
* @param to chat id `xxxxx@c.us`
* @param file base64 data:image/xxx;base64,xxx or the path of the file you want to send.
* @param quotedMsgId string true_0000000000@c.us_JHB2HB23HJ4B234HJB to send as a reply to a message
* @returns `Promise <boolean | string>` This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
*/
sendPtt(to: ChatId, file: AdvancedFile, quotedMsgId?: MessageId): Promise<MessageId>;
/**
* Send an audio file with the default audio player (not PTT/voice message)
* @param to chat id `xxxxx@c.us`
* @param base64 base64 data:image/xxx;base64,xxx or the path of the file you want to send.
* @param quotedMsgId string true_0000000000@c.us_JHB2HB23HJ4B234HJB to send as a reply to a message
*/
sendAudio(to: ChatId, file: AdvancedFile, quotedMsgId?: MessageId): Promise<MessageId>;
/**
* Send a poll to a group chat
* @param to chat id - a group chat is required
* @param name the name of the poll
* @param options an array of poll options
* @param quotedMsgId A message to quote when sending the poll
* @param allowMultiSelect Whether or not to allow multiple selections. default false
*/
sendPoll(to: GroupChatId, name: string, options: string[], quotedMsgId?: MessageId, allowMultiSelect?: boolean): Promise<MessageId>;
/**
* Sends a video to given chat as a gif, with caption or not, using base64
* @param to chat id `xxxxx@c.us`
* @param file DataURL data:image/xxx;base64,xxx or the RELATIVE (should start with `./` or `../`) path of the file you want to send. With the latest version, you can now set this to a normal URL (for example [GET] `https://file-examples-com.github.io/uploads/2017/10/file_example_JPG_2500kB.jpg`).
* @param filename string xxxxx
* @param caption string xxxxx
* @param quotedMsgId string true_0000000000@c.us_JHB2HB23HJ4B234HJB to send as a reply to a message
* @param requestConfig {} By default the request is a get request, however you can override that and many other options by sending this parameter. You can read more about this parameter here: https://github.com/axios/axios#request-config
*/
sendVideoAsGif(to: ChatId, file: AdvancedFile, filename: string, caption: Content, quotedMsgId?: MessageId, requestConfig?: AxiosRequestConfig): Promise<MessageId>;
/**
* Sends a video to given chat as a gif by using a giphy link, with caption or not, using base64
* @param to chat id `xxxxx@c.us`
* @param giphyMediaUrl string https://media.giphy.com/media/oYtVHSxngR3lC/giphy.gif => https://i.giphy.com/media/oYtVHSxngR3lC/200w.mp4
* @param caption string xxxxx
*/
sendGiphy(to: ChatId, giphyMediaUrl: string, caption: Content): Promise<MessageId>;
/**
* Sends a file by Url or custom options
* @param to chat id `xxxxx@c.us`
* @param url string https://i.giphy.com/media/oYtVHSxngR3lC/200w.mp4
* @param filename string 'video.mp4'
* @param caption string xxxxx
* @param quotedMsgId string true_0000000000@c.us_JHB2HB23HJ4B234HJB to send as a reply to a message
* @param requestConfig {} By default the request is a get request, however you can override that and many other options by sending this parameter. You can read more about this parameter here: https://github.com/axios/axios#request-config
* @param waitForId boolean default: false set this to true if you want to wait for the id of the message. By default this is set to false as it will take a few seconds to retrieve to the key of the message and this waiting may not be desirable for the majority of users.
* @param ptt boolean default: false set this to true if you want to send the file as a push to talk file.
* @param withoutPreview boolean default: false set this to true if you want to send the file without a preview (i.e as a file). This is useful for preventing auto downloads on recipient devices.
*/
sendFileFromUrl(to: ChatId, url: string, filename: string, caption: Content, quotedMsgId?: MessageId, requestConfig?: AxiosRequestConfig, waitForId?: boolean, ptt?: boolean, withoutPreview?: boolean, hideTags?: boolean, viewOnce?: boolean): Promise<MessageId | boolean>;
/**
* Returns an object with all of your host device details
*/
getMe(): Promise<any>;
/**
* Returns an object with properties of internal features and boolean values that represent if the respective feature is enabled or not.
*/
getFeatures(): Promise<any>;
/**
* Returns a PNG DataURL screenshot of the session
* @param chatId Chat ID to open before taking a snapshot
* @param width Width of the viewport for the snapshot. Height also required if you want to resize.
* @param height Height of the viewport for the snapshot. Width also required if you want to resize.
* @returns `Promise<DataURL>`
*/
getSnapshot(chatId?: ChatId, width?: number, height?: number): Promise<DataURL>;
/**
* Returns some metrics of the session/page.
* @returns `Promise<any>`
*/
metrics(): Promise<any>;
/**
* Returns an array of group ids where the host account is admin
*/
iAmAdmin(): Promise<GroupChatId[]>;
/**
* Returns an array of group ids where the host account has been kicked
*/
getKickedGroups(): Promise<GroupChatId[]>;
/**
* Syncs contacts with phone. This promise does not resolve so it will instantly return true.
*/
syncContacts(): Promise<boolean>;
/**
* Easily get the amount of messages loaded up in the session. This will allow you to determine when to clear chats/cache.
*/
getAmountOfLoadedMessages(): Promise<number>;
/**
* Find any product listings of the given number. Use this to query a catalog
*
* @param id id of business profile (i.e the number with @c.us)
* @returns None
*/
getBusinessProfilesProducts(id: ContactId): Promise<any>;
/**
* Get the business info of a given contact id
*
* @param id id of business profile (i.e the number with @c.us)
* @returns None
*/
getBusinessProfile(id: ContactId): Promise<BusinessProfile>;
/**
* Sends product with image to chat
* @param imgBase64 Base64 image data
* @param chatid string the id of the chat that you want to send this product to
* @param caption string the caption you want to add to this message
* @param bizNumber string the @c.us number of the business account from which you want to grab the product
* @param productId string the id of the product within the main catalog of the aforementioned business
* @returns
*/
sendImageWithProduct(to: ChatId, image: Base64, caption: Content, bizNumber: ContactId, productId: string): Promise<boolean | MessageId>;
/**
* @deprecated
* Feature Currently only available with Premium License accounts.
*
* Send a custom product to a chat. Please see [[CustomProduct]] for details.
*
* Caveats:
* - URL will not work (unable to click), you will have to send another message with the URL.
* - Recipient will see a thin banner under picture that says "Something went wrong"
* - This will only work if you have at least 1 product already in your catalog
* - Only works on Business accounts
*/
sendCustomProduct(to: ChatId, image: DataURL, productData: CustomProduct): Promise<MessageId | boolean>;
/**
* Sends contact card to given chat id. You can use this to send multiple contacts but they will show up as multiple single-contact messages.
* @param {string} to 'xxxx@c.us'
* @param {string|array} contact 'xxxx@c.us' | ['xxxx@c.us', 'yyyy@c.us', ...]
*/
sendContact(to: ChatId, contactId: ContactId | ContactId[]): Promise<MessageId | boolean>;
/**
*
* {@license:insiders@}
*
* Sends multiple contacts as a single message
*
* @param to 'xxxx@c.us'
* @param contact ['xxxx@c.us', 'yyyy@c.us', ...]
*/
sendMultipleContacts(to: ChatId, contactIds: ContactId[]): Promise<MessageId | boolean>;
/**
* Simulate '...typing' in chat
* @param {string} to 'xxxx@c.us'
* @param {boolean} on turn on similated typing, false to turn it off you need to manually turn this off.
*/
simulateTyping(to: ChatId, on: boolean): Promise<boolean>;
/**
* Simulate '...recording' in chat
* @param {string} to 'xxxx@c.us'
* @param {boolean} on turn on similated recording, false to turn it off you need to manually turn this off.
*/
simulateRecording(to: ChatId, on: boolean): Promise<boolean>;
/**
* @param id The id of the conversation
* @param archive boolean true => archive, false => unarchive
* @return boolean true: worked, false: didnt work (probably already in desired state)
*/
archiveChat(id: ChatId, archive: boolean): Promise<boolean>;
/**
* Pin/Unpin chats
*
* @param id The id of the conversation
* @param pin boolean true => pin, false => unpin
* @return boolean true: worked
*/
pinChat(id: ChatId, pin: boolean): Promise<boolean>;
/**
* Pin/Unpin message
*
* @param id The id of the message
* @param pin boolean true => pin, false => unpin
* @param pinDuration The length of time to pin the message. Default `ThirtyDays`
* @return boolean true: worked
*/
pinMessage(id: MessageId, pin: boolean, pinDuration?: MessagePinDuration): Promise<boolean>;
/**
* Keep a message inside an ephemeral chat
*
* @param id The id of the message
* @return boolean true: worked
*/
keepMessage(id: MessageId, keep: boolean): Promise<boolean>;
/**
*
* {@license:insiders@}
*
* Mutes a conversation for a given duration. If already muted, this will update the muted duration. Mute durations are relative from when the method is called.
* @param chatId The id of the conversation you want to mute
* @param muteDuration ChatMuteDuration enum of the time you want this chat to be muted for.
* @return boolean true: worked or error code or message
*/
muteChat(chatId: ChatId, muteDuration: ChatMuteDuration): Promise<boolean | string | number>;
/**
* Checks if a chat is muted
* @param chatId The id of the chat you want to check
* @returns boolean. `false` if the chat does not exist.
*/
isChatMuted(chatId: ChatId): Promise<boolean>;
/**
*
* {@license:insiders@}
*
* Unmutes a conversation.
* @param id The id of the conversation you want to mute
* @return boolean true: worked or error code or message
*/
unmuteChat(chatId: ChatId): Promise<boolean | string | number>;
/**
* Forward an array of messages to a specific chat using the message ids or Objects
*
* @param to '000000000000@c.us'
* @param messages this can be any mixture of message ids or message objects
* @param skipMyMessages This indicates whether or not to skip your own messages from the array
*/
forwardMessages(to: ChatId, messages: MessageId | MessageId[], skipMyMessages: boolean): Promise<boolean | MessageId[]>;
/**
* Ghost forwarding is like a normal forward but as if it were sent from the host phone [i.e it doesn't show up as forwarded.]
* Any potential abuse of this method will see it become paywalled.
* @param to: Chat id to forward the message to
* @param messageId: message id of the message to forward. Please note that if it is not loaded, this will return false - even if it exists.
* @returns `Promise<MessageId | boolean>`
*/
ghostForward(to: ChatId, messageId: MessageId): Promise<MessageId | boolean>;
/**
* Retrieves all contac