# yaml-language-server: $schema=https://schema.zeabur.app/template.json
apiVersion: zeabur.com/v1
kind: Template
metadata:
    name: LineBot-LLM
spec:
    description: A Line LLM Bot with FastAPI.
    icon: https://raw.githubusercontent.com/yuting1214/logo-store/refs/heads/main/assets/line-icon.svg
    variables:
        - key: PUBLIC_DOMAIN
          type: DOMAIN
          name: Domain
          description: What is the domain you want for your LineBot?
        - key: OPENAI_API_KEY
          type: STRING
          name: What's your OpenAI API key?
          description: You need to fill in your OpenAI API key to get your response from OpenAI.
        - key: LINE_CHANNEL_SECRET
          type: STRING
          name: What's your Line Channel Seret?
          description: Required for Line Bot.
        - key: LINE_CHANNEL_ACCESS_TOKEN
          type: STRING
          name: What's your Line Channel Access Token?
          description: Required for Line Bot.
        - key: USER_NAME
          type: STRING
          name: User Name
          description: User name for accessing backend API document.
        - key: PASSWORD
          type: STRING
          name: Password
          description: Password for accessing backend API document.
    tags:
        - Bot
    readme: "## Key Features and Integrations \U0001F389\n* \U0001F916 LINE Bot Integration: Easily create and manage LINE bots with built-in event handling and messaging capabilities.\n* ⚡ FastAPI API Documentation and Authentication: Leverage FastAPI's powerful documentation tools and secure authentication mechanisms.\n* \U0001F9E0 LLM Integration (OpenAI): Implement advanced chatbot logic using Large Language Models, with support for text and image modalities.\n\n## Why This Template ? \U0001F680\n* \U0001F4DD API-Driven Logging: This template uses API calls to log data, ensuring better modularity and flexibility.\n* ⚙️ Async Non-Blocking Operations: Designed to handle multiple user inputs simultaneously, making the bot responsive and efficient even under heavy load.\n* \U0001F310 LLM Omniversal Integration: Supports various input modalities (text, image, audio) for a more versatile and interactive chatbot experience.\n\n## Setting Up API Key and Credentials \U0001F511\n\nTo enable full functionality, you'll need to set up your LINE API credentials and configure the environment variables.\n\n### 1. Register on LINE Developer Console\n* **Log in to LINE Developer Console**: [LINE Developer Console](https://developers.line.biz/)\n* **Set up LINE Authentication**:\n  - Click **\"Create a new Channel\"**.\n  - Choose **Message API** as the type of channel.\n* **Retrieve Important Keys and Tokens**:\n  - Go to **Basic Settings** and copy the **Channel Secret**.\n  - Go to **Messaging API** and copy the **Channel Access Token** (click **Issue** if setting up for the first time).\n### 2. Set up Webhook\n* **Obtain Public Domain**: Once you have deployed your app and obtained a public domain (e.g., `https://line.app`), ensure you use this URL in the Webhook settings.\n* **Configure Webhook URL**: In **Messaging API** settings, set the **Webhook URL** as:\n```\n  https://your-public-domain/webhooks/line\n```\n  Replace `your-public-domain` with your actual domain and add the `/webhooks/line` suffix for correct routing.\n* **Enable Webhook**: Ensure that the **Use Webhook** option is enabled so your bot can start receiving messages from LINE users.\n\nBy following these steps, your LINE bot will be ready to handle events and interact with users!\n\n## Contributing \U0001F91D\nWe welcome contributions from the community! Whether it's bug fixes, feature enhancements, or documentation improvements, feel free to open a pull request.\n\n---\n\nDesigned with :heart: by [Mark Chen](https://github.com/yuting1214)"
    services:
        - name: postgresql
          icon: https://raw.githubusercontent.com/zeabur/service-icons/main/marketplace/postgresql.svg
          template: PREBUILT
          spec:
            id: postgresql
            source:
                image: postgres:17
                command:
                    - docker-entrypoint.sh
                    - -c
                    - config_file=/etc/postgresql/postgresql.conf
            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: ${PG_PASSWORD}
                    expose: true
                POSTGRES_PORT:
                    default: ${DATABASE_PORT}
                    expose: true
                POSTGRES_URI:
                    default: ${POSTGRES_CONNECTION_STRING}
                    expose: true
                POSTGRES_USER:
                    default: root
                    expose: true
                POSTGRES_USERNAME:
                    default: ${POSTGRES_USER}
                    expose: true
            configs:
                - path: /etc/postgresql/postgresql.conf
                  template: |
                    # https://github.com/postgres/postgres/blob/master/src/backend/utils/misc/postgresql.conf.sample
                    listen_addresses = '*'
                    max_connections = 100
                    shared_buffers = 128MB
                    dynamic_shared_memory_type = posix
                    max_wal_size = 1GB
                    min_wal_size = 80MB
                    log_timezone = 'Etc/UTC'
                    datestyle = 'iso, mdy'
                    timezone = 'Etc/UTC'
                    lc_messages = 'en_US.utf8'
                    lc_monetary = 'en_US.utf8'
                    lc_numeric = 'en_US.utf8'
                    lc_time = 'en_US.utf8'
                    default_text_search_config = 'pg_catalog.english'
                  permission: null
                  envsubst: null
        - name: LineBot
          icon: https://raw.githubusercontent.com/yuting1214/logo-store/refs/heads/main/assets/line-icon.svg
          dependencies:
            - postgresql
          template: PREBUILT
          spec:
            id: linebot
            source:
                image: markchen1214/linebot-fastapi:latest
            ports:
                - id: web
                  port: 5000
                  type: HTTP
            env:
                DATABASE_URL:
                    default: ${POSTGRES_CONNECTION_STRING}
                HOST_URL:
                    default: ${ZEABUR_WEB_URL}
          domainKey: PUBLIC_DOMAIN
localization:
    zh-TW:
        description: LineBot-LLM 是一個使用 FastAPI 開發 LINE 機器人的完整模組化範本。
        readme: "## 主要功能與整合 \U0001F389\n* \U0001F916 **LINE Bot 整合**：輕鬆建立並管理 LINE 機器人，具有內建的事件處理與訊息功能。\n* ⚡ **FastAPI 文件化與認證**：利用 FastAPI 強大的文件生成工具與安全認證機制。\n* \U0001F9E0 **LLM 整合 (OpenAI)**：使用大型語言模型實現先進的聊天機器人邏輯，支援文本、圖片和音頻模態。\n## 為什麼選擇這個範本？ \U0001F680\n* \U0001F4DD **API 驅動的日誌紀錄**：此範本使用 API 呼叫來紀錄數據，確保更高的模組化與靈活性。\n* ⚙️ **非阻塞的非同步操作**：設計用於同時處理多個使用者輸入，使機器人在高負載下仍保持響應快速且高效。\n* \U0001F310 **LLM 全方位整合**：支援各種輸入模態（文本、圖片、音頻），提供更全面和互動式的聊天機器人體驗。\n## 設定 API 金鑰與憑證 \U0001F511\n為了啟用全部功能，您需要設置 LINE API 的憑證並配置環境變數。\n### 1. 在 LINE 開發者控制台註冊\n* **登入 LINE 開發者控制台**：[LINE Developer Console](https://developers.line.biz/)\n* **設定 LINE 認證**：\n  - 點擊 **「建立新頻道」**。\n  - 選擇 **訊息 API** 作為頻道類型。\n* **取得重要的金鑰與憑證**：\n  - 進入 **基本設定** 並複製 **Channel Secret**。\n  - 進入 **Messaging API** 並複製 **Channel Access Token**（如果是首次設定，請點擊 **發行**）。\n### 2. 設定 Webhook\n* **取得公共域名**：當您部署應用程式並獲得公共域名（例如 `https://line.app`）後，請確保在 Webhook 設定中使用此 URL。\n* **配置 Webhook URL**：在 **Messaging API** 設定中，將 **Webhook URL** 設為：\n  ```\n  https://your-public-domain/webhooks/line\n  ```\n  請將 `your-public-domain` 替換為您的實際域名，並加上 `/webhooks/line` 後綴以正確路由。\n* **啟用 Webhook**：確保啟用 **使用 Webhook** 選項，以便機器人可以開始接收來自 LINE 使用者的訊息。\n\n完成這些步驟後，您的 LINE 機器人將準備好處理事件並與使用者互動！\n\n## 貢獻 \U0001F91D\n我們歡迎社群的貢獻！無論是修正錯誤、增強功能，還是改進文件，查看我們的[問題頁面](https://github.com/yuting1214/LineBot/issues)來尋找需要幫助的地方。\n\n---\n\n由 [Mark Chen](https://github.com/yuting1214) 精心設計 :heart:"
