Deploy Your Application
How you will deploy your ChatAlly application depends very much on the modules that you use, specifically the servers/channels that you use to connect to your users’ clients.
In this guide, we will explain an exemplary deployment of a WhatsApp Cloud chat application.
Create the application
-
Follow the Getting Started guide to create an initial application in the directory
app
-
In the
app
directory, install additional modulesTerminal window npm install @chatally/whatsapp-cloud -
Add WhatsApp to the application (instead of the ConsoleServer)
index.js import { Application } from '@chatally/core'import { nlpjsMiddleware, trainNlp } from '@chatally/nlpjs'import { WhatsAppCloud } from '@chatally/whatsapp-cloud'const app = new Application({ log: false })const nlp = await trainNlp(app.getLogger('nlp.js'))app //.use(new WhatsAppCloud({webhooks: { path: '/whatsappcloud' }media: { dbPath: './data/media-ids.db' },})).use(nlpjsMiddleware(nlp)).listen()- using
webhooks.path
would allow us, to run multiple servers for webhooks within one container, e.g. if you want to add a Signal server later - changing
media.dbPath
from the default to a subdirectory, will allow us to map a docker volume to that location and thus persist the database
- using
Create a Docker container
-
Create the
Dockerfile
# Use the official Node.js image from Docker HubFROM node:20# Copy the app to the containerWORKDIR /appCOPY app .# Install app dependenciesRUN npm install# Expose the port the app runs onEXPOSE 3000# Start the appCMD ["node", "index.js"]The WhatsApp Cloud server will run a webhooks endpoint at port 3000. If you reconfigure this, you will need to expose a different port here.
-
Build the image
Terminal window docker build --tag "chatally/whatsapp-cloud" . -
Run the container
We deploy our containers with docker swarm behind a Traefik proxy, but you are free to do however you prefer
version: "3.9"networks:bridge:external: truetraefik_net:external: trueservices:app:image: chatally/whatsapp-cloudnetworks:- traefik_net- bridgevolumes:- ${PWD}/data:/app/datadeploy:labels:- traefik.enable=true- traefik.http.routers.whatsapp_chat.middlewares=sec-headers@file- traefik.http.routers.whatsapp_chat.rule=Host(`chat.example.org`)- traefik.http.routers.whatsapp_chat.tls.certresolver=letsencrypt- traefik.http.routers.whatsapp_chat.tls=true- traefik.http.services.whatsapp_chat.loadbalancer.server.port=3000- We map a local
data
directory to/app/data
, which we have configured as target for our media id database - Adapt the
Host
rule according to your domain.
Terminal window docker stack deploy -c docker-compose.yml whatsapp_chat - We map a local