{"id":20619711,"url":"https://github.com/twtrubiks/line-bot-tutorial","last_synced_at":"2025-05-16T08:03:12.597Z","repository":{"id":84518965,"uuid":"80500278","full_name":"twtrubiks/line-bot-tutorial","owner":"twtrubiks","description":"line-bot-tutorial use python flask","archived":false,"fork":false,"pushed_at":"2024-12-03T11:10:25.000Z","size":44,"stargazers_count":294,"open_issues_count":5,"forks_count":149,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-16T08:02:03.504Z","etag":null,"topics":["bot","crawler","heroku","line","ptt","python-flask","tutorial"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twtrubiks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2017-01-31T07:36:45.000Z","updated_at":"2025-04-27T18:31:41.000Z","dependencies_parsed_at":"2025-01-05T12:04:02.142Z","dependency_job_id":"d7d61096-679d-4d1b-b580-e1431e8ed239","html_url":"https://github.com/twtrubiks/line-bot-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fline-bot-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fline-bot-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fline-bot-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twtrubiks%2Fline-bot-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twtrubiks","download_url":"https://codeload.github.com/twtrubiks/line-bot-tutorial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254493381,"owners_count":22080126,"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","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":["bot","crawler","heroku","line","ptt","python-flask","tutorial"],"created_at":"2024-11-16T12:12:20.284Z","updated_at":"2025-05-16T08:03:12.579Z","avatar_url":"https://github.com/twtrubiks.png","language":"Python","readme":"# line-bot-Tutorial\n\n 教你建立自己的 line-bot 使用 python flask 📝\n\n line-bot-tutorial use python flask\n\n* [Youtube Demo Tutorial V1](https://youtu.be/EToFs-ysXKw)\n\n* [Youtube Demo V2](https://youtu.be/1IxtWgWxtlE)\n\n**oop 版本可參考 [line-bot refactor use oop (design pattern)](https://github.com/twtrubiks/line-bot-oop)，此版本為 functional programming。**\n\n## 執行畫面\n\n請先加入好友\n\n我的 QRCODE\n\n![alt tag](http://i.imgur.com/Kkpzt4p.jpg)\n\n或是手機直接點選 [https://line.me/R/ti/p/%40vbi2716y](https://line.me/R/ti/p/%40vbi2716y)\n\n![alt tag](http://i.imgur.com/oAgR5nr.jpg)\n\n認證記得請選 **同意**\n\n![alt tag](http://i.imgur.com/9LOlGHh.jpg)\n\n### 功能\n\n***精選功能***\n\n![alt tag](http://i.imgur.com/IB3hBl8.jpg)\n\n輸入任何文字即可開始玩\n\n![alt tag](http://i.imgur.com/M30GJOU.jpg)\n\n***開始玩***\n\n![alt tag](http://i.imgur.com/PCcnc5R.jpg)\n\n***新聞***\n\n![alt tag](http://i.imgur.com/mc0R0xL.jpg)\n\n#### 蘋果即時新聞\n\n apple news 即時新聞 ( 來源 [http://www.appledaily.com.tw/realtimenews/section/new/](http://www.appledaily.com.tw/realtimenews/section/new/) )\n\n![alt tag](http://i.imgur.com/OpJj9DE.png)\n\n#### 科技新報\n\n科技新報 ( Tech News ) 最新文章\n( 來源 [https://technews.tw/](https://technews.tw/) )\n\n![alt tag](http://i.imgur.com/H9YsDzP.png)\n\n#### PanX泛科技\n\nPanX泛科技 最新文章\n( 來源 [https://panx.asia/](https://panx.asia/) )\n\n![alt tag](http://i.imgur.com/07N2r9N.png)\n\n***電影***\n\n![alt tag](https://i.imgur.com/DQRUlV8.jpg)\n\n#### 近期上映電影\n\n近期上映的電影 ( 開眼電影網 )\n( 來源 [http://www.atmovies.com.tw/movie/next/0/](http://www.atmovies.com.tw/movie/next/0/) )\n\n![alt tag](http://i.imgur.com/hI3itad.png)\n\n#### eyny\n\neyny 電影版包含 Mega 以及 Google 標題的文章\n( 來源 [http://www.eyny.com/forum-205-1.html](http://www.eyny.com/forum-205-1.html) )\n\n![alt tag](http://i.imgur.com/rIGbmWA.jpg)\n\n#### 觸電網-youtube\n\n觸電網 ( youtube 預告 )\n\n![alt tag](https://i.imgur.com/FPw95Kf.jpg)\n\n***看廢文***\n\n![alt tag](http://i.imgur.com/GJI1BwG.jpg)\n\n#### 近期熱門廢文\n\n( 來源 [http://disp.cc/b/PttHot](http://disp.cc/b/PttHot) )\n\n![alt tag](http://i.imgur.com/Qm28Rso.png)\n\n#### 即時廢文\n\n即時八卦版廢文\n\n( 來源 [https://www.ptt.cc/bbs/Gossiping/index.html](https://www.ptt.cc/bbs/Gossiping/index.html) )\n\n![alt tag](http://i.imgur.com/B2YhFoS.png)\n\n***正妹***\n\n![alt tag](http://i.imgur.com/r6x8GzZ.jpg)\n\n#### PTT 表特版 近期大於 10 推的文章\n\n( 來源 [https://www.ptt.cc/bbs/Beauty/index.html](https://www.ptt.cc/bbs/Beauty/index.html) )\n\n![alt tag](http://i.imgur.com/N00kvip.png)\n\n#### 來張 imgur 正妹圖片\n\n( 來源 ，自己的  imgur ，透過官方 api  [imgurpython](https://github.com/Imgur/imgurpython) 回傳圖片  )\n\n![alt tag](http://i.imgur.com/dzTvo4z.png)\n\n#### 隨便來張正妹圖片\n\n( 來源 ，爬蟲 [auto_crawler_ptt_beauty_image](https://github.com/twtrubiks/auto_crawler_ptt_beauty_image)  ，從資料庫取出圖片)\n\n![alt tag](http://i.imgur.com/emQRbRb.png)\n\n***貼圖***\n\n如果傳任意貼圖，則會回傳任意有效貼圖 ( 目前我只有把官方 package_id 為 1 的 sticker_id 放在程式碼裡 )，\n\n相關的 sticker_id 以及 package_id 可參考官網的 [sticker_list.pdf](https://developers.line.me/media/messaging-api/sticker_list.pdf)。\n\n![alt tag](https://i.imgur.com/d6yaNBW.jpg)\n\n希望這個 **阿肥bot** 能帶給大家歡樂，程式碼很多基本上就是簡單的爬蟲。\n\n如果需要其他的功能，可以給小弟一點建議，我會盡量完成他。\n\n***油價查詢***\n\n![alt tag](https://i.imgur.com/pgwYGQe.png)\n\n***分享 bot***\n\n如果你想要分享你的 bot 給別人，可以使用 `https://line.me/R/nv/recommendOA/{LINE_id}` ，\n\n舉個例子，我的 bot 的 Line ID 為 `@vbi2716y`，所以我就可以寫成如下，\n\n`https://line.me/R/nv/recommendOA/@vbi2716y`\n\n![alt tag](https://i.imgur.com/jlOJ71S.png)\n\n更多說明可參考 [sharing-your-bot-account](https://developers.line.me/ja/docs/messaging-api/using-line-url-scheme/#sharing-your-bot-account)。\n\n## 教學\n\n請先到 [https://business.line.me/zh-hant/](https://business.line.me/zh-hant/) 這裡登入自己\n\n原本的 line 帳號，然後點選 Messaging API\n\n![alt tag](http://i.imgur.com/KIzExmQ.jpg)\n\n接下來你會看到 **開始使用Messaging API** 以及 **開始使用Developer Trial**\n\n在這裡我們選 **開始使用Messaging API**\n\n![alt tag](http://i.imgur.com/graLPrj.jpg)\n\n這兩個差別在哪裡呢? 可以到同一個頁面的下方觀看，基本上就只是方案不同而已\n\n![alt tag](http://i.imgur.com/bERbTGz.jpg)\n\n接著就是一些設定，點選 選擇公司/經營者\n\n![alt tag](http://i.imgur.com/d1pVdx9.jpg)\n\n點選 新增公司/經營者\n\n![alt tag](http://i.imgur.com/of23y7W.jpg)\n\n填寫一些資料\n\n![alt tag](http://i.imgur.com/7L9nulI.jpg)\n\nline bot 的 大頭貼 以及 名稱 設定\n\n![alt tag](http://i.imgur.com/7483ljT.jpg)\n\n![alt tag](http://i.imgur.com/a4Mf3Rl.jpg)\n\n設定完後，請選擇 申請\n\n![alt tag](http://i.imgur.com/Q6q8zGA.jpg)\n\n以上設定應該不會有什麼問題\n\n請選擇 開始使用 API\n\n![alt tag](http://i.imgur.com/DOEjH0F.jpg)\n\n請選擇 確認\n\n![alt tag](http://i.imgur.com/pKWBvsj.jpg)\n\n這些請注意，  選擇 **允許** ，然後記得 **儲存**\n\n![alt tag](http://i.imgur.com/Ofm9SeJ.jpg)\n\n點選 **Line Developers**\n\n![alt tag](http://i.imgur.com/cW9713h.jpg)\n\n你會進入下面這個畫面，在這個畫面中，有兩個東西很重要，分別是\n\n* Channel Secret\n\n* Channel Access Token\n\n***Channel Secret***\n\n![alt tag](http://i.imgur.com/jpIEMh4.jpg)\n\n***Channel Access Token***\n\n如果你看到的是空的，請點選 **ISSUE** 就會顯示了\n\n![alt tag](http://i.imgur.com/PcCEL4P.jpg)\n\n請將你的 **Channel Secret** 以及 **Channel Access Token**\n\n貼到 [config.ini](https://github.com/twtrubiks/line-bot-tutorial/blob/master/config.ini) 底下 ( 如不了解 .ini 的使用方法，可參考 [configparser_tutorial](https://github.com/twtrubiks/python-notes/tree/master/configparser_tutorial) )\n\n```ini\n[line_bot]\nChannel_Access_Token = YOUR_CHANNEL_SECRET\nChannel_Secret = YOUR_CHANNEL_SECRET\n```\n\n更多資訊可參考 [line-bot-sdk-python](https://github.com/line/line-bot-sdk-python)\n\n接下來因為 Line Bot 需要 SSL憑證 ( https )，所以我直接使用 [Heroku](https://dashboard.heroku.com/)\n\n如果不知道什麼是 [Heroku](https://dashboard.heroku.com/)  以及它的使用方法\n\n請參考我之前寫的 [Deploying-Flask-To-Heroku](https://github.com/twtrubiks/Deploying-Flask-To-Heroku)\n\n佈署\n\n![alt tag](http://i.imgur.com/kseRgxr.jpg)\n\n如上圖，我的網址是 [https://python-ine-bot.herokuapp.com/](https://python-ine-bot.herokuapp.com/)\n\n接著我們要加入 Webhook URL ，請點選 EDIT ，並且加入你自己的網址，網址格式\n\n```python\nhttps://{你的網址}/callback\n```\n\n舉例，我的網址就是\n\n```python\nhttps://python-ine-bot.herokuapp.com/callback\n```\n\n![alt tag](http://i.imgur.com/5ckn24T.jpg)\n\n![alt tag](http://i.imgur.com/TIjIM9W.jpg)\n\n輸入完之後，可以按 VERIFY ，如果你的 CODE 正確無誤，就會顯示 Success\n\n![alt tag](http://i.imgur.com/Mey5FKF.jpg)\n\n不過我使用 [line-bot-sdk-python](https://github.com/line/line-bot-sdk-python)當我按下 VERIFY，卻出現錯誤，不過是可以正常運作，所以暫時先不管他。\n\n![alt tag](http://i.imgur.com/wb0Qw5W.jpg)\n\n關於上述這個問題，可以到 [issues 2](https://github.com/twtrubiks/line-bot-tutorial/issues/2)\n以及 [issues 3](https://github.com/twtrubiks/line-bot-tutorial/issues/3) 觀看說明。( 感謝熱心的網友 )\n\n基本上到這裡就是完成了，趕快去加入自己的 line bot 玩玩看吧~\n\n只要我有新的想法，我會同步更新在這篇文章， line bot 還有很多好玩的地方\n\n## 使用 imgur 官方 api\n\n透過 imgur 官方 api  [imgurpython](https://github.com/Imgur/imgurpython) ,\n\n從自己的相簿隨機回傳一張正妹照片，\n\n請到下方獲取自己的 CLIENT_ID ,  CLIENT_SECRET  , 以及自己相簿的 album_id\n\n![alt tag](http://i.imgur.com/nQNQVD7.jpg)\n\n並將自己的資料輸入在下方程式碼\n\n```python\nclient_id = 'YOUR_IMGUR_CLIENT_ID'\nclient_secret = 'YOUR_IMGUR__CLIENT_SECRET'\nalbum_id = 'YOUR_IMGUR_ALBUM_ID'\n```\n\n更多詳細的介紹可參考 [imgurpython](https://github.com/Imgur/imgurpython)\n\n## 其他補充\n\n只要有使用到網址，請記得一定都要用 **https**\n\n舉例\n\n```pyhton\nimage_message = ImageSendMessage(\n            original_content_url=\"https://example.com.img1.jpg\",\n            preview_image_url=\"https://example.com.img1.jpg\"\n        )\n```\n\n## 設定選單\n\n有一些東西是必須到 line 的官網去設定的，像是下方的選單\n\n![alt tag](http://i.imgur.com/IB3hBl8.jpg)\n\n請到 [https://admin-official.line.me/](https://admin-official.line.me/) 選擇自己的 bot ，然後開始設定，\n\n建立圖片影音內容 -\u003e 圖文訊息選單 ( 如下圖 )\n\n![alt tag](http://i.imgur.com/igKd6Og.png)\n\n顯示設定，請選擇 ***反映***，不然會沒有效果\n\n![alt tag](http://i.imgur.com/pEHSxUH.png)\n\n接著選擇樣式，\n\n記得，***選單內容設定*** 全部都要設定，不然會沒有效果\n\n![alt tag](http://i.imgur.com/u0bzYu7.png)\n\n最後，那個主要兩個字非常礙眼 ( 如下圖 )\n\n![alt tag](http://i.imgur.com/Lv3BMyz.jpg)\n\n我們可以從這裡把它關掉\n\n帳號設定 -\u003e 基本設定\n\n![alt tag](http://i.imgur.com/bwjWijG.png)\n\n將 行動官網選單 設定為 隱藏 即可\n\n![alt tag](http://i.imgur.com/Q1qvjTT.png)\n\n## Heroku 注意事項\n\n有些人可能會遇到佈署失敗的問題，可以試著將 [runtime.txt](https://github.com/twtrubiks/line-bot-tutorial/blob/master/runtime.txt) 修改為 3.9.13\n\n( 這個只要依照提示更新就行了 )\n\n如果遇到 Upgrading to the Latest Stack，只需要到 Heroku 上修正後，重新佈署即可，可參考\n\n[Upgrading to the Latest Stack](https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack) 以及 [Stacks](https://devcenter.heroku.com/articles/stack),\n\n更新 stack 指令\n\n`heroku stack:set heroku-22 -a \u003capp name\u003e`\n\n之後再 commit push 一次就會自動 migrate 到新的 stack.\n\n因為 gunicorn 的更新，現在需要將 [Procfile](https://github.com/twtrubiks/line-bot-tutorial/blob/master/Procfile) 多加上 `--preload`，也就是變成\n\n```Procfile\nweb gunicorn app:app --preload\n```\n\n詳細可參考\n[Advanced configuration](https://devcenter.heroku.com/articles/python-gunicorn#advanced-configuration)。\n\n## 執行環境\n\n* Python 3.12\n\n## Reference\n\n* [line messaging-api](https://devdocs.line.me/en/#messaging-api)\n* [line-bot-sdk-python](https://github.com/line/line-bot-sdk-python)\n* [imgurpython](https://github.com/Imgur/imgurpython)\n\n## Donation\n\n文章都是我自己研究內化後原創，如果有幫助到您，也想鼓勵我的話，歡迎請我喝一杯咖啡:laughing:\n\n![alt tag](https://i.imgur.com/LRct9xa.png)\n\n[贊助者付款](https://payment.opay.tw/Broadcaster/Donate/9E47FDEF85ABE383A0F5FC6A218606F8)\n\n## License\n\nMIT license\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fline-bot-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwtrubiks%2Fline-bot-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwtrubiks%2Fline-bot-tutorial/lists"}