Skip to main content

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

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


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplybot-0.24.8.113-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file simplybot-0.24.8.113.tar.gz.

File metadata

  • Download URL: simplybot-0.24.8.113.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for simplybot-0.24.8.113.tar.gz
Algorithm Hash digest
SHA256 56ea40b52496af338e6467e16c0f554b0bdc27175c0fdb21cd3ccd8c1537a6dc
MD5 6b747255aec43aa417ec11e3e6670ff1
BLAKE2b-256 c3c888a4ecb9db91912c4f8a2c99885a49d9638bab7c51134e7e345d6f9ce682

See more details on using hashes here.

File details

Details for the file simplybot-0.24.8.113-py3-none-any.whl.

File metadata

  • Download URL: simplybot-0.24.8.113-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for simplybot-0.24.8.113-py3-none-any.whl
Algorithm Hash digest
SHA256 6c35a40f68e2d3052fce1832e1c6577c3e26890d3a15d0a0c62782b7005d6698
MD5 9487196345dcd1d5f9d67e768c24d1cc
BLAKE2b-256 0121cd078aaf822968c1275eca0db10224318e2e948d38c32f448488320f9ab0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page