Skip to main content

Minimal Telegram Bot API wrapper to send messages - to user, channel, or group.

Project description

Robogram 🤖📨️ - Telegram Bot API

https://img.shields.io/pypi/v/robogram.svg https://img.shields.io/pypi/l/robogram.svg https://img.shields.io/pypi/pyversions/robogram.svg https://github.com/rnag/robogram/actions/workflows/dev.yml/badge.svg Documentation Status Updates

robogram is an (unofficial) Minimal Telegram Bot API Wrapper to send messages on Telegram - to user, channel, or group.

The only dependency is requests – with over 50K stars on GitHub.

Install

robogram is available on PyPI, and can be installed with pip:

$ pip install robogram

You’ll also need to obtain an Bot Token as outlined in the docs.

Usage

Use a TeleBot to send a message to a personal chat, channel, or group on Telegram:

from robogram import TeleBot

# Authentication token, that you get by:
#   (1) opening a chat with `@BotFather`
#   (2) using command `/newbot` to create a new bot
BOT_TOKEN = 'TOKEN'

# Chat ID, that you get by:
#   (1) Add the new bot to personal chat, channel, or group
#   (2) Send a message to bot
CHAT_ID = -123456789

bot = TeleBot(BOT_TOKEN)

r = bot.send_message(CHAT_ID, 'Hello World!')
print(r)

Looking for an easier way to get the Chat ID for a personal chat, channel, or group?

Follow steps above, and add the Bot to chat. Then use TeleBot.get_chat_ids_from_updates, a convenience wrapper around /getUpdates:

import json

# Get a mapping of Chat ID to Chat Type/Title,
# based on `/getUpdates` response.
#
# Example Response:
# {
#   12345: '[PRIVATE] User321',
#   -97531: '[CHANNEL] My Channel',
# }
chat_id_to_title = bot.get_chat_ids_from_updates()
print(json.dumps(chat_id_to_title, indent=2))

To get info on the TeleBot associated with the token:

me = bot.get_me()
print(json.dumps(me, indent=2))

Credits

This package was created with Cookiecutter and the rnag/cookiecutter-pypackage project template.

History

0.1.0 (2024-06-20)

  • First release on PyPI.

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

robogram-0.1.0.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

robogram-0.1.0-py2.py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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