Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
HOST="localhost"
PORT="3000"
DATABASE_URL="mysql://root:12345@localhost:3306/baileys_api"
RECONNECT_INTERVAL="5000"
MAX_RECONNECT_RETRIES="5"
SSE_MAX_QR_GENERATION="10"
LOG_LEVEL="warn"
NODE_ENV=development
LOG_LEVEL=debug
DATABASE_URL=postgres://user:password@localhost:5432/baileys_api
PORT=3000
MAX_RECONNECT_ATTEMPTS=5
RECONNECT_INTERVAL=5000
MAX_QR_ATTEMPTS=5
PAIR_CODE_TIMEOUT=600000
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

38 changes: 33 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
node_modules/
dist/
debug/
prisma/migrations/
# dependencies (bun install)
node_modules

# output
out
dist
*.tgz

# code coverage
coverage
*.lcov

# logs
logs
_.log
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# dotenv environment variable files
.env
*.tgz
.env.development.local
.env.test.local
.env.production.local
.env.local

# caches
.eslintcache
.cache
*.tsbuildinfo

# IntelliJ based IDEs
.idea

# Finder (MacOS) folder config
.DS_Store
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
},
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.biome": "always",
"source.organizeImports.biome": "always"
}
}
65 changes: 30 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
> 🚨 **NOTICE**: `@adiwajshing/baileys` which is this project relied on, has been discontinued. Thus, this project will be archived and stopped receiving updates anymore. Thanks everyone who's been part of this❤️
> 🚨 **NOTICE**: This project status is still WIP

---

# Baileys API

An implementation of [@adiwajshing/Baileys](https://github.com/adiwajshing/Baileys) as a simple REST API with multiple device support
An implementation of [baileys](https://github.com/WhiskeySockets/baileys) as REST API that supports managing multiple connections at once

## Requirements

- **NodeJS** version **14.5.0** or higher
- **Prisma** [supported databases](https://www.prisma.io/docs/reference/database-reference/supported-databases). Tested on MySQL and PostgreSQL
- Latest version of **NodeJS v20** or any higher major versions
- **PostgreSQL** database. It's possible to use other databases, but you might've to update the **drizzle** schema and adjust some part of the codes

## Installation

Expand All @@ -31,66 +31,61 @@ You can skip this part if you're using the prebuilt one from the release page

## Setup

1. Copy the `.env.example` file and rename it into `.env`, then update your [connection url](https://www.prisma.io/docs/reference/database-reference/connection-urls) in the `DATABASE_URL` field
1. Update your [provider](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#fields) in the `prisma/schema.prisma` file if you're using database other than MySQL
1. Run your [migration](https://www.prisma.io/docs/reference/api-reference/command-reference#prisma-migrate)
1. Copy the `.env.example` file and rename it into `.env`, then update your connection url in the `DATABASE_URL` field
1. Run the migration

```sh
npx prisma migrate (dev|deploy)
npm run db:migrate
```

or push the schema

```sh
npx prisma db push
npm run db:push
```

Don't forget to always re-run those whenever there's a change on the `prisma/schema.prisma` file
Don't forget to always re-run those whenever there's a change on the `migrations/` directory

## `.env` Configurations

```env
# Listening Host
HOST="localhost"

# Listening Port
PORT="3000"

# Database Connection URL
DATABASE_URL="mysql://root:12345@localhost:3306/baileys_api"

# Reconnect Interval (in Milliseconds)
RECONNECT_INTERVAL="5000"

# Maximum Reconnect Attempts
MAX_RECONNECT_RETRIES="5"

# Maximum SSE QR Generation Attempts
SSE_MAX_QR_GENERATION="10"

# Pino Logger Level
LOG_LEVEL="warn"
# Environment
NODE_ENV=development
# Pino log level
LOG_LEVEL=debug
# Database connection url
DATABASE_URL=postgres://user:password@localhost:5432/baileys_api
# App port
PORT=3000
# Max reconnect attempts before a connection is destroyed
MAX_RECONNECT_ATTEMPTS=5
# Interval for each reconnect, this uses exponential backoff
RECONNECT_INTERVAL=5000
# Max qr generation attempts before a connection is destroyed
MAX_QR_ATTEMPTS=5
# Timeout for authenticating using pair code before a connection is destroyed
PAIR_CODE_TIMEOUT=600000
```

## Usage

1. Make sure you have completed the **Installation** and **Setup** step
1. You can then start the app using the `start` script
2. You can then start the app using the `start` script

```sh
npm run start
```

1. Now the endpoint should be available according to your environment variables configuration. Default is at `http://localhost:3000`
3. Now the endpoint should be available according to your environment variables configuration. Default is at `http://localhost:3000`

## API Docs

The API documentation is available online [here](https://documenter.getpostman.com/view/18988925/2s8Z73zWbg). You can also import the **Postman Collection File** `(postman_collection.json)` into your Postman App alternatively
The API follow OpenAPI v3.0 spec that's accessible at `/doc`. Additionally, a SwaggerUI is also available at `/ui`

## Notes

- There's no authentication, you may want to implement your own. I don't want to force anyone into using a specific authentication method, choose whatever you love
- There's no default authentication, you may want to implement your own. There's no opinionated way for authentication, use whatever suits your need

## Notice

This project is intended for learning purpose only, don't use it for spamming or any activities that's prohibited by **WhatsApp**
This project is not affiliated in any way, and is not intended for spamming or any activities that's prohibited by **WhatsApp**
40 changes: 40 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "https://biomejs.dev/schemas/2.1.2/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"files": {
"ignoreUnknown": false
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedImports": "warn"
},
"style": {
"noNonNullAssertion": "off"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
},
"assist": {
"enabled": true,
"actions": {
"source": {
"organizeImports": "on"
}
}
}
}
10 changes: 10 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "drizzle-kit";
import { env } from "./src/lib/env";

export default defineConfig({
dialect: "postgresql",
dbCredentials: { url: env.DATABASE_URL },
out: "./migrations/",
schema: "./src/lib/db/schema.ts",
casing: "snake_case",
});
Loading