petermouse / TOC-Project-2017

TOC Project 2017 - Telegram Bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TOC Project 2017

A telegram bot based on a finite state machine

This telegram bot contains three features:

  1. Search for uniform-invoice prize winning numbers
  2. Search for newest articles in PTT website
  3. Search for vocabulary in English-Chinese(Traditional) dictionary

Setup

Prerequisite

  • Python 3

Install Dependency

Simply use pip3 command to install from the requirements file

pip3 install -r requirements.txt

Below is the list of required packages:

  • Flask
  • transitions
  • pygraphviz (For visualizing Finite State Machine)
  • python-telegram-bot
  • requests (For HTTP requests)
  • beautifulsoup4 (For pulling out data from HTML files)

Secret Data

API_TOKEN and WEBHOOK_URL in app.py MUST be set to proper values. Otherwise, you might not be able to run your code.

You can get API_TOKEN from @botfather (web link)

Run Locally

You can either setup https server or using ngrok as a proxy.

ngrok would be used in the following instruction

(or run the executable file with same arguments)

ngrok http 5000

After that, ngrok would generate a https URL.

You should set WEBHOOK_URL (line 11 in app.py) to your-https-URL/hook.

Run the server

python3 app.py

Finite State Machine

fsm

Usage

The initial state is set to init.

There has three branches leave from init. These branches correspond to different features memtioned above.

If the user entered "1", "2" or "3", init is triggered to advance to the corresponding state, and telegram bot will ask for more details in order to retrive data the user want

Finally, if the result has sent to the user, states will go_back to init state

Snapshots

Sequence of actions started from typing "1" at init state snapshot-1

Sequence of actions started from typing "2" at init state snapshot-2

Sequence of actions started from typing "3" at init state snapshot-3

Author

petermouse

The project template is provided by Lee-W

About

TOC Project 2017 - Telegram Bot

License:MIT License


Languages

Language:Python 100.0%