Chatwoot的部署-网站添加聊天对话框

开源代码 https://github.com/chatwoot/chatwoot

创建安装文件夹

mkdir -p /root/data/docker_data/chatwoot

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

创建环境配置文件.env

该链接中下载模板  https://github.com/chatwoot/chatwoot/blob/develop/.env.example

完整配置参考 https://www.chatwoot.com/docs/self-hosted/configuration/environment-variables

简单配置样本说明 改名环境配置文件为.env后上传到 安装文件夹chatwoot

# 在服务器上运行 openssl rand -base64 32,获得生成随机字符串 用作密码

# 用于验证签名cookie的完整性 
SECRET_KEY_BASE= bY00SEKLFz9H3x3mi3CR3VQaqU7N5RVXWkuJKChmt=

# 替换域名或者IP地址
FRONTEND_URL= https://chat.domain.com

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

# 注册选项
# true : 允许注册
# false : 关闭注册
# api_only: 关闭UI上的注册,但可以通过API注册
ENABLE_ACCOUNT_SIGNUP=false

# Redis 配置
REDIS_URL=redis://redis:6379
# 设置REDIS的密码
Q4008lVBoP+k0R97z9pRmXcXtWeS2y1QbMyUxU53s=

# Postgres Database 配置
POSTGRES_HOST=postgres
POSTGRES_USERNAME=postgres
POSTGRES_PASSWORD=Q4008lVBoP+k0R97z9pRmXcXtWeS2y1QbMyUxU53s=
RAILS_ENV=development
RAILS_MAX_THREADS=5

# SMTP配置,可以用来配置邮件通知。
MAILER_SENDER_EMAIL=Chatwoot <accounts@chatwoot.com>
SMTP_DOMAIN=chatwoot.com
SMTP_ADDRESS=
SMTP_PORT=
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
# 如果SMTP服务器需要,注释掉以下环境变量。
# SMTP_TLS=
# SMTP_SSL=

# 存储形式,默认本地
ACTIVE_STORAGE_SERVICE=local

# Amazon S3
S3_BUCKET_NAME=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=

# 日志设置
RAILS_LOG_TO_STDOUT=true
LOG_LEVEL=info
LOG_SIZE=500   

创建docker-compose文件

安装文件夹chatwoot下创建docker-compose文件 参考样本

version: '3'

services:
  base: &base
    image: chatwoot/chatwoot:latest
    env_file: .env
    volumes:
      - /root/data/docker_data/chatwoot/data/storage:/app/storage

  rails:
    <<: *base
    depends_on:
      - postgres
      - redis
    ports:
      - 5678: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']

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

  postgres:
    image: postgres:12
    restart: always
    # ports:
    #  - 5432:5432
    volumes:
      - /root/data/docker_data/chatwoot/data/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=Q4008lVBoP+k0R97z9pRmXcXtWeS2y1QbMyUxU53s=

  redis:
    image: redis:alpine
    restart: always
    command: ["sh", "-c", "redis-server --requirepass \"$REDIS_PASSWORD\""]
    env_file: .env
    volumes:
      - /root/data/docker_data/chatwoot/data/redis:/data
    # ports:
    #  - 6379:6379

准备数据库

docker compose run --rm rails bundle exec rails db:chatwoot_prepare   

当出现Created database 'chatwoot_production'说明完成

安装并启动

docker-compose up -d

Chatwoot镜像的更新遵循以下5步

docker-compose down

docker-compose pull

docker compose run --rm rails bundle exec rails db:chatwoot_prepare

docker-compose up -d

docker image prune

备注:

容器chatwoot-base-1不会运行 默认显示停止状态 Chatwoot镜像的更新/迁移/更新数据库 需再次执行以下命令

docker compose run --rm rails bundle exec rails db:chatwoot_prepare

反向代理及对话连续性

反向代理并开启 SSL 域名 -> 服务器IP:5678

通过电子邮件启用对话连续性 即使客户离线 可以继续通过其留下的邮箱继续接受离线信息

案例如使用sendgrid 需.env 中设置以下几项

MAILER_INBOUND_EMAIL_DOMAIN=自设域名
RAILS_INBOUND_EMAIL_SERVICE=sendgrid
RAILS_INBOUND_EMAIL_PASSWORD=自设密码

后台设置Inbound Parse入站解析 生成如下格式

[https://actionmailbox:自设密码@您的chatwoot服务器域名/rails/action_mailbox/sendgrid/inbound_emails](https://actionmailbox:%E8%87%AA%E8%AE%BE%E5%AF%86%E7%A0%81@xn--chatwoot-xq8mn1jrviuyeb49ab2tq66c/rails/action_mailbox/sendgrid/inbound_emails)

显示客户IP信息

https://www.chatwoot.com/docs/self-hosted/configuration/enable-ip-logging/

Create an account at MaxmindDB and create an API key.

# 显示客户IP信息 配置文件.env中填写
IP_LOOKUP_API_KEY=maxmind申请的License key

注册免费试用账户即可 首次使用 数据会存在服务器本地

案例参考

https://www.stao.fr/

➡️ 在线预约

电子设备维护/网络服务 预约

➡️ 远程协助

在线文字/语音/视频 协助

📢 免费提供咨询/报价 其余服务付费提供 (维修/网络/协助…) 在线预约/远程协助