{"id":29791079,"url":"https://github.com/lin-jun-xiang/agent-line-bot","last_synced_at":"2025-07-28T00:14:27.734Z","repository":{"id":203272508,"uuid":"709214769","full_name":"Lin-jun-xiang/agent-line-bot","owner":"Lin-jun-xiang","description":"🤖Free Agent Line Bot with Google Image Search, Image Generator, Video Generator...","archived":false,"fork":false,"pushed_at":"2025-07-24T08:51:52.000Z","size":9763,"stargazers_count":124,"open_issues_count":2,"forks_count":138,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-24T09:00:29.247Z","etag":null,"topics":["agent","chatbot","chatgpt","crawler","gpt","linebot","llm","vlm","zhipuai"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lin-jun-xiang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-10-24T09:01:13.000Z","updated_at":"2025-07-24T08:51:55.000Z","dependencies_parsed_at":"2024-05-14T04:24:23.449Z","dependency_job_id":"af0a9d08-f6ca-4278-b6e3-5a580d396ce2","html_url":"https://github.com/Lin-jun-xiang/agent-line-bot","commit_stats":null,"previous_names":["lin-jun-xiang/chatgpt-line-bot","lin-jun-xiang/agent-line-bot"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Lin-jun-xiang/agent-line-bot","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fagent-line-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fagent-line-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fagent-line-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fagent-line-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lin-jun-xiang","download_url":"https://codeload.github.com/Lin-jun-xiang/agent-line-bot/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lin-jun-xiang%2Fagent-line-bot/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267442959,"owners_count":24087909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","chatbot","chatgpt","crawler","gpt","linebot","llm","vlm","zhipuai"],"created_at":"2025-07-28T00:14:25.446Z","updated_at":"2025-07-28T00:14:27.724Z","avatar_url":"https://github.com/Lin-jun-xiang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ChatGPT Line Bot\n\n## 🤖 簡介\n\n將 GPT Bot 整合到 Line。並且**完全免費**支援一般**問答、圖片生成、圖片推理、線上圖片搜索、文字生影片、圖片生影片**...等功能。\n\n\n## ✨ 功能\n\n* **自然語言對話**\n\n    \u003cimg src=\"img/2023-10-25-10-03-47.png\" width=\"15%\" /\u003e\n\n* **圖片生成**\n\n    \u003cimg src=\"static/images/2025-07-22-17-43-28.png\" width=\"30%\"/\u003e\n\n    \u003cimg src=\"static/images/2025-07-23-13-57-01.png\" width=\"30%\"/\u003e\n\n* **圖片推理**\n\n    \u003cimg src=\"static/images/2025-07-22-17-47-27.png\" width=\"30%\"/\u003e\n\n* **文字生成影片**\n\n    \u003cimg src=\"static/images/2025-07-23-11-15-54.png\" width=\"30%\"/\u003e\n\n    \u003cvideo src=\"https://github.com/user-attachments/assets/37bbc2ba-2cc5-4143-8941-9395130d34cb\" controls width=\"50\"\u003e\u003c/video\u003e\n\n* **圖片生成影片**\n\n    \u003cimg src=\"static/images/2025-07-23-14-01-43.png\" width=\"30%\"/\u003e\n\n    \u003cvideo src=\"https://github.com/user-attachments/assets/6da09107-1d28-43af-ae75-3401a56eabc1\" controls width=\"50\"\u003e\u003c/video\u003e\n    \n* 每週 **星座資訊**（即時）\n\n    \u003cimg src=\"img/2023-11-02-10-00-32.png\" width=\"15%\"/\u003e\n\n* **YouTube 音樂** 頻道的定時推播\n\n    \u003cimg src=\"img/2023-11-03-14-44-41.png\" width=\"20%\" /\u003e\n\n* **在線圖片搜尋**（即時）\n\n    \u003cimg src=\"img/2024-05-17-15-08-12.png\" width=\"40%\"/\u003e\n\n\u003e [!NOTE]\n\u003e 如果你有任何功能請求，請隨時提交 PR 或 ISSUE。\n\n## 🔨 工具\n\n* `Python FastAPI`：創建 ChatGPT 回應 API\n* `gpt4free`：**免費使用 OpenAI API**\n* `zhipuai`：**免費使用 GPT API**\n* `Line messaging API channel`：連接 ChatGPT API\n* `GitHub`：代碼存儲庫\n* `replit/render/ngrok`：**免費部署你自己的 FastAPI**\n* `CronJob`：免費發送定時請求，實現定時推播消息\n\n## 🧠 免費 GPT 選項\n\n由於 `g4f` 依賴於逆向工程來調用 OpenAI 的 API，可能會不穩定。因此，作者建議使用 **Zhipu AI** 開放平台作為免費 GPT API 的替代方案。\n\n* `g4f`：使用逆向工程調用 OpenAI API\n* `zhipuai`：**Zhipu AI** 開放平台提供免費 GPT API。訪問 [官方網站](https://open.bigmodel.cn/dev/howuse/glm-4) 註冊帳戶，無需信用卡或費用。在 [個人中心](https://open.bigmodel.cn/usercenter/proj-mgmt/apikeys) 添加 API 金鑰，如下所示。將此 API 金鑰設置在環境變量中使用此 GPT 選項。\n    ![](static/images/2025-01-02-10-18-10.png)\n\n## 🎈 安裝步驟\n\n### 獲取 Tokens\n\n1. 獲取 Line Tokens：\n    1. 登錄 [Line Developer](https://developers.line.biz/en/)\n    2. 創建一個 bot：\n        1. 創建一個 `Provider` -\u003e 點擊 `Create`\n        2. 創建一個 `Channel` -\u003e 選擇 `Create a Messaging API channel`\n        3. 填寫所需的基本信息\n        4. 完成後，進入 `Basic Settings` -\u003e 在 `Channel Secret` 下，點擊 `Issue` 生成 `LINE_CHANNEL_SECRET`（後面會用到）。\n        5. 在 `Messaging API` 下，點擊 `Issue` 生成 `Channel access token`（後面會用到）。\n\n### 專案設置與執行\n\n1. Fork GitHub 專案：\n    * 註冊/登錄 [GitHub](https://github.com/)\n    * 前往 [ChatGPT-Line-Bot](https://github.com/Lin-jun-xiang/ChatGPT-Line-Bot)\n    * 點擊 `Star` 支持開發者\n    * 點擊 `Fork` 將所有代碼複製到你的存儲庫\n\n2. 選擇部屬方式\n\n    \u003cdetails\u003e\n    \u003csummary\u003e\u003cb\u003e🏠 本地免費部署\u003c/b\u003e\u003c/summary\u003e\n\n    ### 本地部署步驟\n\n    #### 2.1 啟動 Python FastAPI Server\n    ```bash\n    $env:LINE_CHANNEL_SECRET=\"...\"; $env:LINE_CHANNEL_ACCESS_TOKEN=\"...\"; $env:SERPAPI_API_KEY=\"...\"; $env:GPT_METHOD=\"...\"; $env:GPT_API_KEY=\"...\"; python main.py\n    ```\n    * `GPT_METHOD`：選擇 `g4f` 或 `zhipuai`\n    * `GPT_API_KEY`：如果使用 `zhipuai` 方法，提供你的 API 金鑰\n\n    #### 2.2 使用 ngrok 建立隧道\n    使用本地電腦作為服務器來部署 API：\n\n    1. [建立 ngrok 環境](https://dashboard.ngrok.com/get-started/setup/)\n    2. 下載適合你操作系統的 `ngrok` 版本\n    3. 將 `ngrok.exe` 路徑添加到系統的環境變量中\n    4. 執行：`ngrok config add-authtoken \u003ctoken\u003e`。從你的個人 [ngrok dashboard](https://dashboard.ngrok.com/get-started/your-authtoken) 獲取 token。\n    5. 執行：`ngrok http --url=\u003cYOUR STATIC DOMAIN\u003e.ngrok-free.app 8090` (若失敗請改嘗試 `ngrok http --hostname=\u003cYOUR STATIC DOMAIN\u003e.ngrok-free.app 8090`)\n\n        \u003cimg src=\"static/images/2025-02-11-16-16-27.png\" width=\"60%\" /\u003e\n        \u003cimg src=\"img/2024-05-15-14-03-09.png\" width=\"60%\"/\u003e\n\n    #### 2.3 設置 Webhook URL\n    將 `https://\u003cYOUR STATIC DOMAIN\u003e.ngrok-free.app/callback` 替換 Line Developer 控制台 `Messaging API` 區域中的 webhook URL。\n\n    \u003cimg src=\"static/images/2025-02-11-16-26-05.png\" width=\"60%\" /\u003e\n\n    \u003c/details\u003e\n\n    \u003cdetails\u003e\n    \u003csummary\u003e\u003cb\u003e☁️ 雲端免費部署\u003c/b\u003e\u003c/summary\u003e\n\n    ### 雲端部署選項\n\n    #### 選項 1：Render 部署\n    1. 前往 [Render](https://render.com/) 並註冊帳戶\n    2. 點擊 \"New Web Service\"\n    3. 連接你的 **GitHub** 存儲庫\n    4. 設置環境變數：\n    - `LINE_CHANNEL_SECRET`\n    - `LINE_CHANNEL_ACCESS_TOKEN`\n    - `SERPAPI_API_KEY`（可選）\n    - `GPT_METHOD`\n    - `GPT_API_KEY`（如果使用 zhipuai）\n    5. 部署完成後，使用提供的 URL 作為 webhook\n    6. 結合 [cronjob](https://console.cron-job.org/jobs) 觸發定時調用服務，避免服務閒置過久關閉\n        ![](static/images/2025-07-22-16-32-04.png)\n\n    ### 設置 Webhook URL\n    將雲端服務提供的 URL（例如：`https://your-app.render.com/callback`）設置為 Line Developer 控制台中的 webhook URL。\n\n    \u003c/details\u003e\n\n\n### 連接服務與 Line Bot\n\n回到 [Line Developer 首頁](https://manager.line.biz/account)，點擊 `Add Friend Guide`，掃描 QR 碼將 Line Bot 添加為好友。\n\n首頁 -\u003e 選擇你的 bot -\u003e 添加好友工具 -\u003e 創建好友動作條碼（https://manager.line.biz/account/\u003cyourBotId\u003e/gainfriends）\n\n恭喜！你已創建了你的第一個 Line Bot。試著與它交談——它會回覆你！\n\n## ⛄ 群組對話 vs. 個人對話\n\n* 在一對一對話中，任何消息都會觸發回應。\n* 在群組對話中，使用 `@chat` 前綴與機器人互動，例如，`@chat hi~`。\n\n\n## 🎃 功能詳介\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e自定義 Bot 個性\u003c/b\u003e\u003c/summary\u003e\n\n隨時修改 LineBot 的 `System Instruction`，個別定義屬於你喜歡的風格\n\n* 透過關鍵字`@prompt`修改: `@prompt 你是一個個性溫和的AI助理，請用繁體中文回答`\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e初始化 Bot\u003c/b\u003e\u003c/summary\u003e\n\n初始化 Bot 的 `System Instruction`，並且初始化歷史對話紀錄\n\n* 透過關鍵字`@init`初始化: `@init`\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e星座運勢查詢\u003c/b\u003e\u003c/summary\u003e\n\n當你的消息包含星座資訊請求時，網絡爬蟲將抓取每週星座：\n\n* 個人聊天：`給我天蠍座星座`, `我想知道天蠍座星座`, ...\n* 群組聊天：`@chat 給我天蠍座星座`, `@chat 我想知道天蠍座星座`, ...\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e在線圖片搜尋\u003c/b\u003e\u003c/summary\u003e\n\n當你的消息包含圖片請求時，網絡爬蟲將抓取圖片：\n\n* 個人聊天：`在線找到林翔抽煙的圖片`, `給我在線林翔抽煙的圖片`, ...\n* 群組聊天：`@chat 在線找到林翔抽煙的圖片`, `@chat 給我在線林翔抽煙的圖片`, ...\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e圖片生成\u003c/b\u003e\u003c/summary\u003e\n\n只要你輸入「生成」或「創建」相關的圖片請求，Bot 會自動使用 AI 生成圖片並回傳。\n\n* 例如：`生成一隻貓的圖片`, `創建一張風景圖`\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e圖片推理（VLM）\u003c/b\u003e\u003c/summary\u003e\n\n先上傳一張圖片，再詢問與圖片內容相關的問題，Bot 會用 AI 進行推理並回覆。\n\n* 例如：**上傳圖片後**問 `這張圖片裡有什麼？`、`幫我分析這個截圖`\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e文字生成影片\u003c/b\u003e\u003c/summary\u003e\n\n只要你輸入「生成」或「創建」相關的影片請求，Bot 會自動使用 AI 生成影片並回傳。\n\n* 例如：`生成一段正在走動的貓的影片`\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e圖片生成影片\u003c/b\u003e\u003c/summary\u003e\n\n只要你輸入圖片後，接著輸入「根據圖片生成」或「根據圖片創建」相關的影片請求，Bot 會自動使用 AI 生成影片並回傳。\n\n* 例如：`根據剛剛上船的圖片生成一段...的影片`,\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e自動廣播消息 - 每日 YouTube 推薦\u003c/b\u003e\u003c/summary\u003e\n\n* 使用 `broadcast` API，Line Bot 可以一次性推送消息給所有用戶。\n* 此示例演示了 Line Bot 如何每天早上推送 3 首隨機選擇的 YouTube 歌曲：\n  * 創建文件 `./data/favorite_videos.json`。參考作者的數據集。\n\n    （數據集是使用 `YouTube Data v3 API` 抓取喜愛視頻生成的。本指南不涉及 YouTube API 的使用。）\n\n  * 使用 `./ChatGPT_linebot/modules/youtube_recommend.py` 隨機選擇 3 首歌曲，由 GPT 格式化。\n  * 在 `./ChatGPT_linebot/urls.py` 中添加 `/recommend` 路由：\n\n    ```python\n    videos = recommend_videos() # 獲取 3 首歌曲\n\n    if videos:\n        line_bot_api.broadcast(TextSendMessage(text=videos)) # 廣播給用戶\n\n        # 推送消息給已知群組\n        known_group_ids = [\n            'C6d-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',\n            'Ccc-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',\n            'Cbb-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',\n        ]\n        for group_id in known_group_ids:\n            line_bot_api.push_message(group_id, TextSendMessage(text=videos))\n    ```\n\n    要獲取群組 `group_id`，在控制台中打印：\n\n    ```python\n    elif event.source.type == 'group' and user_message.startswith('@chat'):\n        group_id = event.source.group_id\n        print(group_id) # 輸出 group_id\n    ```\n\n  * 現在，訪問 `/recommend` 路由將廣播消息給所有用戶和指定群組。\n  * 使用 [cron-job.org](https://cron-job.org/en/) 每天早上 8:00 定時推送：\n    1. 註冊/登錄 [cron-job.org](https://cron-job.org/en/)\n    2. 點擊右上角的 `CREATE CRONJOB`\n    3. 標題：`ChatGPT-Line-Bot`，URL：例如，`https://ChatGPT-Line-Bot.jimmylin.repl.co/`\n    4. 設置為每 `5 分鐘` 运行\n    5. 點擊 `CREATE`\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003e自動廣播消息 - 財經資訊推播\u003c/b\u003e\u003c/summary\u003e\n  * 與 **每日 YouTube 推薦** 一樣，只需要將 `/recommend` 替換成 `/cwsChannel` 即可。\n  * 可於 CronJob 設置每 `3 小時` 運行\n\n  \u003cimg src=\"static/images/2025-02-11-17-27-24.png\" width=\"30%\" /\u003e\n\n\u003c/details\u003e\n\n## 參考資料\n\n1. [Line_Bot_Tutorial](https://github.com/FawenYo/LINE_Bot_Tutorial)\n\n2. [ChatGPT-Line-Bot](https://github.com/TheExplainthis/ChatGPT-Line-Bot)\n\n\u003ca href=\"#top\"\u003e返回頂部\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flin-jun-xiang%2Fagent-line-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flin-jun-xiang%2Fagent-line-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flin-jun-xiang%2Fagent-line-bot/lists"}