Skip to content

JohnnyFoxChang/LINE-subscribe-open-data-bot

 
 

Repository files navigation

Subscribe open data with LINE Bot/Notify/LIFF

License: MIT Python Version

The bot provides subscribing and notifying open data - air pollution.

Using 所有縣市 trigger and start bot.

It builds by:

  • flask/Python 3.8
  • LINE v10.12
  • LINE Notify
  • LINE Login/LIFF v2.3
  • Sqlite

You need Github, LINE, Heroku accounts to deploy this bot.

Developer Side

Environment property

These properties are need to export in environment.

LINE_CHANNEL_ACCESS_TOKEN=
LINE_CHANNEL_SECRET=
LINE_NOTIFY_CLIENT_ID=
LINE_NOTIFY_CLIENT_SECRET=
LINE_NOTIFY_REDIRECT_URI=
LIFF_BIND_ID=
LIFF_CONFIRM_ID=
DATABASE_URL=postgres://USER:PASSWORD@127.0.0.1:5432/postgres

LINE account (LINE_CHANNEL_ACCESS_TOKEN, LINE_CHANNEL_SECRET)

  • Got A LINE Bot API developer account Make sure you already registered, if you need use LINE Bot.
  • Go to LINE Developer Console
    • Close auto-reply setting on "Messaging API" Tab.
    • Setup your basic account information. Here is some info you will need to know.
      • Callback URL: https://{YOUR_URL}/webhooks/line
      • Verify your webhook.
  • You will get following info, need fill back to .env file.
    • Channel Secret
    • Channel Access Token (You need to issue one here)

LIFF (LIFF_BIND_ID & LIFF_CONFIRM_ID)

  • Input https://{YOUR_URL}/notify into binding LIFF app.
  • Input https://{YOUR_URL}/notify/callback into callback LIFF app.

LINE notify

  • Input your key into LINE_NOTIFY_CLIENT_ID and LINE_NOTIFY_CLIENT_SECRET

  • Copy callback LIFF app url to NOTIFY callback url column.

Local testing

  1. first terminal window
cp .env.sample .env
pip install -r requirements.txt --user
python api.py
  1. Create a provisional Https:
ngrok http 5000

or maybe you have npm environment:

npx ngrok http 5000

  1. Copy url to LINE Developer Console

Heroku

Deploy

Click Configure Add-ons and input Heroku Scheduler to install scheduler.

  • Add two jobs on Heroku Schedular:

    • python scripts/sync_to_sql.py
    • python scripts/notify_me.py
  • Add Heroku Postgres and it would create DATABASE_URL environment variable automatically.

If you are not sure where are files in, use following up commands:

heroku run bash
heroku logs --tail

License

MIT License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 86.3%
  • HTML 13.7%