Support bot for Game of Verbs with DialogueFlow at its core
See for yourself:
Python should already be installed. This project is tested on Python 3.11. You may use other versions as you will, but YMMV.
Clone the repo / download code
Using virtual environment virtualenv/venv is recommended for project isolation.
Install requirements:
pip install -r requirements.txt
Set up environmental variables.
Create .env
file in root folder and write down the following variables:
TELEGRAM_BOT_TOKEN
- Access token of your bot. You get one from BotFather Telegram bot when you create a bot.TELEGRAM_LOGGING_BOT_TOKEN
- same as above, but used for sending logs. Can be the same bot or separate as the main one.VK_GROUP_TOKEN
- Access token of your VK group. Get it from the group's settings.PROJECT_ID
- Google Cloud project's IDGOOGLE_APPLICATION_CREDENTIALS
- Filepath tocredentials.json
of your Google Cloud project. See below how to get it.DIALOG_FLOW_API_KEY
- DialogueFlow's access token. See below how to get it.LOGGING_LEVEL
- Desired logging levelTELEGRAM_USER_ID
- Your numeric Telegram ID. Can be checked by writing to special user info bot. Used to recieve logs.
To work with DialogueFlow, you'll need a Google Cloud project and a DialogueFlow project. Follow the article above to set everything up, but the main points are:
- Make a Google Cloud project (or select an existing one)
- Make sure DialogFlow's API is enabled
- Make a DialogueFlow project, write your Google Cloud's project ID into appropriate field in DF's settings
- Use Google Cloud CLI to authenticate and create
credentials.json
file - Create DialogueFlow API key, using instructions
To create API key use a helper script create_api_key.py
python create_api_key.py your_key_name
For details and options see the official instructions
For DialogueFlow to be able to respond to users' messages it must be taught intents. While it can be done manually in DF project's dashboard, you can use create_intent.py
script if you have a JSON file with training phrases
JSON file's structure should like this:
{
"Name of the intent": {
"questions": [
"User expression 1",
"User expression 2",
"User expression 3",
"..."
],
"answer": "Text of the answer"
}
}
In this case run the script create_intent.py
:
python create_intent.py filepath/to/phrases/file.json
Telegram and VK bots are separate and should be launched by executing telegram_bot.py
and vk_bot.py
python telegram_bot.py # launches Telegram bot
python vk_bot.py # launches VK bot
For Telegram bot to be able to send messages, send it a /start
command
The code is written for educational purposes on online-course for web-developers dvmn.org.