Draw your telegram bot in draw.io and generate its code

Overview

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. 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 save users answers to a document using save_answers standard function.

Upcoming features

  • Using user answers into message blocks
  • New type of functions with string outcome (now only True and False outcomes available)
You might also like...
An Telegram Bot By @AsmSafone To Stream Videos in Telegram Voice Chat. This is Also The Source Code of The Bot Which is Being Used In @SafoTheBot Group! ❤️

Telegram Video Player Bot (Beta) An Telegram Bot By @AsmSafone To Stream Videos in Telegram Voice Chat. Special Features Supports Live Streaming From

A Telegram Repo For Devs To Controll The Bots Under Maintenance.This Bot Is For Developers, If Your Bot Is Down, Use This Repo To Give Your Dear Subscribers Some Support By Providing Them Response.
A Telegram Repo For Devs To Controll The Bots Under Maintenance.This Bot Is For Developers, If Your Bot Is Down, Use This Repo To Give Your Dear Subscribers Some Support By Providing Them Response.

Maintenance Bot A Telegram Repo For Devs To Controll The Bots Under Maintenance About This Bot This Bot Is For Developers, If Your Bot Is Down, Use Th

A Telegram Repo For Devs To Controll The Bots Under Maintenance.This Bot Is For Developers, If Your Bot Is Down, Use This Repo To Give Your Dear Subscribers Some Support By Providing Them Response.
A Telegram Repo For Devs To Controll The Bots Under Maintenance.This Bot Is For Developers, If Your Bot Is Down, Use This Repo To Give Your Dear Subscribers Some Support By Providing Them Response.

Maintenance Bot A Telegram Repo For Devs To Controll The Bots Under Maintenance About This Bot This Bot Is For Developers, If Your Bot Is Down, Use Th

Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & runs for 24x7 hours.
Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & runs for 24x7 hours.

PowerfulBotStatus-IDN-C-X Easy & powerful bot to check if your all Telegram bots are working or not. This bot status bot updates every 45 minutes & ru

A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.
A simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statistical tables and plots to users as Telegram messages.

telegram-stats-bot Telegram-stats-bot is a simple bot that lives in your Telegram group, logging messages to a Postgresql database and serving statist

Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API.

Tg_PHub_Bot Telegram PHub Bot using ARQ Api and Pyrogram. This Bot can Download and Send PHub HQ videos in Telegram using ARQ API. OS Support All linu

Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features! 🥰
Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features! 🥰

CallMusicPlus69 This Repo base on! 🤗️ A CallsMusic Based Telegram Bot and Userbot To Play Music in Your Telegram Groups With Some Cool Extra Features

Asad Alexa VC Bot Is A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group.
Asad Alexa VC Bot Is A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group.

Asad Alexa VC Bot Is A Telegram Bot Project That's Allow You To Play Audio And Video Music On Telegram Voice Chat Group.

A telegram bot script for generating session string using pyrogram and telethon on Telegram bot

String-session-Bot Telegram Bot to generate Pyrogram and Telethon String Session. A star ⭐ from you means a lot to us! Usage Deploy to Heroku Tap on a

Owner
DENIS TSITKO
DENIS TSITKO
null 1 Feb 18, 2022
This is telegram bot to generate string session for using user bots. You can see live bot in https://telegram.dog/string_session_Nsbot

TG String Session Generate Pyrogram String Session Using this bot. Demo Bot: Configs: API_HASH Get from Here. API_ID Get from Here. BOT_TOKEN Telegram

Anonymous 27 Oct 28, 2022
ANKIT-OS/STYLISH-TEXT is a special repository. Its Is A Telegram Bot Which Can Translate Your Text Into 100+ Language

?? ᴳᴼᴼᴳᴸᴱ⁻ᵀᴿᴬᴺᔆᴸᴬᵀᴱᴿ ?? The owner would not be responsible for any kind of bans due to the bot. • ⚡ INSTALLING ⚡ • • ??️ Lᴀɴɢᴜᴀɢᴇs Aɴᴅ Tᴏᴏʟs ?? • If

ANKIT KUMAR 1 Dec 23, 2021
(@Tablada32BOT is my bot in twitter) This is a simple bot, its main and only function is to reply to tweets where they mention their bot with their @

Remember If you are going to host your twitter bot on a page where they can read your code, I recommend that you create an .env file and put your twit

null 3 Jun 4, 2021
A Telegram Bot to generate permanent Stream and Download links for any Telegram file

Telegram File To Stream Link This bot will give you permanent Stream and Download links for Telegram files Deploy the Bot Press the below button to de

Shadow 80 Dec 16, 2022
Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

Telegram VCVideoPlayBot An Telegram Bot By @ZauteKm To Stream Videos in Telegram Voice Chat. NOTE: Make sure you have started a VoiceChat in your Grou

Zaute 20 Oct 21, 2022
Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

Telegram bot to stream videos in telegram voicechat for both groups and channels. Supports live strams, YouTube videos and telegram media.

SUBIN 449 Dec 27, 2022
Its Is A Telegram Maths Basic Calculator Bot

Its Is A Telegram Maths Basic Calculator Bot

ANKIT KUMAR 1 Dec 26, 2021
ANKIT-OS/TG-MUSIC-PLAYER a special repository. Its Is A Telegram Bot To Play To Play Music In Voice Chat

?? ?? TG MUSIC PLAYER ?? ?? The owner would not be responsible for any kind of bans due to the bot. • ⚡ INSTALLING ⚡ • • ??️ Lᴀɴɢᴜᴀɢᴇs Aɴᴅ Tᴏᴏʟs ?? •

ANKIT KUMAR 1 Dec 27, 2021