Git Product home page Git Product logo

line_bot_server's Introduction

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_server

Pre requirements

# mac
brew install postgresql

# ubuntu
sudo apt-get install postgresql postgresql-contrib
# mac
brew install redis

# ubuntu
sudo apt-get install redis-server

Install Dependency

pipenv install

Setup

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 as SECRET_KEY)
  • LINE_CHANNEL_SECRET
  • LINE_CHANNEL_ACCESS_TOKEN
  • POSTGRESQL_NAME
  • POSTGRESQL_USER
  • POSTGRESQL_PASSWORD
  • POSTGRESQL_HOST
  • POSTGRESQL_PORT
  • IMGUR_CLIENT_ID
  • CHROME_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_KEY
  • DATABASES
  • LINE_CHANNEL_SECRET
  • LINE_CHANNEL_ACCESS_TOKEN
  • IMGUR_CLIENT_ID
  • CHROME_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 data
  • tainan: Store Tainan hospital data

Start postgresql

# mac
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Import Hospital Data

Import tainan hosptial data

python manage.py import_dengue_hospital

Import Tainan Minimum Area Data

python manage.py import_tainan_minarea

Cache

Cache is used to store user state.
Currently redis server is used

Start Redis

redis-server

Logger (Optional But Recommended)

  • loggers
    • django: global logging
    • dengue_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.ini

Stop

sudo killall -s INT uwsgi

Realod

touch server-setting/linebot.ini

Restart

sudo killall -s INT uwsgi
sudo uwsgi --ini server-setting/linebot.ini --touch-reload=`pwd`/server-setting/linebot.ini

View Log

sudo tail -f /var/log/bot_denguefever_daemon.log

Configration

Under denguefever_tw/denguefever_tw/static/dengue_bot_config

  • FSM.json: Finite state machine
  • dengue_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.

line_bot_server's People

Contributors

dependabot[bot] avatar lee-w avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.