File | Date | Author | Commit |
---|---|---|---|
bots | 2021-04-21 | DENIS TSITKO | [ea67f2] save_answers function corrected |
examples | 2021-04-25 | DENIS TSITKO | [85c96d] using user answers in message blocks |
images | 2021-04-21 | DENIS TSITKO | [da4344] screenshots |
templates | 2021-04-20 | DENIS TSITKO | [2114fe] version 1.0 |
BotStructure.py | 2021-04-20 | DENIS TSITKO | [90c562] Add files via upload |
LICENSE.txt | 2021-04-20 | DENIS TSITKO | [90c562] Add files via upload |
README.md | 2021-04-25 | DENIS TSITKO | [85c96d] using user answers in message blocks |
drawyourbot.py | 2021-04-25 | DENIS TSITKO | [85c96d] using user answers in message blocks |
project_demo.gif | 2021-04-21 | DENIS TSITKO | [d70d60] project demo |
project_demo.mp4 | 2021-04-21 | DENIS TSITKO | [e0f350] Create project_demo.mp4 |
requirements.txt | 2021-04-20 | DENIS TSITKO | [90c562] Add files via upload |
Contents:
Draw your bot is an open sourced project made to let people construct chat bots without coding or with minimal coding.
You can just draw your chat bot logic in draw.io and generate its code.
This project will be most useful for those who need to make simple support or survey bot.
It could also save some time for those who are building really complex bots. In that cases generated bot can be
just a start point.
First you need to install requirements from requirements.txt.
The only requirement is python-telegram-bot library.
To install the requirements just use the following command:
python -m pip install -r requirements.txt --user
Now you need to register your bot in telegram and get its token. You can register your bot using /newbot command in
botfather telegram bot.
Here are the instructions
As you registered your bot and got its token, you need to draw your bot logic in draw.io.
Your bot should have exactly one start point. That is a circle or ellipse with your bot token as label:
Your start point should have exactly one arrow.
There are two types of messages: with name (that message will wait for users answer and you will be able to use that
answer in your functions blocks and without name (that is just a text message which bot will print out).
Both are drawing as rectangle and should not have more when one outgoing arrow. Name of the message should be in
square brackets at the beginning of blocks label.
You can use users answers in your message blocks. To use the answer, you need to add __block name__ into your
message block (the example is an echo_bot in examples folder).
Message with name example:
Message without name example:
For single choice block you should use rhombus. It should always have name and each outgoing line should have label
which will be options in your bot.
On your draw it will looks like that:
And in your bot like that:
You can use functions in your bot. There are some useful functions in standardfuncs.py and you can make your own file
with functions.
All functions should have exactly two outcomes: True and False.
You can use answers to your named message blocks and single choice blocks by providing blocks name to functions and
you can use all answers by providing answers keyword to your functions. And you can also use any other hardcoded
parameters (for strings you should use quotes).
Function should start with _functions_ keyword and contain the name of python file with your functions (without
extension) and function name with its parameters.
Example: _functions_fileWithFunctions::function(argument1, argument2, "string1", "string2")
In your draw it will looks like that:
To generate your bot code use the following command:
python drawyourbot.py path_to_your_drawio_file
Your bot will be saved to bots path. To run it use the following command:
python path_to_your_bot_file
Arrow is a class for arrows.
It have the following attributes:
- id: string (arrow id)
- source: string (source element id)
- target: string (target element id)
- label: string (arrow label)
- target_element: Message, SingleChoice or FunctionsBlock (the target element for the arrow)
Start is a class for start point.
It have the following attributes:
- id: string (start element id)
- label: string (start element label, which should be your telegram bot token)
- arrow: Arrow (start points outgoing arrow)
Message is a class for message blocks.
It have the following attributes:
- id: string (message block id)
- label: string (message text)
- name: string (message block name)
- arrow: Arrow (message block outgoing arrow)
- type: string (always "message")
SingleChoice is a class for single choice blocks.
It have the following attributes:
- id: string (single choice block id)
- label: string (single choice text)
- name: string (single choice block name)
- arrows: list of Arrow (single choice block outgoing arrows)
- type: string (always "single choice")
FunctionsBlock is a class for functions blocks.
It have the following attributes:
- id: string (functions block id)
- library: string (file with function)
- function: string (function with arguments)
- name: string (function name)
- function_args: string (function arguments in one string)
- arrows: list of arrow (functions block outgoing arrows)
- type: string (always "functions block")
BotStructure class is initializing with the path to drawio file and loads its structure.
It have the following attributes:
- root: xml.etree.ElementTree (xml with bot structure)
- errors: string (errors in bot structure drawio)
- arrows: list of Arrow (arrows from drawio)
- start: Start (start point)
- messages: list of Message (message blocks)
- functions_blocks: list of FunctionsBlock (function blocks)
- single_choice_blocks: list of SingleChoice (single choice blocks)
BotCode class initializing with BotStructure object. It generates bot code (make_bot() function) and writes that code
into file (write_code() function).
Checks if first argument contains all of other arguments.
All arguments should be strings (it could be the names of message and single choice blocks - in that case function will
check users answers to those blocks).
Saves all users answers into file.
Takes answers keyword and the name of the file where it should save answers.
To generate a bot from drawio file in examples folder you need to open it in draw.io and change "bot_token" on start point to your
bots token.
After that just use the following command:
python drawyourbot.py examples/drawio_file_name.drawio
Your bot will be saved into bots. You can run it with the following command:
python bots/drawio_file_name.py
Now you can use user answers into message blocks