Here are the authentication settings and the key functionalities for interacting with the WhatsApp API for WAABOT-SDK:
First, ensure that you’ve created an account on waabot.com. The detailed steps are on the Prerequisites Page. If you encounter any issues during the registration process or require further assistance, please reach out to our support team at support@waabot.com for prompt assistance.
To get started with the SDK, follow these steps to create your credentials:
To create a session for API access, follow these steps:
Endpoint: https://api.waabot.com/api/v1/sessions
{
"email": "your-account-email",
"password": "your-account-password"
}
Make a POST request to the provided endpoint with the JSON payload, replacing “your-account-email” and “your-account-password” with your actual account credentials. Save the session details, including the accessToken
and refreshToken
from the response, to a secure location or a .env
file.
To initialize the WhatsApp client and start interacting with the API, follow these steps:
const { Waabot } = require("wasms-sdk");
const waabot = new Waabot(config.accessToken, config.refreshToken);
const chatId = "15417543010";
const chat = {
chatId,
fullname: "Chat Name",
displayName: "Display Name",
organization: "Organization",
phoneNumber: chatId,
};
const message = "This is the message to be sent!";
Import the Waabot
class from the SDK.
Create a new instance of Waabot
by passing the accessToken
and refreshToken
obtained from the session creation step.
Define a chat
object with the necessary details, such as chatId
, fullname
, displayName
, organization
, and phoneNumber
.
Set the message
variable with the desired content of the message to be sent.
To create a WhatsApp instance, use the following code:
const response = await waabot.whatsapp.createNew();
The response will contain the settings and details of the newly created instance.
To configure the WhatsApp instance, use the following code:
waabot.setConfig({
session_id: "464c3391-dee7-4206-ad13-d75ffb7498a0",
access_token: "0b375583-b9c7-4a86-b95c-7e5064326778",
});
Replace the session_id
and access_token
with the appropriate values you want to use for the rest of the requests.
To send a text message, use the following code:
await waabot.whatsapp.sendTextMessages({ chatId, message });
To send a list message, use the following code:
await waabot.whatsapp.sendListMessage({
chatId,
msgdata: {
buttonText: "Button Text",
text: "Middle Text",
title: "Head Title",
description: "Footer Description",
sections: [
{
title: "title",
rows: [
{
title: "Title Option 1",
description: "Option Description",
rowId: "string"
}
]
}
],
"listType": 0
}
});
To send a contact, use the following code:
await waabot.whatsapp.sendContact({
chatId,
vcard: {
fullName: chat.fullname,
displayName: chat.displayName,
organization: chat.organization,
phoneNumber: chat.phoneNumber,
},
});
Note: The provided code snippets are examples and may need to be modified to fit your specific implementation and requirements.