The WhatsApp handler in Bot Studio is responsible for managing WhatsApp bots. This handler leverages the Baileys library and uses an unofficial WhatsApp WebSocket.
Verifications
The origin server sends verification requests to the WhatsApp handler to validate the provided WhatsApp keys. The handler creates a WhatsApp client and listens for events. If a QR code is generated or the client encounters any issues, the provided key is considered invalid.
Activating Bots
When creating a WhatsApp bot, a new client is created. This client connects to an unofficial WhatsApp WebSocket used by the WhatsApp application or WhatsApp Web. Since the client runs on your account, the bot operates within your account, and WhatsApp treats it as if you were using the service.
The client stores your authentication information in an encoded format on the server. The client does not sync your account history, such as messages, so previous messages and histories are not fetched.
The client simulates the browser you used to scan the QR code. For example, if you used the Chrome browser, the client will also simulate Chrome. It doesn't actually create a browser to connect to the WhatsApp WebSocket but informs the WebSocket of the browser being used.
The client updates your authentication information on the server and then listens for all events used by your WhatsApp bot, such as the Message Upsert Event
.
Receiving Events
When an event is received, the event executor is identified based on the event type. All variables created from the event are those received from WhatsApp's WebSockets. You can find a list of all variables from each event here.
Executing Worker Nodes
Node names in Bot Studio are not opinionated. Each name references a specific feature. In WhatsApp bots, node names are based on the features of the Baileys library. For example, the Send Message
node uses the Send Message feature in Baileys, and all configurations for this feature are based on the node's data.
Cleaning Sessions
When you log out of the bot on WhatsApp, your session will be removed. This session removal occurs every 24 hours or one minute after a server restart. The session removal process deletes all invalid sessions from Bot Studio.
To remove a session, you must log out from that session in your WhatsApp account, exactly where you scanned the code.
QR Code
When creating a new QR code, it must be scanned within 30 seconds of creation. A new key associated with the QR code is created immediately, but it remains invalid until you scan the QR code and validate the key. Scanning the QR code does not mean Bot Studio has access to your account or that a bot is running. To create a bot, complete these steps.
Advertisements
Advertisements are currently disabled for WhatsApp bots but will be added in the future.