Bots for the quiz¶
This repository contains Vkontakte and Telegram chatbots for the quiz.
Features¶
Questions are taken from text files located in the specified folder;
The database is stored in cloud Redis;
The user has an unlimited number of attempts to answer the question;
The user can surrender. After he gets the correct answer and the next question.
How to install¶
Copy the scripts to your computer:
git clone https://github.com/eskelevir/quiz-bot.git
Go to the folder:
cd quiz-bot
Install the required python packages:
Python3 should be already installed. Then use pip (or pip3, if there is a conflict with Python2) to install dependencies:
pip install -r requirements.txt
Remember, it is recommended to use virtualenv/venv for better isolation.
Create a folder for quiz content and extract the archive into it ;
Get the necessary data to work with Vkontakte and Telegram (link);
Create and configure Telegram bot to receive notifications (link);
Get the necessary data to work with Redis (link);
Create the file. env and record the received data:
QUIZ_FOLDER_PATH=the path to the folder with text files with material for the quiz TG_TOKEN=Telegram bot token VK_TOKEN=Vkontakte bot token TG_LOGGER_BOT_TOKEN=Telegram logger bot token TG_LOGGER_BOT_CHAT_ID=Telegram logger chat id REDIS_ENDPOINT=url db REDIS_DB_PASSWORD=Redis database password
Project Goals¶
The code is written for educational purposes on online-course for web-developers dvmn.org.
Notification¶
Telegram bot¶
- Create a Telegram bot using BotFather and Get the Api Token:
Open Telegram;
Search @ botfather;
Type /newbot;
It will show “Alright, a new bot. How are we going to call it? Please choose a name for your bot.”;
Type the name of your bot;
After, it’ll show “Good. Now let’s choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.”;
You’ve to give a unique username and it should be ending with bot;
After giving the name it’ll show :
“Done! Congratulations on your new bot. You will find it at t.me/[your_name_bot]. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you’ve finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.”
Use this token to access the HTTP API: “TOKEN”.
Receive the chat_id. To do this, write to the Telegram special bot: @userinfobot.
Social network data¶
Vkontakte¶
Get the token group
Allow sending messages
Telegram¶
Create a bot in Telegram, get the API key of the bot. The bot will become the channel administrator (instruction);
chat_id of the channel is a link to it, for example: @coolchannel.