Skip to content

Commit

Permalink
feat: adds in-memory and Redis as session stores (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Hermawan <[email protected]>
  • Loading branch information
kevinhermawan and kevin-hyperjump authored Jul 15, 2024
1 parent 949780f commit 098e6b3
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ BUSINESS_PHONE_NUMBER_ID=12345678912323
DIFY_BASE_URL=https://api.dify.ai/v1
DIFY_API_KEY=app-Jdasdsdsd98n98787y
RASA_BASE_URL=http://localhost:5005/webhooks/rest/webhook
CONNECTION_PLATFORM=dify
CONNECTION_PLATFORM=dify
SESSION_DATABASE=in-memory # in-memory | redis
REDIS_URL=redis://0.0.0.0:6379
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ node_modules/
dist

# test
coverage
coverage

# Redis
redis-data
39 changes: 26 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ Here is the diagram to understand the flow:
![diagram](./docs/diagram.png)

## Features

- Webhook endpoint to receive messages from WhatsApp
- Integration with Dify and Rasa for natural language processing and response generation
- Verification of incoming webhook requests

## Prerequisites

Ensure you have the following installed:

Node.js (v18.x or later)
Expand All @@ -21,32 +23,40 @@ npm (v10.x or later)
## Getting Started

1. Clone the Repository

```bash
git clone https://github.com/yourusername/whatsapp-chatbot-connector.git
cd whatsapp-chatbot-connector
```

2. Install Dependencies

```bash
npm install
```

3. Set Environment Variables

```bash
cp .env.example .env
```

then fill in the appropriate values in the .env file.

Choose to connect to which platform by filling the `CONNECTION_PLATFORM` variable in the .env file.
Choose to connect to which platform by filling the `CONNECTION_PLATFORM` variable in the .env file.

```
CONNECTION_PLATFORM=dify
```

or

```
CONNECTION_PLATFORM=rasa
```

4. Running the Server

```bash
npm run dev
```
Expand All @@ -63,19 +73,21 @@ Now just use your WhatsApp app to send a text message to the WhatsApp Business n

## Environment Variables

| Variable Name | Description | Example |
| --- | --- | --- |
| NODE_ENV | Environment variable to set the node environment. | development |
| WEBHOOK_VERIFY_TOKEN | Webhook verification token. The value should be the same as the one you set in the WhatsApp Business API. Detail in picture below, poin **number 2**
| GRAPH_API_TOKEN | Graph API token. The value should be the same as the one you set in the WhatsApp Business API. Detail in picture below, poin **number 5** | abacdefghijk |
| BUSINESS_PHONE_NUMBER_ID | Business phone number ID. The value should be obtained from WhatsApp Business API. Detail in picture below, poin **number 6** | 12345678912323 |
| DIFY_BASE_URL | Dify base URL. | https://api.dify.ai/v1 |
| DIFY_API_KEY | Dify API key. | app-Jdasdsdsd98n98787y |
| RASA_BASE_URL | Rasa base URL. | http://localhost:5005/webhooks/rest/webhook |
| CONNECTION_PLATFORM | Platform to connect to. value should be `dify` or `rasa` | dify |

| Variable Name | Description | Example |
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| NODE_ENV | Environment variable to set the node environment. | development |
| WEBHOOK_VERIFY_TOKEN | Webhook verification token. The value should be the same as the one you set in the WhatsApp Business API. Detail in picture below, poin **number 2** |
| GRAPH_API_TOKEN | Graph API token. The value should be the same as the one you set in the WhatsApp Business API. Detail in picture below, poin **number 5** | abacdefghijk |
| BUSINESS_PHONE_NUMBER_ID | Business phone number ID. The value should be obtained from WhatsApp Business API. Detail in picture below, poin **number 6** | 12345678912323 |
| DIFY_BASE_URL | Dify base URL. | https://api.dify.ai/v1 |
| DIFY_API_KEY | Dify API key. | app-Jdasdsdsd98n98787y |
| RASA_BASE_URL | Rasa base URL. | http://localhost:5005/webhooks/rest/webhook |
| CONNECTION_PLATFORM | Platform to connect to. value should be `dify` or `rasa` | dify |
| SESSION_DATABASE | Database to store session. value should be `in-memory` or `redis` | in-memory |
| REDIS_URL | Redis URL. Required if `SESSION_DATABASE` is set to `redis` | redis://localhost:6379 |

## WhatsApp Business API Configuration

![configuration](./docs/whatsapp-configuration.png)
![api setup](./docs/whatsap-api-setup.png)

Expand All @@ -84,4 +96,5 @@ Now just use your WhatsApp app to send a text message to the WhatsApp Business n
You can deploy this app to any server that runs Node.js. The easiest one is to use Vercel. Just clone this repo and connect it from Vercel Dashboard then you are good to go.

## License
This project is licensed under the MIT License. See the LICENSE file for details.

This project is licensed under the MIT License. See the LICENSE file for details.
13 changes: 11 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ name: wa-connector
services:
wa-connector:
image: wa-connector:latest
container_name: wa-connector
container_name: wa-connector
ports:
- "5007:5007"
- "5007:5007"
env_file:
- .env # Load environment variables from the .env file

redis:
image: redis:latest
container_name: redis
ports:
- "6379:6379"
volumes:
- ./redis-data:/data
- ./redis.conf:/usr/local/etc/redis/redis.conf
command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
174 changes: 137 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"dotenv": "^16.4.5",
"express": "^4.19.2",
"morgan": "^1.10.0",
"ts-node": "^10.9.2"
"redis": "^4.6.15",
"ts-node": "^10.9.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@eslint/js": "^8.56.0",
Expand Down
Loading

0 comments on commit 098e6b3

Please sign in to comment.