kikiimdev / WAZone-Server

Test KreatifIndo - WAZone

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool


Logo

WAZONE - Server

This project was created to fulfill the job acceptance test at KreatifIndo
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. API Reference
  4. Contact

About The Project

Goal

Build WhatsApp API Service with Baileys that can:

  • Send WhatsApp message
  • Receive WhatsApp message
  • Get WhatsApp contacts
  • Able to login Multi Device

(back to top)

Built With

  • Node
  • Express
  • Prisma
  • Baileys
  • Typescript

(back to top)

Challenges

  • 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 because contacts.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 in inMemoryStore, 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;

(back to top)

Feature To Implement In The Future

  • Implement socket for realtime update.
  • Implement API Key using JWT to identify botId (currently using x-bot-id on headers.

(back to top)

Getting Started

Step or instructions on setting up the project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

  • Node 16^

Installation

  1. Clone the repo

    git clone https://github.com/kim-dev-git/WAZone-Server.git
  2. Open the project folder

    cd WAZone-Server
  3. Install NPM packages

    npm install
  4. 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")
    }
  5. Initialize the database

    npx prisma db push
  6. Run project

    npm run dev

(back to top)

API Reference

Get one bot

  GET /bots
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Create bot

  POST /bots
Parameter Type On Description
name string body Required. Your Bot Name

Start bot

  POST /bots/up
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Stop bot

  POST /bots/down
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Get all bot contacts

  GET /contacts
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Get all bot chats

  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: 628765xxx@s.whatsapp.net

  GET /chats/:phoneNumber
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Get all bot messages

  GET /messages
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Get all bot messages with chatId filter

  GET /messages/:chatId
Parameter Type On Description
x-bot-id string headers Required. Your Bot Id

Send message to a phoneNumber

  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.

(back to top)

Contact

Kiki Irwan Maulana - kiki.im.dev@gmail.com

Project Link: https://github.com/kim-dev-git/WAZone-Server

(back to top)

About

Test KreatifIndo - WAZone


Languages

Language:TypeScript 100.0%