Docker部署开源客户沟通平台ChatWoot

Chatwoot 简介

Chatwoot 是一款开源的多渠道客户支持平台,旨在帮助企业建立强大、高效的客户服务体系。以下是 Chatwoot 的一些主要特点和功能:

多渠道支持:    Chatwoot 支持通过多种渠道与客户进行互动,包括实时聊天、电子邮件、社交媒体(如 Facebook 和 Twitter)等。
实时聊天:      提供实时聊天功能,使客服团队能够与客户实时互动,解决问题并提供支持。
帮助中心功能:   Chatwoot 还提供强大的帮助中心功能,帮助企业创建和维护丰富的知识库,使客户能够自助获取信息,提高服务效率。
电子邮件集成:   可以集成多个电子邮件账户,使客服团队能够通过 Chatwoot 统一管理和回复客户的电子邮件。
自动化和工作流: 提供自动化工作流和规则引擎,帮助优化客户服务流程,提高效率。
开放源代码:    Chatwoot 是开源软件,你可以自由查看、修改和定制其代码以满足特定需求。
多语言支持:    提供多语言支持,适应全球范围内的用户和客户。
团队协作:      支持多用户和团队协作,使团队成员能够协同工作,提供一致的客户支持。
跟踪和分析:    提供报告和分析工具,帮助你了解客户服务绩效,并采取相应的改进措施。

通过使用 Chatwoot,企业可以更好地管理和响应客户请求,提高客户满意度,同时保持对话历史记录,以更好地了解客户需求。

使用 Docker 部署

一、安装docker

先设置一下配置文件
mkdir /etc/docker && nano -w /etc/docker/daemon.json

{
  "data-root": "/srv/docker",
  "dns": ["8.8.8.8", "8.8.4.4"]
}

Docker 20.10.13 版本起,docker-compose 被替换为 docker compose(插件形式),可以直接用 pacman 安装:

1️⃣ 安装 Docker 和 Compose 插件

pacman -S docker docker-compose

2️⃣ 启动 Docker

systemctl enable --now docker

3️⃣ 验证 docker compose 是否可用

docker compose version

如果安装成功,你应该会看到类似输出:

Docker Compose version 2.32.4

二、配置服务器

创建程序目录

/srv && mkdir chatwoot && cd chatwoot

创建数据目录

mkdir -p ./{postgres,redis,storage}

设置环境变量

wget -O .env https://raw.githubusercontent.com/chatwoot/chatwoot/develop/.env.example

env 环境变量文件

wget -O .env https://raw.githubusercontent.com/chatwoot/chatwoot/develop/.env.example

SECRET_KEY_BASE :     可以用命令 openssl rand -base64 32 来生成;
FRONTEND_URL :        前端地址,根据实际情况填写,例如 http://127.0.0.1:3000,或具体ip,例如http://192.168.0.10:3000
HELPCENTER_URL :      帮助中心地址,可以和 FRONTEND_URL 一样
POSTGRES_PASSWORD:    PostgresSQL 数据库密码,这个密码需要与 docker-compose.yaml 里的 PostgresSQL 密码一致

nano -w .env

# Learn about the various environment variables at
# https://www.chatwoot.com/docs/self-hosted/configuration/environment-variables/#rails-production-variables

# Used to verify the integrity of signed cookies. so ensure a secure value is set
# SECRET_KEY_BASE should be alphanumeric. Avoid special characters or symbols. 
# Use `rake secret` to generate this variable
SECRET_KEY_BASE=BJ/aKkDoj1E0HqwtwqXSE9gcqd5hzG8tgT809UV0zM4=

# Replace with the URL you are planning to use for your app
FRONTEND_URL=http://116.202.96.177:3000
# To use a dedicated URL for help center pages
# HELPCENTER_URL=http://0.0.0.0:3000
HELPCENTER_URL=http://116.202.96.177:3000

# If the variable is set, all non-authenticated pages would fallback to the default locale.
# Whenever a new account is created, the default language will be DEFAULT_LOCALE instead of en
# DEFAULT_LOCALE=en

# If you plan to use CDN for your assets, set Asset CDN Host
ASSET_CDN_HOST=

# Force all access to the app over SSL, default is set to false
FORCE_SSL=false

# This lets you control new sign ups on your chatwoot installation
# true : default option, allows sign ups
# false : disables all the end points related to sign ups
# api_only: disables the UI for signup, but you can create sign ups via the account apis
ENABLE_ACCOUNT_SIGNUP=false

# Redis config
# specify the configs via single URL or individual variables
# ref: https://www.iana.org/assignments/uri-schemes/prov/redis
# You can also use the following format for the URL: redis://:password@host:port/db_number
REDIS_URL=redis://redis:6379
# If you are using docker-compose, set this variable's value to be any string,
# which will be the password for the redis service running inside the docker-compose
# to make it secure
REDIS_PASSWORD=
# Redis Sentinel can be used by passing list of sentinel host and ports e,g. sentinel_host1:port1,sentinel_host2:port2
REDIS_SENTINELS=
# Redis sentinel master name is required when using sentinel, default value is "mymaster".
# You can find list of master using "SENTINEL masters" command
REDIS_SENTINEL_MASTER_NAME=

# By default Chatwoot will pass REDIS_PASSWORD as the password value for sentinels
# Use the following environment variable to customize passwords for sentinels.
# Use empty string if sentinels are configured with out passwords
# REDIS_SENTINEL_PASSWORD=

# Redis premium breakage in heroku fix
# enable the following configuration
# ref: https://github.com/chatwoot/chatwoot/issues/2420
# REDIS_OPENSSL_VERIFY_MODE=none

# Postgres Database config variables
# You can leave POSTGRES_DATABASE blank. The default name of
# the database in the production environment is chatwoot_production
# POSTGRES_DATABASE=
POSTGRES_HOST=postgres
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=password
RAILS_ENV=development
# Changes the Postgres query timeout limit. The default is 14 seconds. Modify only when required.
# POSTGRES_STATEMENT_TIMEOUT=14s
RAILS_MAX_THREADS=5

# The email from which all outgoing emails are sent
# could user either  `email@yourdomain.com` or `BrandName <email@yourdomain.com>`
MAILER_SENDER_EMAIL=Chatwoot <accounts@chatwoot.com>

#SMTP domain key is set up for HELO checking
SMTP_DOMAIN=chatwoot.com
# Set the value to "mailhog" if using docker-compose for development environments,
# Set the value as "localhost" or your SMTP address in other environments
# If SMTP_ADDRESS is empty, Chatwoot would try to use sendmail(postfix)
SMTP_ADDRESS=
SMTP_PORT=1025
SMTP_USERNAME=
SMTP_PASSWORD=
# plain,login,cram_md5
SMTP_AUTHENTICATION=
SMTP_ENABLE_STARTTLS_AUTO=true
# Can be: 'none', 'peer', 'client_once', 'fail_if_no_peer_cert', see http://api.rubyonrails.org/classes/ActionMailer/Base.html
SMTP_OPENSSL_VERIFY_MODE=peer
# Comment out the following environment variables if required by your SMTP server
# SMTP_TLS=
# SMTP_SSL=
# SMTP_OPEN_TIMEOUT
# SMTP_READ_TIMEOUT

# Mail Incoming
# This is the domain set for the reply emails when conversation continuity is enabled
MAILER_INBOUND_EMAIL_DOMAIN=
# Set this to the appropriate ingress channel with regards to incoming emails
# Possible values are :
# relay for Exim, Postfix, Qmail
# mailgun for Mailgun
# mandrill for Mandrill
# postmark for Postmark
# sendgrid for Sendgrid
RAILS_INBOUND_EMAIL_SERVICE=
# Use one of the following based on the email ingress service
# Ref: https://edgeguides.rubyonrails.org/action_mailbox_basics.html
# Set this to a password of your choice and use it in the Inbound webhook
RAILS_INBOUND_EMAIL_PASSWORD=

MAILGUN_INGRESS_SIGNING_KEY=
MANDRILL_INGRESS_API_KEY=

# Creating Your Inbound Webhook Instructions for Postmark and Sendgrid:
# Inbound webhook URL format:
#    https://actionmailbox:[YOUR_RAILS_INBOUND_EMAIL_PASSWORD]@[YOUR_CHATWOOT_DOMAIN.COM]/rails/action_mailbox/[RAILS_INBOUND_EMAIL_SERVICE]/inbound_emails
# Note: Replace the values inside the brackets; do not include the brackets themselves.
# Example: https://actionmailbox:mYRandomPassword3@chatwoot.example.com/rails/action_mailbox/postmark/inbound_emails
# For Postmark
# Ensure the 'Include raw email content in JSON payload' checkbox is selected in the inbound webhook section.

# Storage
ACTIVE_STORAGE_SERVICE=local

# Amazon S3
# documentation: https://www.chatwoot.com/docs/configuring-s3-bucket-as-cloud-storage
S3_BUCKET_NAME=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=

# Log settings
# Disable if you want to write logs to a file
RAILS_LOG_TO_STDOUT=true
LOG_LEVEL=info
LOG_SIZE=500
# Configure this environment variable if you want to use lograge instead of rails logger
#LOGRAGE_ENABLED=true

### This environment variables are only required if you are setting up social media channels

# Facebook
# documentation: https://www.chatwoot.com/docs/facebook-setup
FB_VERIFY_TOKEN=
FB_APP_SECRET=
FB_APP_ID=

# https://developers.facebook.com/docs/messenger-platform/instagram/get-started#app-dashboard
IG_VERIFY_TOKEN=

# Twitter
# documentation: https://www.chatwoot.com/docs/twitter-app-setup
TWITTER_APP_ID=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_ENVIRONMENT=

#slack integration
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=

# Google OAuth
GOOGLE_OAUTH_CLIENT_ID=
GOOGLE_OAUTH_CLIENT_SECRET=
GOOGLE_OAUTH_CALLBACK_URL=

### Change this env variable only if you are using a custom build mobile app
## Mobile app env variables
IOS_APP_ID=L7YLMN4634.com.chatwoot.app
ANDROID_BUNDLE_ID=com.chatwoot.app

# https://developers.google.com/android/guides/client-auth (use keytool to print the fingerprint in the first section)
ANDROID_SHA256_CERT_FINGERPRINT=AC:73:8E:DE:EB:56:EA:CC:10:87:02:A7:65:37:7B:38:D4:5D:D4:53:F8:3B:FB:D3:C6:28:64:1D:AA:08:1E:D8

### Smart App Banner
# https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
# You can find your app-id in https://itunesconnect.apple.com
#IOS_APP_IDENTIFIER=1495796682

## Push Notification
## generate a new key value here : https://d3v.one/vapid-key-generator/
# VAPID_PUBLIC_KEY=
# VAPID_PRIVATE_KEY=
#
# for mobile apps
# FCM_SERVER_KEY=

### APM and Error Monitoring configurations
## Elastic APM
## https://www.elastic.co/guide/en/apm/agent/ruby/current/getting-started-rails.html
# ELASTIC_APM_SERVER_URL=
# ELASTIC_APM_SECRET_TOKEN=

## Sentry
# SENTRY_DSN=


## Scout
## https://scoutapm.com/docs/ruby/configuration
# SCOUT_KEY=YOURKEY
# SCOUT_NAME=YOURAPPNAME (Production)
# SCOUT_MONITOR=true

## NewRelic
# https://docs.newrelic.com/docs/agents/ruby-agent/configuration/ruby-agent-configuration/
# NEW_RELIC_LICENSE_KEY=
# Set this to true to allow newrelic apm to send logs.
# This is turned off by default.
# NEW_RELIC_APPLICATION_LOGGING_ENABLED=

## Datadog
## https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#environment-variables
# DD_TRACE_AGENT_URL=

# MaxMindDB API key to download GeoLite2 City database
# IP_LOOKUP_API_KEY=

## Rack Attack configuration
## To prevent and throttle abusive requests
# ENABLE_RACK_ATTACK=true
# RACK_ATTACK_LIMIT=300
# ENABLE_RACK_ATTACK_WIDGET_API=true

## Running chatwoot as an API only server
## setting this value to true will disable the frontend dashboard endpoints
# CW_API_ONLY_SERVER=false

## Development Only Config
# if you want to use letter_opener for local emails
# LETTER_OPENER=true
# meant to be used in github codespaces
# WEBPACKER_DEV_SERVER_PUBLIC=

# If you want to use official mobile app,
# the notifications would be relayed via a Chatwoot server
ENABLE_PUSH_RELAY_SERVER=true

# Stripe API key
STRIPE_SECRET_KEY=
STRIPE_WEBHOOK_SECRET=

# Set to true if you want to upload files to cloud storage using the signed url
# Make sure to follow https://edgeguides.rubyonrails.org/active_storage_overview.html#cross-origin-resource-sharing-cors-configuration on the cloud storage after setting this to true.
DIRECT_UPLOADS_ENABLED=

#MS OAUTH creds
AZURE_APP_ID=
AZURE_APP_SECRET=

## Advanced configurations
## Change these values to fine tune performance
# control the concurrency setting of sidekiq
# SIDEKIQ_CONCURRENCY=10


# AI powered features
## OpenAI key
# OPENAI_API_KEY=

# Housekeeping/Performance related configurations
# Set to true if you want to remove stale contact inboxes
# contact_inboxes with no conversation older than 90 days will be removed
# REMOVE_STALE_CONTACT_INBOX_JOB_STATUS=false

docker-compose.yaml

wget -O docker-compose.yaml https://raw.githubusercontent.com/chatwoot/chatwoot/develop/docker-compose.production.yaml
version: '3'

services:
  base: &base
    image: chatwoot/chatwoot:latest
    env_file: .env ## Change this file for customized env variables
    volumes:
      - ./storage:/app/storage

  rails:
    <<: *base
    depends_on:
      - postgres
      - redis
    ports:
      - '127.0.0.1:3000:3000'
    environment:
      - NODE_ENV=production
      - RAILS_ENV=production
      - INSTALLATION_ENV=docker
    entrypoint: docker/entrypoints/rails.sh
    command: ['bundle', 'exec', 'rails', 's', '-p', '3000', '-b', '0.0.0.0']
    restart: always

  sidekiq:
    <<: *base
    depends_on:
      - postgres
      - redis
    environment:
      - NODE_ENV=production
      - RAILS_ENV=production
      - INSTALLATION_ENV=docker
    command: ['bundle', 'exec', 'sidekiq', '-C', 'config/sidekiq.yml']
    restart: always

  postgres:
    image: pgvector/pgvector:pg16
    restart: always
    ports:
      - '127.0.0.1:5432:5432'
    volumes:
      - ./postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=chatwoot
      - POSTGRES_USER=postgres
      # Please provide your own password.
      - POSTGRES_PASSWORD=password

  redis:
    image: redis:alpine
    restart: always
    command: ["sh", "-c", "redis-server --requirepass \"$REDIS_PASSWORD\""]
    env_file: .env
    volumes:
      - ./redis:/data
    ports:
      - '127.0.0.1:6479:6379'

准备数据库

docker compose run --rm rails bundle exec rails db:chatwoot_prepare
[root@archlinux chatwoot]# docker compose run --rm rails bundle exec rails db:chatwoot_prepare
[+] Running 26/26
 ✔ postgres Pulled                                                                                                                                                                                                                                         6.9s 
   ✔ a480a496ba95 Pull complete                                                                                                                                                                                                                            2.2s 
   ✔ 894a87c2a602 Pull complete                                                                                                                                                                                                                            2.2s 
   ✔ 5c683167ebb4 Pull complete                                                                                                                                                                                                                            2.4s 
   ✔ a4a2ff601989 Pull complete                                                                                                                                                                                                                            2.5s 
   ✔ f9f18b35445d Pull complete                                                                                                                                                                                                                            2.8s 
   ✔ 4341d9f4d10b Pull complete                                                                                                                                                                                                                            2.9s 
   ✔ d75b4dfa7494 Pull complete                                                                                                                                                                                                                            2.9s 
   ✔ 79531d2c07af Pull complete                                                                                                                                                                                                                            3.0s 
   ✔ 38d735e5fe5b Pull complete                                                                                                                                                                                                                            6.4s 
   ✔ 021a1a38fd6a Pull complete                                                                                                                                                                                                                            6.5s 
   ✔ f79edff05c77 Pull complete                                                                                                                                                                                                                            6.5s 
   ✔ 09219b44bd7a Pull complete                                                                                                                                                                                                                            6.5s 
   ✔ 9b2fb85f538d Pull complete                                                                                                                                                                                                                            6.5s 
   ✔ 1a6cb584f284 Pull complete                                                                                                                                                                                                                            6.5s 
   ✔ 4f41ac91f783 Pull complete                                                                                                                                                                                                                            6.6s 
   ✔ 1329a6ef5c19 Pull complete                                                                                                                                                                                                                            6.7s 
 ✔ redis Pulled                                                                                                                                                                                                                                            2.3s 
   ✔ 1f3e46996e29 Pull complete                                                                                                                                                                                                                            1.2s 
   ✔ 12fe5ac456cc Pull complete                                                                                                                                                                                                                            1.4s 
   ✔ 388474e9a6f9 Pull complete                                                                                                                                                                                                                            1.6s 
   ✔ adb45f7190c7 Pull complete                                                                                                                                                                                                                            1.7s 
   ✔ 3502a8ad5915 Pull complete                                                                                                                                                                                                                            2.1s 
   ✔ 05de3e1b5dd0 Pull complete                                                                                                                                                                                                                            2.1s 
   ✔ 4f4fb700ef54 Pull complete                                                                                                                                                                                                                            2.1s 
   ✔ a863f8dcffe5 Pull complete                                                                                                                                                                                                                            2.1s 
[+] Creating 3/3
 ✔ Network chatwoot_default       Created                                                                                                                                                                                                                  0.1s 
 ✔ Container chatwoot-redis-1     Created                                                                                                                                                                                                                  0.0s 
 ✔ Container chatwoot-postgres-1  Created                                                                                                                                                                                                                  0.0s 
[+] Running 2/2
 ✔ Container chatwoot-redis-1     Started                                                                                                                                                                                                                  0.3s 
 ✔ Container chatwoot-postgres-1  Started                                                                                                                                                                                                                  0.3s 
[+] Running 12/12
 ✔ rails Pulled                                                                                                                                                                                                                                           28.2s 
   ✔ b84a74cde5af Pull complete                                                                                                                                                                                                                            0.4s 
   ✔ c895ececcf9a Pull complete                                                                                                                                                                                                                            1.5s 
   ✔ 1a7293d14d6f Pull complete                                                                                                                                                                                                                            1.6s 
   ✔ e6b6ac5b3a26 Pull complete                                                                                                                                                                                                                            2.9s 
   ✔ e894f191bace Pull complete                                                                                                                                                                                                                            2.9s 
   ✔ 2f064b36509f Pull complete                                                                                                                                                                                                                            7.6s 
   ✔ ada3f8e9dfa9 Pull complete                                                                                                                                                                                                                            7.6s 
   ✔ 69219aa0a172 Pull complete                                                                                                                                                                                                                           25.1s 
   ✔ 9b55ccc9f75c Pull complete                                                                                                                                                                                                                           28.1s 
   ✔ a9c5df089efc Pull complete                                                                                                                                                                                                                           28.1s 
   ✔ 4f4fb700ef54 Pull complete                                                                                                                                                                                                                           28.1s 
+ rm -rf /app/tmp/pids/server.pid
+ rm -rf '/app/tmp/cache/*'
+ echo 'Waiting for postgres to become ready....'
Waiting for postgres to become ready....
+ docker/entrypoints/helpers/pg_database_url.rb
+ export 'POSTGRES_PORT=5432'
+ PG_READY='pg_isready -h postgres -p 5432 -U postgres'
+ pg_isready -h postgres -p 5432 -U postgres
postgres:5432 - accepting connections
+ echo 'Database ready to accept connections.'
Database ready to accept connections.
+ bundle install
Bundle complete! 127 Gemfile dependencies, 253 gems now installed.
Gems in the groups 'development' and 'test' were not installed.
Bundled gems are installed into `/gems`
1 installed gem you directly depend on is looking for funding.
  Run `bundle fund` for details
+ BUNDLE='bundle check'
+ bundle check
The Gemfile's dependencies are satisfied
+ exec bundle exec rails db:chatwoot_prepare
I, [2025-02-11T01:13:47.659755 #1]  INFO -- : [rake ip_lookup:setup] IP_LOOKUP_API_KEY empty. Skipping geoip database setup
Created database 'chatwoot_production'

三、启动与停止服务

[root@archlinux chatwoot]# docker compose down
WARN[0000] /srv/chatwoot/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 3/3
 ✔ Container chatwoot-postgres-1  Removed                                                                                                                                                                                                                  0.3s 
 ✔ Container chatwoot-redis-1     Removed                                                                                                                                                                                                                  0.3s 
 ✔ Network chatwoot_default       Removed                                                                                                                                                                                                                  0.1s 
[root@archlinux chatwoot]# docker compose up -d
WARN[0000] /srv/chatwoot/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Running 6/6
 ✔ Network chatwoot_default       Created                                                                                                                                                                                                                  0.1s 
 ✔ Container chatwoot-redis-1     Started                                                                                                                                                                                                                  1.0s 
 ✔ Container chatwoot-base-1      Started                                                                                                                                                                                                                  0.8s 
 ✔ Container chatwoot-postgres-1  Started                                                                                                                                                                                                                  1.0s 
 ✔ Container chatwoot-sidekiq-1   Started                                                                                                                                                                                                                  1.2s 
 ✔ Container chatwoot-rails-1     Started 

四、配置nginx

cd /etc/nginx/vhost/
nano -w yourdomain.com_ssl.conf

server {
  server_name <yourdomain.com>;

  # Point upstream to Chatwoot App Server
  set $upstream 127.0.0.1:3000;

  # Nginx strips out underscore in headers by default
  # Chatwoot relies on underscore in headers for API
  # Make sure that the config is set to on.
  underscores_in_headers on;
  location /.well-known {
    alias /var/www/ssl-proof/chatwoot/.well-known;
  }

  location / {
    proxy_pass_header Authorization;
    proxy_pass http://$upstream;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Ssl on; # Optional

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_http_version 1.1;
    proxy_buffering off;

    client_max_body_size 0;
    proxy_read_timeout 36000s;
    proxy_redirect off;
  }
  listen 80;
}

关于Zeno Chen

本人涉及的领域较多,杂而不精 程序设计语言: Perl, Java, PHP, Python; 数据库系统: MySQL,Oracle; 偶尔做做电路板的开发,主攻STM32单片机
此条目发表在Ruby分类目录。将固定链接加入收藏夹。