第一步:將昨天下載完的壓縮檔解壓縮,取出line-bot-sdk-python-master\examples中的flask-echo資料夾將其中資料和Linebot資料夾轉移至我們創立的資料夾
第二步:編輯app.py
更改紅框內的內容將其改成在LINE提供的channel_secret和channel_access_token(可於LINE Developer尋找),於def callback副程式內加上print(body)
將flask,future,requests, line_bot_sdk,gunicorn, psycopg這些字串放入requirements.txt檔裡面讓Heroku記得下載
第三步:回到CMD
PS F:\課業\juclinebot\juctest> heroku login
» Warning: heroku update available from 7.53.0 to 7.56.1.
heroku: Press any key to open up the browser to login or q to exit:
Opening browser to https://cli-auth.heroku.com/auth/cli/browser/acc9faa8-807c-49c3-aad3-df1f897d13c3?requestor=SFMyNTY.g2gDbQAAAA4xMTguMTUwLjEyNS42NG4GADCf_Qp8AWIAAVGA.UxxAOnDfwa6LFXrKpiyhZzod7g7PE1m94BbzcfUJioY
Logging in... done
Logged in as juc097676907@gmail.com
PS F:\課業\juclinebot\juctest>
PS F:\課業\juclinebot\juctest> heroku git:remote -a juctest
» Warning: heroku update available from 7.53.0 to 7.56.1.
set git remote heroku to https://git.heroku.com/juctest.git
PS F:\課業\juclinebot\juctest> git init
PS F:\課業\juclinebot\juctest> git add .
PS F:\課業\juclinebot\juctest> git commit -am'ok'
[master 8ede0b8] ok
Committer: cscs020 <rusa020@easybuy3c.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+), 1 deletion(-)
PS F:\課業\juclinebot\juctest> git push heroku master
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 390 bytes | 390.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/python
remote: -----> Python app detected
remote: -----> No Python version was specified. Using the same version as the last build: python-3.9.6
remote: To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
remote: ! Python has released a security update! Please consider upgrading to python-3.9.7
remote: Learn More: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> No change in requirements detected, installing from cache
remote: -----> Using cached install of python-3.9.6
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: -----> Discovering process types
remote: Procfile declares types -> web
remote:
remote: -----> Compressing...
remote: Done: 57.6M
remote: -----> Launching...
remote: Released v76
remote: https://juctest.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/juctest.git
a14adf9..8ede0b8 master -> master
第四步:回到LINE Developer更改webhook
改成https://{hereku專案名}.herokuapp.com/callback
將Use webhook打開,關閉Auto-reply messages 。
第五步:拿起LINE掃描QRcode將機器人加入好友並傳送訊息
成功QAQ
參考資料:
LINE Bot聊天機器人程式開發教學(二):註冊與設定Heroku平台應用程式 - 超圖解系列圖書
使用 Heroku 建立範例聊天機器人 | LINE Developers
LineBot+Python,輕鬆建立聊天機器人 | BlackMaple's Blog
(376) 【Maso的萬事屋】10分鐘用Python做LineBot聊天機器人|程式設計 - YouTube