Bot follow scenario for ordering tickets through vk.com.
Bot supports commands:
- '/t', '/ticket', 'заказ', 'регистрация', '1' — start scenario;
- '/h', '/help', 'помощь', '2' — instruction about the work of the bot.
Script steps:
- Entering the city of departure. Checking a city using regular expression, suggest a city where we can fly
- Entering the destination city. Checking a city using regular expression, suggest a city where we can fly
* If there is no flight between the selected cities, we text about it and complete the scenario. - Entering the date: we ask the user for the departure date in the YYYY-mm-dd format.
- Selecting a flight. With the help of the dispatcher, we offer 5 flights closest to the selected date, indicating their numbers and ask enter the number you like.
- Specify the number of places (from 1 to 5).
- Suggest writing a comment in any form.
- Clarify the entered data.
- Request a phone number.
- Inform user that he will be contacted by the entered number.
If a command (/ ticket or / help) is entered during a script, the script stops and the command is executed.
Pytnon: pytnon 3.8.5
APIs:
- https://avatars.dicebear.com API for creating a unique user avatar
- Yandex API for getting flight schedules and checking for flights between cities
- Travelpayouts API for autocomplete city if the user made a mistake or did not enter it completely
Libs:
- vk_api (wrapper vk.com API)
- requests
- Pillow
- cairosvg
- re
- unittest
- logging
- coverage
- pony ORM
- Make dir and jump into it
$mkdir vk_chat_bot && cd vk_chat_bot
- Clone repository
git clone https://github.com/toohottostop/vk_chat_bot.git
- Install virtual environment package
$sudo apt install python3-virtualenv
Set your virtual environment package
$python3 -m virtualenv <name_of_virtualenv>
Activate virtual environment
$source <name_of_virtualenv>/bin/activate
- Install requirements
pip install -r requirements.txt
- Set your vk token -
TOKEN
, vk group id -GROUP_ID
, yandex API token -YANDEX_KEY
insettings.py
- Set your data base in
settings.py
(in project I used Postgres, but you can choose another one)
DB_CONFIG = dict(provider='', user='', password='', host='', database='' )
- Run tests
python -m unittest tests.py
python chat_bot.py
chat_bot.py
- 72%