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)
Owner
DENIS TSITKO
DENIS TSITKO
A free and open-source SMS/Call bombing application

TBOMB V0.1 A free and open-source SMS/Call bombing application NOTE: For Termux To use the bomber type the following commands in Termux: pkg install g

ᴀɴᴋɪᴛ ᴋᴜᴍᴀʀ 2 Dec 07, 2021
Official Python wrapper for the Quantel Finance API

Quantel is a powerful financial data and insights API. It provides easy access to world-class financial information. Quantel goes beyond just financial statements, giving users valuable information l

Guy 47 Oct 16, 2022
Use CSV files as a Nornir Inventory source with hosts, groups and defaults.

nornir_csv Use CSV files as a Nornir Inventory source with hosts, groups and defaults. This can be used as an equivalent to the Simple Inventory plugi

Matheus Augusto da Silva 2 Aug 13, 2022
Connect your Nintendo Switch playing status to Discord!

Disclaimer: Unfortunately, it appears that Nintendo has removed returning self-Presence in their API as of recently, making this project near obsolete

Deltaion Lee 145 Dec 30, 2022
universal messaging & notifications api

Pronounced "boat-shahft" What is botschaft? Botschaft is unified messaging & notifications appliance. Want to text yourself when a long-running task c

Tyler M. Kontra 25 Aug 16, 2022
This is a Python package to create a snowflake identifier similar to Discord's or Twitter's.

snowflake2 Based on falcondai and fenhl's Python snowflake tool, but with documentation and simliarities to Discord. Installation instructions Install

Learnloot 2 Mar 19, 2022
❤️A next gen powerful telegram group manager bot for manage your groups and have fun with other cool modules

Natsuki Based on Python Telegram Bot Contributors Video Tutorial: Complete guide on deploying @TheNatsukiBot's clone on Heroku. ☆ Video by Sadew Jayas

Pawan Theekshana 8 Oct 06, 2022
A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python.

A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using async and await

Senpai Development 4 Nov 05, 2021
Weather App using openweathermap API

This is my hobby project used to learn how to use public api for project.In this i used the api of openweathermap to featch the weather details of various city across the globe by giving city name as

Subramanya K S 1 Nov 06, 2021
Telegram Google Translater Bot

Google-Translater-Bot Hey Mo Tech, I am simple Google Translater Bot. I can translate any language to you selected language Team Mo Tech Deploy To Her

21 Dec 01, 2022
A Telegram Music Bot with proper functions written in Python with Pyrogram and Py-Tgcalls.

⭐️ Yukki Music Bot ⭐️ A Telegram Music Bot written in Python using Pyrogram and Py-Tgcalls Ready to use method A Support Group and ready-to-use runnin

Shikhar Kumar 1000 Jan 03, 2023
Demonstrating attacks, mitigations, and monitoring on AWS

About Inspectaroo is a web app which allows users to upload images to view metadata. It is designed to show off many AWS services including EC2, Lambd

Alex McCormack 1 Feb 11, 2022
A Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot

Adv Auto Filter Bot This Is Just An Simple Advance Auto Filter Bot Complete Rewritten Version Of Adv-Filter-Bot.. Just Sent Any Text As Query It Will

TeamShadow 4 Dec 10, 2021
A Bot to get RealTime Tweets to a Specific Chats from Desired Persons on Twitter to Telegram Chat.

TgTwitterStreamer A Bot to get RealTime Tweets to a Specific Chats from Desired Persons on Twitter to Telegram Chat. For Getting ENV's Refer this Link

Anonymous 69 Dec 20, 2022
A working selfbot for discord

React Selfbot Yes, for real ⚠ "Maintained" version: https://github.com/AquaSelfBot/AquaSelfbot ⚠ Why am I making this open source? Because can't stop

3 Jan 25, 2022
Automatically check for free Anmeldung appointments.

Berlin Anmeldung Appointments (Python) This Python script will automatically check for free Anmeldung appointments in Berlin, and find them for you. T

Martín Aberastegue 6 May 19, 2022
A simple chat api that can also work with ipb4 and chatbox+

SimpleChatApi API for chatting that can work on its own or work with Invision Community and Chatbox+. You are also welcome to create frontend for this

Anubhav K. 1 Feb 01, 2022
aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in a future time.

aws-lambda-scheduler aws-lambda-scheduler lets you call any existing AWS Lambda Function you have in the future. This functionality is achieved by dyn

Oğuzhan Yılmaz 57 Dec 17, 2022
Discord bot that automatically fills out health screenings

Auto Covid Bot Automatically fill out the NYC DOE health screening form by registering with a discord bot School code can be found on https://schoolse

Cleo 2 Jul 29, 2022
Using GNU Radio and HackRF One to Receive, Analyze and Send ASK/OOK signals

play_with_ask NIS-8016 Lab A code: Recv.grc/py: Receive signals and match with ASK button using HackRF and GNU radio. I use AM demod block(can also in

Chen Anxue 1 Jul 04, 2022