teleasy 2.0.2
Creating Telegram Bots Made Simple
PyPi Page
Table of contents
Example
from teleasy import TelegramBot, UpdateInfo
bot = TelegramBot(<YOUR_TOKEN>)
@bot.on_normal_message
def on_normal_message(chat: ChatInstance):
chat.print(f"hello {chat.first_name}")
@bot.on_command("/input")
def input_example(chat: ChatInstance):
color = chat.input("what's your favorite color?")
chat.print(f"Your favorite color is {color}")
bot.start()
See Examples-Folder for more
Setup
pip install teleasy
pip3 install teleasy
python3 -m pip install teleasy
# Now, you can import the relevant Classes using
from teleasy import TelegramBot, UpdateInfo
# or just do
import teleasy
# and access the classes from the 'teleasy' object directly
see Installation Help (Wiki) for more Help
Introduction
# first import the relevant classes
from teleasy import TelegramBot, ChatInstance
# create bot object using your token as parameter
bot = TelegramBot(<YOUR_TOKEN>)
# let's define our first message handler that will respond
# to all messages with "Hello, World!"
@bot.on_normal_message
# tell the bot to use the following function
# when encountering normal messages
def normal_message_handler(chat: ChatInstance):
# every handler will be passed a custom ChatInstance
# this object contains information about the message
# and may be used to get user input
chat.print("Hello World!")
# handlers are run in parallel using multithreading to enable
# very easy handling of user input
# now we need to start the bot
bot.start()
# and it's ready to go! Feel free to copy this code and try it out
command handlers
# we can also define command handlers:
@bot.on_command("/help") # optional "/" in front of command name
def help_command_handler(chat: ChatInstance):
chat.print("Welcome to the Help-Function")
user input
# each telegram message handler will be given its own thread to operate in
# this allows us to get user input very easily by doing so:
@bot.on_command("dialogue")
def dialogue_command_handler(chat: ChatInstance):
# the chat.input method works like the built-in 'input()' method in python
color = chat.input("What's your favorite color?")
food = chat.input("What's your favorite food?")
chat.print(f"color: {color}\nfood: {food}")
Status
Project is IN PROGRESS
Project is currently in its BETA
License
This project is licensed under the terms of the MIT license.