Mosquito Man Line Bot
Line Bot that provides information about dengue fever.
Including the following functionality
- Basic Dengue Fever Knowledge
- Real Time Epidemic Information
- Nearby Hospital
Add this bot
- line id: @mosquitoman
- QR Code
QR code
Clone This Project
git clone --recursive https://github.com/NCKU-CCS/line_bot_serverPre requirements
- Python 3
- pipenv
- pygraphviz (For visualizing Finite State Machine)
- postgres (Database)
# mac
brew install postgresql
# ubuntu
sudo apt-get install postgresql postgresql-contrib
- postgis (Database)
- redis (In Memeory Database)
# mac
brew install redis
# ubuntu
sudo apt-get install redis-serverInstall Dependency
pipenv installSetup
Use Different Setting Files
Currently this repo tracks only denguefever_tw/denguefever_tw/settings/productions.py
All other setting files should be defined under denguefever_tw/denguefever_tw/settings/
Use the following command to setup or change Django settings
export DJANGO_SETTINGS_MODULE="denguefever_tw.settings.your_setting_file"Change your_setting_file to corresponding file
e.g. export DJANGO_SETTINGS_MODULE="denguefever_tw.settings.production"
Prodcution
All the sensitive data are not versioned and should be configured by the environment variables.
The variables needed including
DJANGO_SECRET_KEY(loaded asSECRET_KEY)LINE_CHANNEL_SECRETLINE_CHANNEL_ACCESS_TOKENPOSTGRESQL_NAMEPOSTGRESQL_USERPOSTGRESQL_PASSWORDPOSTGRESQL_HOSTPOSTGRESQL_PORTIMGUR_CLIENT_IDCHROME_DRIVER_PATH
Develop
When developing, you should define your own local.py under settings/.
This file will be and should be ignored by git.
You should import base.py first.
from .base import *Then, set up the following variables
SECRET_KEYDATABASESLINE_CHANNEL_SECRETLINE_CHANNEL_ACCESS_TOKENIMGUR_CLIENT_IDCHROME_DRIVER_PATH
e.g.
from .base import *
SECRET_KEY = 'This is the secret key'
LINE_CHANNEL_SECRET = 'This is your Line channel secret'
LINE_CHANNEL_ACCESS_TOKEN = 'This is your Line access token'
IMGUR_CLIENT_ID = 'This is your client id of Imgur application'
CHROME_DRIVER_PATH = 'This is path of your Chrome browser driver'
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pwd',
'HOST': 'localhost',
'PORT': '',
},
'tainan': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_pwd',
'HOST': 'localhost',
'PORT': '',
},
}Database
Currently postgis is used with one default db and one tainan db.
default: Store all data other than Tainan hospital datatainan: Store Tainan hospital data
Start postgresql
# mac
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log startImport Hospital Data
Import tainan hosptial data
python manage.py import_dengue_hospitalImport Tainan Minimum Area Data
python manage.py import_tainan_minareaCache
Cache is used to store user state.
Currently redis server is used
Start Redis
redis-serverLogger (Optional But Recommended)
- loggers
django: global loggingdengue_linebot.denguebot_fsm: FSM logging including all the conditional judgements and operation processes
e.g.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s:%(asctime)s:%(module)s:%(process)d:%(thread)d\n%(message)s'
},
'simple': {
'format': '%(levelname)s\n%(message)s'
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'verbose',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'level': 'INFO',
},
'dengue_linebot.denguebot_fsm': {
'handlers': ['console'],
'level': 'INFO',
}
},
}More detail on Logging System in django
Usage
Run uwsgi
Start
sudo uwsgi --ini server-setting/linebot.ini --touch-reload=`pwd`/server-setting/linebot.iniStop
sudo killall -s INT uwsgiRealod
touch server-setting/linebot.iniRestart
sudo killall -s INT uwsgi
sudo uwsgi --ini server-setting/linebot.ini --touch-reload=`pwd`/server-setting/linebot.iniView Log
sudo tail -f /var/log/bot_denguefever_daemon.logConfigration
Under denguefever_tw/denguefever_tw/static/dengue_bot_config
FSM.json: Finite state machinedengue_msg.json: Static Messages
Setup callback URL on LINE
Add https://Your Domain Name/callback/ to Webhook URL on your LINE Developer page.
License
Copyright (c) NCKU The Mosquito Man Project. All rights reserved.
Licensed under the MIT License.