# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: Chatwoot
spec:
    description: Delightful customer relationships, at scale
    coverImage: https://img.5xcamp.us/i/eacda81d-496e-4d9c-ac0c-242081ce79d9.png
    icon: https://cdn.zeabur.com/chatwoot.png
    variables:
        - key: FRONTEND_URL
          type: DOMAIN
          name: 域名
          description: 前端服务访问使用的url
        - key: SECRET_KEY_BASE
          type: STRING
          name: Rails 密钥（SECRET_KEY_BASE）
          description: 用于验证 Rails 签名 Cookie 的密钥，可以通过 `bundle exec rake secret` 生成
        - key: DEFAULT_LOCALE
          type: STRING
          name: 默认语言（DEFAULT_LOCALE）
          description: 默认使用的语言，例如 zh_CN、en、ja
    tags:
        - Tool
    readme: |-
        Chatwoot is an open-source, self-hosted customer engagement suite. Chatwoot lets you view and manage your customer data, communicate with them irrespective of which medium they use, and re-engage them based on their profile.

        ## Features

        Chatwoot allows you to manage conversations across various channels, including websites, Facebook, Instagram, Twitter, Telegram, WhatsApp, Line, and more, all from a single dashboard. It offers CRM features to save customer information, supports custom attributes, shared inboxes, private notes, canned responses, conversation labels, and auto-assignment.

        Chatwoot also ensures conversation continuity and supports multiple languages. Additionally, it provides powerful APIs and webhooks for integration and can be linked with Slack for seamless communication.

        ## Deployment

        This template is mostly pre-configured for you. However, it is recommended to **update the SECRET_KEY_BASE of the `sidekiq` and `rails` services to a unique value**. You can generate it by running "bundle exec rake secret". The value should be consistent across both services.

        For more configuration (email sending, social platform, etc.), see [the `.env.example` file in Chatwoot repository](https://github.com/chatwoot/chatwoot/blob/develop/.env.example).
    services:
        - name: redis
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/redis.svg
          template: PREBUILT
          spec:
            source:
                image: redis/redis-stack-server:latest
            ports:
                - id: database
                  port: 6379
                  type: TCP
            volumes:
                - id: data
                  dir: /data
            instructions:
                - title: Command to connect to your Redis
                  content: redis-cli -h ${PORT_FORWARDED_HOSTNAME} -p ${DATABASE_PORT_FORWARDED_PORT} -a ${REDIS_PASSWORD}
                - title: Redis Connection String
                  content: redis://:${REDIS_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}
                - title: Redis password
                  content: ${REDIS_PASSWORD}
                - title: Redis host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: Redis port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                REDIS_ARGS:
                    default: --requirepass ${REDIS_PASSWORD}
                REDIS_CONNECTION_STRING:
                    default: redis://:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}
                    expose: true
                REDIS_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                REDIS_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                REDIS_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                REDIS_URL:
                    default: ${REDIS_CONNECTION_STRING}
                    expose: true
        - name: postgresql
          icon: https://cdn.zeabur.com/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            source:
                image: pgvector/pgvector:pg17
            ports:
                - id: database
                  port: 5432
                  type: TCP
            volumes:
                - id: data
                  dir: /var/lib/postgresql/data
            instructions:
                - title: Connection String
                  content: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}
                - title: PostgreSQL Connect Command
                  content: psql "postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${PORT_FORWARDED_HOSTNAME}:${DATABASE_PORT_FORWARDED_PORT}/${POSTGRES_DATABASE}"
                - title: PostgreSQL username
                  content: ${POSTGRES_USERNAME}
                - title: PostgresSQL password
                  content: ${POSTGRES_PASSWORD}
                - title: PostgresSQL database
                  content: ${POSTGRES_DATABASE}
                - title: PostgreSQL host
                  content: ${PORT_FORWARDED_HOSTNAME}
                - title: PostgreSQL port
                  content: ${DATABASE_PORT_FORWARDED_PORT}
            env:
                PGDATA:
                    default: /var/lib/postgresql/data/pgdata
                POSTGRES_CONNECTION_STRING:
                    default: postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}
                    expose: true
                POSTGRES_DATABASE:
                    default: ${POSTGRES_DB}
                    expose: true
                POSTGRES_DB:
                    default: zeabur
                POSTGRES_HOST:
                    default: ${CONTAINER_HOSTNAME}
                    expose: true
                POSTGRES_PASSWORD:
                    default: ${PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: root
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
        - name: sidekiq
          icon: https://cdn.zeabur.com/chatwoot.png
          template: PREBUILT
          spec:
            source:
                image: chatwoot/chatwoot:latest
                command:
                    - bundle
                args:
                    - exec
                    - sidekiq
                    - -C
                    - config/sidekiq.yml
            volumes:
                - id: storage
                  dir: /app/storage
            env:
                ACTIVE_STORAGE_SERVICE:
                    default: local
                DEFAULT_LOCALE:
                    default: en
                ENABLE_ACCOUNT_SIGNUP:
                    default: "false"
                FORCE_SSL:
                    default: "false"
                INSTALLATION_ENV:
                    default: docker
                LOG_LEVEL:
                    default: info
                NODE_ENV:
                    default: production
                RAILS_ENV:
                    default: production
                RAILS_LOG_TO_STDOUT:
                    default: "true"
                SECRET_KEY_BASE:
                    default: 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
        - name: rails
          icon: https://cdn.zeabur.com/chatwoot.png
          template: PREBUILT
          spec:
            source:
                image: chatwoot/chatwoot:latest
                command:
                    - /bin/sh
                args:
                    - /docker/entrypoint.sh
                    - bundle
                    - exec
                    - rails
                    - s
                    - -p
                    - "3000"
                    - -b
                    - 0.0.0.0
            ports:
                - id: web
                  port: 3000
                  type: HTTP
            volumes:
                - id: storage
                  dir: /app/storage
            env:
                ACTIVE_STORAGE_SERVICE:
                    default: local
                DEFAULT_LOCALE:
                    default: en
                ENABLE_ACCOUNT_SIGNUP:
                    default: "false"
                FORCE_SSL:
                    default: "false"
                INSTALLATION_ENV:
                    default: docker
                LOG_LEVEL:
                    default: info
                NODE_ENV:
                    default: production
                RAILS_ENV:
                    default: production
                RAILS_LOG_TO_STDOUT:
                    default: "true"
                SECRET_KEY_BASE:
                    default: 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
            configs:
                - path: /docker/entrypoint.sh
                  template: |
                    #!/bin/sh

                    set -x

                    # Remove a potentially pre-existing server.pid for Rails.
                    rm -rf /app/tmp/pids/server.pid
                    rm -rf /app/tmp/cache/*

                    echo "Waiting for postgres to become ready...."

                    # Let DATABASE_URL env take presedence over individual connection params.
                    # This is done to avoid printing the DATABASE_URL in the logs
                    $(docker/entrypoints/helpers/pg_database_url.rb)
                    PG_READY="pg_isready -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USERNAME"

                    until $PG_READY
                    do
                      sleep 2;
                    done

                    echo "Database ready to accept connections."

                    #install missing gems for local dev as we are using base image compiled for production
                    bundle install

                    BUNDLE="bundle check"

                    until $BUNDLE
                    do
                      sleep 2;
                    done

                    if [ -d /app/storage/MIGRATED_FLAG ]; then
                      echo "Skipping migration as the flag is present"
                    else
                      echo "Running migrations"
                      bundle exec rails db:chatwoot_prepare || exit 1
                      touch /app/storage/MIGRATED_FLAG
                    fi

                    # Execute the main process of the container
                    exec "$@"
                  permission: null
                  envsubst: null
          domainKey: FRONTEND_URL
localization:
    ja-JP:
        description: 規模に応じて心地よい顧客関係を構築
        readme: |-
            Chatwootは、オープンソースでセルフホスト型の顧客エンゲージメントスイートです。Chatwootを使用すると、顧客データを表示および管理し、どのようなメディアを使用していても彼らとコミュニケーションを取り、そのプロフィールに基づいて再び関与させることができます。

            ## 機能

            Chatwootは、単一のダッシュボードから、ウェブサイト、Facebook、Instagram、Twitter、Telegram、WhatsApp、Lineなど、さまざまなチャネルでの会話を管理できます。CRM機能を提供し、顧客情報を保存し、カスタム属性、共有受信トレイ、プライベートノート、定型返信、会話ラベル、自動割り当てをサポートしています。

            Chatwootは、会話の継続性を確保し、複数の言語をサポートしています。さらに、強力なAPIとWebhooksを提供して統合し、Slackと連携してシームレスなコミュニケーションを実現することができます。

            ## 展開

            このテンプレートは、ほとんど事前設定されています。ただし、`sidekiq`と`rails`サービスのSECRET_KEY_BASEをユニークな値に更新することをお勧めします。これを生成するには、`bundle exec rake secret`を実行します。この値は、両方のサービスで一貫している必要があります。

            その他の設定（メール送信、ソーシャルプラットフォームなど）については、[Chatwootリポジトリの`.env.example`ファイル](https://github.com/chatwoot/chatwoot/blob/develop/.env.example)を参照してください。
    zh-CN:
        description: 规模化地打造令人愉悦的客户关系
        readme: |-
            Chatwoot 是一款开源的，自我托管的客户互动套件。Chatwoot 让你可以查看和管理客户资料，无论他们使用何种媒介与他们沟通，并根据其个人资料重新吸引他们。

            ## 功能

            Chatwoot 允许你从单一的仪表板上管理跨各种渠道的对话，包括网站、Facebook、Instagram、Twitter、Telegram、WhatsApp、Line 等。它提供 CRM 功能来保存客户信息，支持自定义属性、共享收件箱、私人笔记、预设回复、对话标签和自动分配。

            Chatwoot 还确保对话的连续性并支持多种语言。此外，它提供强大的 API 和 webhooks 进行整合，还可以与 Slack 连接以实现无缝沟通。

            ## 部署

            此模板已大多数预配置完成。然而，建议 **将 `sidekiq` 和 `rails` 服务的 SECRET_KEY_BASE 更新为唯一值**，可以执行 `bundle exec rake secret` 产生这个 secret key。这个值应该在两个服务中应当一致。

            有关更多信息（发送电子邮件、社交平台等），请参阅 [Chatwoot 存储库中的 `.env.example` 文件](https://github.com/chatwoot/chatwoot/blob/develop/.env.example)。
    zh-TW:
        description: 規模化地打造令人愉悅的客戶關係
        readme: |-
            Chatwoot 是一款開源的，自我託管的客戶互動套件。Chatwoot 讓你可以查看和管理客戶資料，無論他們使用何種媒介與他們溝通，並根據其個人資料重新吸引他們。

            ## 功能

            Chatwoot 允許你從單一的儀表板上管理跨各種渠道的對話，包括網站、Facebook、Instagram、Twitter、Telegram、WhatsApp、Line 等。它提供 CRM 功能來保存客戶資訊，支持自訂屬性、共享收件箱、私人筆記、預設回覆、對話標籤和自動分配。

            Chatwoot 還確保對話的連續性並支持多種語言。此外，它提供強大的 API 和 webhooks 進行整合，還可以與 Slack 連接以實現無縫溝通。

            ## 部署

            此模板已大多數預配置完成。然而，建議 **將 `sidekiq` 和 `rails` 服務的 SECRET_KEY_BASE 更新為唯一值**，可以執行 `bundle exec rake secret` 產生這個 secret key。這個值應該在兩個服務中應當一致。

            有關更多資訊（傳送電子郵件、社交平台等），請參閱 [Chatwoot 儲存庫中的 `.env.example` 檔案](https://github.com/chatwoot/chatwoot/blob/develop/.env.example)。
