This project was created to fulfill the job acceptance test at KreatifIndo
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Build WhatsApp API Service with Baileys
that can:
- Send WhatsApp message
- Receive WhatsApp message
- Get WhatsApp contacts
- Able to login Multi Device
- I've built a WhatsApp API Service before, but thats only for sending message through API
- Getting the contacts info is quiet a hassle, theres 3 way that i found to get the contacts:
- Via
inMemoryStore
that save all the event to JSON file, usually you will only get Group contacts instead Personal contacts. Its becausecontacts.set
socket.event read Personal contacts then read Group contact and Personal contacts will be overwriten by Group contacts in the JSON file; - Via
contacts.upsert
socket.event, this event only return Personal contacts and i'am using this in the early development, but later i found that the event sometimes didnt trigger, so i need to find another way; - Via
contacts.set
socket.event, this event used to store the contacts ininMemoryStore
, the issues is its trigger 2 times, sometimes it return Personal contacts first then Group contacts and vice versa. I solve it by filtering it which Group and Personal contacts because they return different object;
- Via
- Implement socket for realtime update.
- Implement API Key using JWT to identify
botId
(currently usingx-bot-id
on headers.
Step or instructions on setting up the project locally. To get a local copy up and running follow these simple example steps.
- Node 16^
-
Clone the repo
git clone https://github.com/kim-dev-git/WAZone-Server.git
-
Open the project folder
cd WAZone-Server
-
Install NPM packages
npm install
-
For the
.env
file you can create or copy it from.env.example
PORT=5000 DATABASE_URL="file:./wazone.db?connection_limit=1" // SQLite # DATABASE_URL="mysql://johndoe:randompassword@localhost:3306/mydb" // Use this if want to use MySQL/PostgreSQL
If you want to change db provider (MySQL/PostgreSQL) edit
prisma/schema.prisma
generator client { provider = "prisma-client-js" } datasource db { provider = "sqlite" // (mysql/postgresql) <== change this url = env("DATABASE_URL") }
-
Initialize the database
npx prisma db push
-
Run project
npm run dev
GET /bots
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
POST /bots
Parameter | Type | On | Description |
---|---|---|---|
name |
string |
body |
Required. Your Bot Name |
POST /bots/up
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
POST /bots/down
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
GET /contacts
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
GET /chats
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
Get all bot chat with the phoneNumber
: +628765xxx/08765xxx
filter or might be whatsAppId
: [email protected]
GET /chats/:phoneNumber
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
GET /messages
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
GET /messages/:chatId
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
POST /messages
Parameter | Type | On | Description |
---|---|---|---|
x-bot-id |
string |
headers |
Required. Your Bot Id |
phoneNumber |
string |
body |
Required. Your message destination |
content |
object |
body |
Required. Your message content, usualy containt { text: string } . For more details click here. |
Kiki Irwan Maulana - [email protected]
Project Link: https://github.com/kim-dev-git/WAZone-Server