Skip to content

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

  1. Follow the Getting Started guide to create an initial application in the directory app

  2. In the app directory, install additional modules

    Terminal window
    npm install @chatally/whatsapp-cloud
  3. 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
  4. Provide WhatsApp configuration

Create a Docker container

  1. Create the Dockerfile

    # Use the official Node.js image from Docker Hub
    FROM node:20
    # Copy the app to the container
    WORKDIR /app
    COPY app .
    # Install app dependencies
    RUN npm install
    # Expose the port the app runs on
    EXPOSE 3000
    # Start the app
    CMD ["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.

  2. Build the image

    Terminal window
    docker build --tag "chatally/whatsapp-cloud" .
  3. 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: true
    traefik_net:
    external: true
    services:
    app:
    image: chatally/whatsapp-cloud
    networks:
    - traefik_net
    - bridge
    volumes:
    - ${PWD}/data:/app/data
    deploy:
    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