This is a simple implementation of the @WhiskeySockets/Baileys library for interacting with WhatsApp through a RESTful API. This README provides instructions on how to set up and use the API.
To get started, follow these steps:
-
Install the required dependencies:
npm install
-
Start the API server:
npm run start
I'm highly recommended to create your sessionId using a unique identifier like uuid, but you can also use your phone number as sessionId
the receiver phone number only support with full country code eg: 6285123123123
To use the WhatsApp API, you'll need to create a session. Use the following curl command to create a session:
curl --location --request POST 'localhost:3000/sessions/:sessionId' \
--header 'x-api-key: YOUR_API_KEY'Replace :sessionId with a unique session identifier and YOUR_API_KEY with your actual API key.
You can check the status of a session using the following curl command:
curl --location 'localhost:3000/sessions/:sessionId' \
--header 'x-api-key: YOUR_API_KEY'Replace :sessionId with the session you want to check and YOUR_API_KEY with your actual API key.
To log out of a session, use the following curl command:
curl --location --request POST 'localhost:3000/sessions/:sessionId/logout' \
--header 'x-api-key: YOUR_API_KEY'Replace :sessionId with the session you want to log out of and YOUR_API_KEY with your actual API key.
You can send a text message using the API with the following curl command:
curl --location 'localhost:3000/send' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data '{
"sender": "YOUR_SESSION_ID",
"receiver": "YOUR_TARGET_RECEIVER",
"message": "YOUR_MESSAGE"
}'Replace YOUR_SESSION_ID with the session you want to send the message from, YOUR_TARGET_RECEIVER with the recipient's identifier, and YOUR_MESSAGE with the actual message content.
To send bulk text messages, you can use the following curl command:
curl --location 'localhost:3000/send' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data '{
"sender": "YOUR_SESSION_ID",
"receiver": "YOUR_TARGET_RECEIVER_1|YOUR_TARGET_RECEIVER_2",
"message": "YOUR_MESSAGE"
}'Replace YOUR_SESSION_ID with the session you want to send the messages from, YOUR_TARGET_RECEIVER_1|YOUR_TARGET_RECEIVER_2 with a pipe-separated list of target receivers, and YOUR_MESSAGE with the actual message content.
To send media messages, use the following curl command:
curl --location 'localhost:3000/send' \
--header 'Content-Type: application/json' \
--header 'x-api-key: YOUR_API_KEY' \
--data '{
"sender": "YOUR_SESSION_ID",
"receiver": "YOUR_TARGET_RECEIVER_1",
"message": "YOUR_MESSAGE",
"file" : "YOUR_MEDIA_PUBLIC_URL"
}'Replace YOUR_SESSION_ID with the session you want to send the media from, YOUR_TARGET_RECEIVER_1 with the recipient's identifier, YOUR_MESSAGE with the actual message content, and YOUR_MEDIA_PUBLIC_URL with the public URL of the media file you want to send.
Feel free to explore and integrate this WhatsApp API into your applications for automated messaging and interaction with WhatsApp. Make sure to keep your API key secure and follow WhatsApp's terms of service and guidelines when using this API.