Menu

Tree [85c96d] main /
 History

HTTPS access


File Date Author Commit
 bots 2021-04-21 DENIS TSITKO DENIS TSITKO [ea67f2] save_answers function corrected
 examples 2021-04-25 DENIS TSITKO DENIS TSITKO [85c96d] using user answers in message blocks
 images 2021-04-21 DENIS TSITKO DENIS TSITKO [da4344] screenshots
 templates 2021-04-20 DENIS TSITKO DENIS TSITKO [2114fe] version 1.0
 BotStructure.py 2021-04-20 DENIS TSITKO DENIS TSITKO [90c562] Add files via upload
 LICENSE.txt 2021-04-20 DENIS TSITKO DENIS TSITKO [90c562] Add files via upload
 README.md 2021-04-25 DENIS TSITKO DENIS TSITKO [85c96d] using user answers in message blocks
 drawyourbot.py 2021-04-25 DENIS TSITKO DENIS TSITKO [85c96d] using user answers in message blocks
 project_demo.gif 2021-04-21 DENIS TSITKO DENIS TSITKO [d70d60] project demo
 project_demo.mp4 2021-04-21 DENIS TSITKO DENIS TSITKO [e0f350] Create project_demo.mp4
 requirements.txt 2021-04-20 DENIS TSITKO DENIS TSITKO [90c562] Add files via upload

Read Me

README start point

project demo

Contents:

Draw your bot

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.

Install requirements

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

Registering a telegram bot

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

Drawing a bot

As you registered your bot and got its token, you need to draw your bot logic in draw.io.

Start point

Your bot should have exactly one start point. That is a circle or ellipse with your bot token as label:
start point
Your start point should have exactly one arrow.

Message block

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 with name

Message without name example:
message with name

Single choice block

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:
single choice

And in your bot like that:
single choice in bot

Functions block

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:
functions block

Generating bot code

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

Custom classes

Arrow

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

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

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

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

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

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

BotCode class initializing with BotStructure object. It generates bot code (make_bot() function) and writes that code
into file (write_code() function).

Standard functions

contains

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).

save_answers

Saves all users answers into file.
Takes answers keyword and the name of the file where it should save answers.

Examples

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

New features

Now you can use user answers into message blocks

Upcoming features

  • New type of functions with string outcome (now only True and False outcomes available)
  • New standard function to search through md documents