An open API service indexing awesome lists of open source software.

https://github.com/david-lor/basic_python_telegrambot

A very simple Python tool to send messages via a Telegram bot
https://github.com/david-lor/basic_python_telegrambot

python telegram telegram-bot

Last synced: 8 months ago
JSON representation

A very simple Python tool to send messages via a Telegram bot

Awesome Lists containing this project

README

          

# Basic Python Telegram Bot

basictelebot is a very simple Python tool to send messages via a Telegram bot. It only allows sending simple text messages to a single destination, using Python's requests native library.

## Sending messages with function

```python
from basictelebot import send_message
token = "my telegram bot token"
chatid = 123456
text = "hi there!"
send_message(token, chatid, text)
```

## Sending messages with object

```python
from basictelebot import TelegramBot
bot = TelegramBot("my telegram bot token")
chatid = 123456
text = "hi there!"
bot.send_message(chatid, text)
```

## Was the message sent successfully?

Both send_message function and class method return True if message was sent successfully, and False if any error of any type happened (including exceptions in requests module).

```python
from basictelebot import send_message
token = "my telegram bot token"
chatids = [123, 456, 789]
text = "hi there!"
for chatid in chatids:
if send_message(token, chatid, text):
print("Message sent to", chatid)
else:
print("Message could not be sent to", chatid)
```