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
Easy way to use Telegram bot to hide your identity.

telegram-support-bot Easy way to use Telegram bot to hide your identity. Useful for support, anonymous channel management. Free clone of Livegram Bot.

Daniil Okhlopkov 197 Dec 23, 2022
👾 Telegram Smart Group Assistant 🤖

DarkHelper 🌖 Features ⚡️ Smart anti-apam & anti-NFSW message checker Tag Members , Entertain facility , Welcommer ban , unban , mute , unmute , lock

amirali rajabi 38 Dec 18, 2022
A telegram bot writen in python for mirroring files on the internet to our beloved Google Drive

[] Mirror Bot This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive. Deploying on Heroku Give Star &

43 Mar 06, 2022
Some python code to make twitter bots ;)

How to set up a twitter bot using python's tweepy library Create a twitter developer account and project Make sure you are logged into your twitter ac

Wael 2 Jan 10, 2022
Cloudshell-sandbox-reporter - Helper modules and classes for writing to Cloudshell sandbox console

Cloudshell Sandbox Reporter This project provides utility classes for formatting

QualiLab 2 Sep 07, 2022
Upload comma-delimited files to biglocalnews.org in your GitHub Action

Upload comma-delimited files to biglocalnews.org in your GitHub Action Inputs api-key: Your biglocalnews.org API token. project-id: The identifier of

biglocalnews 1 Apr 20, 2022
Allows you to easily share bookmarks from Raindrop.io in Telegram chats.

Allows you to easily share bookmarks from Raindrop.io in Telegram chats. As well as save links/photos/longreads from Telegram right into Raindrop.io. Join us, we have a nice 'reader mode' :)

Oleh 36 Dec 19, 2022
Useful tools for building interactions in Python

discord-interactions-python Types and helper functions for Discord Interactions webhooks. Installation Available via pypi: pip install discord-interac

Discord 77 Dec 07, 2022
KTUN Öğrenci Bilgi Sistemine bağlanıp her 15 dakikada notları kontrol eden ve değişiklik olduğu zaman size Discord Webhook ile mesaj atan uygulama.

KTUN_Obis KTUN Öğrenci Bilgi Sistemi KTUN Öğrenci Bilgi Sistemine selenium kullanarak girip setttings.py dosyasında verdiğiniz bilgeri doldurup ardınd

İbrahim Uysal 5 Oct 27, 2022
A file-based quote bot written in Python

Let's Write a Python Quote Bot! This repository will get you started with building a quote bot in Python. It's meant to be used along with the Learnin

1 Jan 15, 2022
Cogs for Red-DiscordBot

Redbot cogs for Red-DiscordBot authored by Kreusada This is my repository for Red Discord-Bot. I built these cogs because these were the features that

Kreus Amredes 26 Nov 07, 2022
PepeSniper is an open-source Discord Nitro auto claimer/redeemer made in python.

PepeSniper is an open-source Discord Nitro auto claimer made in python. It sure as hell is not the fastest sniper out there but it gets the job done in a timely and stable manner. It also supports ho

Unknown User 1 Dec 22, 2021
Gathers data and displays metrics related to climate change and resource depletion on a PowerBI report.

Apocalypse Status Dashboard Purpose Climate change and resource depletion are grave long-term dangers. The code in this repository will pull data from

Summer Is Here 1 Nov 12, 2021
An automated tool that fetches information about your crypto stake and generates historical data in time.

Introduction Yield explorer is a WIP! I needed a tool that would show me historical data and performance of my staked crypto but was unable to find a

Sedat Can Yalçın 42 Nov 26, 2022
GBSLocalLauncher - A script to compose ENV file for Local Compose

GBSLocalLauncher This is a script to compose ENV file for Local Compose. It crea

2 Jan 27, 2022
A full-featured Python wrapper for the Onfleet API.

UPDATE: Please use Onfleet's wrapper instead. This repository is not maintained. https://github.com/onfleet/pyonfleet --- Python-Onfleet   python-onfl

Lionheart Software 11 Jan 13, 2022
Lumberjack-bot - A game bot written for Lumberjack game at Telegram platform

This is a game bot written for Lumberjack game at Telegram platform. It is devel

Uğur Uysal 6 Apr 07, 2022
A Python wrapper for the WooCommerce API.

WooCommerce API - Python Client A Python wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library. Insta

WooCommerce 171 Dec 25, 2022
Trust-minimized Bitcoin wallet

coldcore Trust-minimized, airgapped Bitcoin management This is experimental software. Wait for a formal release before use with real funds. A trust-mi

James O'Beirne 121 Jan 01, 2023
A library for demo trading | backtest and forward test simulation

Trade Engine a library for demo trading | backtest and forward test simulation Features Limit/Market orders: you can place a Limit or Market order in

Ali Moradi 7 Jul 02, 2022