-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 51a9db7
Showing
23 changed files
with
8,090 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
WEB_HOOK_URL= | ||
PORT=3000 | ||
API_SECRET_KEY= | ||
NODE_ENV=development | ||
LOG_LEVEL=info | ||
RATE_LIMIT_WINDOW_MS=900000 | ||
RATE_LIMIT_MAX_REQUESTS=100 | ||
SESSION_NAME=session | ||
MEDIA_DIR=storage/media | ||
SESSIONS_DIR=storage/sessions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module.exports = { | ||
env: { | ||
node: true, | ||
es2021: true, | ||
}, | ||
extends: ['eslint:recommended'], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
rules: { | ||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', | ||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules/ | ||
.env | ||
logs/* | ||
tokens/* | ||
!logs/.gitkeep | ||
storage/media/* | ||
!storage/media/.gitkeep | ||
storage/sessions/* | ||
!storage/sessions/.gitkeep | ||
.DS_Store | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"semi": true, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "es5" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Use the official Node.js image as a base | ||
FROM node:20-alpine | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy the package.json and package-lock.json to install dependencies | ||
COPY package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install --production | ||
|
||
# Copy the rest of the application files | ||
COPY . . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 3000 | ||
|
||
# Command to run the application | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Hamed Elfayome | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
# WhatsApp API Server | ||
![License](https://img.shields.io/badge/license-MIT-blue.svg) | ||
![Release](https://img.shields.io/github/v/release/hamed-elfayome/wppconnect-lite-server?label=Release&style=round-square) | ||
|
||
|
||
Lite WhatsApp API server for WppConnect, built with Node.js and Express. | ||
|
||
## Features | ||
|
||
- WhatsApp session management | ||
- Message sending and receiving | ||
- Media handling | ||
- Webhook integrations | ||
- Rate limiting | ||
- Authentication | ||
- Logging | ||
- Error handling | ||
|
||
## Prerequisites | ||
|
||
- Node.js >= 14 | ||
- npm >= 6 | ||
- A server for webhook handling | ||
|
||
## Installation | ||
|
||
1. Clone the repository | ||
```bash | ||
git clone <repository-url> | ||
cd whatsapp-api-server | ||
``` | ||
|
||
2. Install dependencies | ||
```bash | ||
npm install | ||
``` | ||
|
||
3. Create and configure .env file | ||
```bash | ||
cp .env.example .env | ||
``` | ||
|
||
4. Start the server | ||
```bash | ||
# Development | ||
npm run dev | ||
|
||
# Production | ||
npm start | ||
``` | ||
|
||
## API Documentation | ||
|
||
### Authentication | ||
|
||
All API endpoints require an `x-api-key` header with your configured API secret key. | ||
|
||
### Endpoints | ||
|
||
#### Initialize WhatsApp Session | ||
|
||
```http | ||
POST /api/whatsapp/initialize | ||
``` | ||
|
||
Initializes a new WhatsApp session and generates a QR code for authentication. | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"success": true, | ||
"message": "Initialization started" | ||
} | ||
``` | ||
|
||
#### Get Session Status | ||
|
||
```http | ||
GET /api/whatsapp/session-status | ||
``` | ||
|
||
Returns the current status of the WhatsApp session. | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"success": true, | ||
"status": "connected", | ||
"message": "Session is active and connected", | ||
"qrCode": null | ||
} | ||
``` | ||
|
||
Possible status values: | ||
- `no_session`: No session exists | ||
- `initializing`: Session is being created | ||
- `qr_ready`: QR code is ready for scanning | ||
- `connected`: Successfully connected | ||
- `disconnected`: Session is disconnected | ||
- `error`: Error occurred | ||
|
||
#### Send Message | ||
|
||
```http | ||
POST /api/whatsapp/send-message | ||
Content-Type: application/json | ||
{ | ||
"number": "1234567890", | ||
"message": "Hello from WhatsApp API!" | ||
} | ||
``` | ||
|
||
Sends a message to the specified WhatsApp number. | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"success": true, | ||
"message": "Message sent successfully to 1234567890", | ||
"messageId": "ABCD1234" | ||
} | ||
``` | ||
|
||
#### Disconnect Session | ||
|
||
```http | ||
POST /api/whatsapp/disconnect | ||
``` | ||
|
||
Disconnects the current WhatsApp session. | ||
|
||
**Response:** | ||
```json | ||
{ | ||
"success": true, | ||
"message": "Session disconnected successfully", | ||
"status": "disconnected", | ||
"qrCode": null | ||
} | ||
``` | ||
|
||
### Webhooks | ||
|
||
The server sends various events to your Laravel backend. You need to implement these webhook endpoints: | ||
|
||
#### Status Update Webhook | ||
|
||
```http | ||
POST /webhook/status | ||
{ | ||
"status": "connected" | ||
} | ||
``` | ||
|
||
Receives WhatsApp connection status updates. | ||
|
||
#### QR Code Webhook | ||
|
||
```http | ||
POST /webhook/qr | ||
{ | ||
"qrCode": "base64_encoded_qr_code_data" | ||
} | ||
``` | ||
|
||
Receives QR code data when initializing WhatsApp. | ||
|
||
#### Incoming Message Webhook | ||
|
||
```http | ||
POST /incoming-message | ||
{ | ||
"from": "1234567890@c.us", | ||
"sender": { | ||
"id": "1234567890@c.us", | ||
"name": "John Doe", | ||
"pushname": "John" | ||
}, | ||
"body": "Hello!", | ||
"type": "chat", | ||
"timestamp": 1683000000, | ||
"isGroupMsg": false, | ||
"messageId": "ABCD1234", | ||
"quotedMsg": null, | ||
"mentionedJidList": [] | ||
} | ||
``` | ||
|
||
Receives incoming WhatsApp messages. | ||
|
||
#### Media Upload Webhook | ||
|
||
```http | ||
POST /media | ||
{ | ||
file base64 | ||
} | ||
``` | ||
|
||
Receives media files from WhatsApp messages. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details. |
Oops, something went wrong.