A Python library to build simple Telegram bots more easily
Project description
simplybot
A python library to create telegram bots simply and easily
Get started
- First install the main bot library
pip install simplybot
Example
# initialize bot token
from simplybot import startBot
bot = startBot('token here')
# example send plain text message
def start(message, chat_id):
bot.send_text(chat_id, "Hello %username! I'm your friendly telegram bot.", message=message)
# quoted message
bot.handle_command('start', start)
def quotedMessage(message, chat_id):
bot.send_text(chat_id, "This is quoted message", quoted=message.message_id)
bot.handle_command('start', start)
bot.handle_command('quoted', quotedMessage)
bot.start_polling() # start the bot
sending media
def send_media_messages(message, chat_id):
# Send an image from a URL
image_url = "https://example.com/path/to/image.jpg"
bot.send_img(chat_id, image_url, caption="Here is an image from a URL!")
# Send an image from a local file path
local_image_path = "path/to/local/image.jpg"
bot.send_img(chat_id, local_image_path, caption="Here is an image from a local file!")
# Send a video from a local file path
local_video_path = "path/to/local/video.mp4"
bot.send_video(chat_id, local_video_path, caption="Check out this video!")
# Send an audio file from a local file path
local_audio_path = "path/to/local/audio.mp3"
bot.send_audio(chat_id, local_audio_path, caption="Listen to this audio!")
# Send a document from a local file path
local_doc_path = "path/to/local/document.pdf"
bot.send_docs(chat_id, local_doc_path, mimetype="application/pdf")
markup/callback message
def start(message, chat_id):
# Define the buttons
payloads = {
'button': [
{
'rows': [
{
'type': 'inline',
'displayText': 'Option 1',
'callback': 'option_1'
},
{
'type': 'inline',
'displayText': 'Option 2',
'callback': 'option_2'
},
]
}
]
}
# Send the message with buttons
bot.send_message_with_buttons(chat_id, "Click button below", payloads)
def handle_option_1(call, chat_id):
# Respond to Option 1 button press
bot.send_text(chat_id, "You selected Option 1!")
def handle_option_2(call, chat_id):
# Respond to Option 2 button press
bot.send_text(chat_id, "You selected Option 2!")
other
# send quiz & polling message
def quiz(message, chat_id):
polling_message = {
'description': 'What is the capital of France?',
'rows': [
{
'name': 'Paris',
'isCorrectAnswers': True
},
{
'name': 'London',
'isCorrectAnswers': False
},
{
'name': 'Berlin',
'isCorrectAnswers': False
}
],
'isAnonymous': False,
'isQuizVote': True,
'allowMultipleVote': False,
'explanation': 'The capital of France is Paris.'
}
bot.send_poll(chat_id, polling_message)
# send contact
bot.send_contact(chat_id, '+1234567890', 'John')
# send location
bot.send_location(chat_id, 37.7749, -122.4194)
Credit
- eternnoir telebot
- & me :)
I have been works lonely for 7 hours making this libary and i forgot to touch some grass outside so give me:
- fork this reposity
- click the star
adjidev 2024
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplybot-0.24.8.113.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for simplybot-0.24.8.113-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 6c35a40f68e2d3052fce1832e1c6577c3e26890d3a15d0a0c62782b7005d6698 |
|
| MD5 | 9487196345dcd1d5f9d67e768c24d1cc |
|
| BLAKE2b-256 | 0121cd078aaf822968c1275eca0db10224318e2e948d38c32f448488320f9ab0 |