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
- Host: GitHub
- URL: https://github.com/david-lor/basic_python_telegrambot
- Owner: David-Lor
- Created: 2018-05-14T14:50:47.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-14T14:53:25.000Z (about 8 years ago)
- Last Synced: 2025-02-04T02:58:12.511Z (over 1 year ago)
- Topics: python, telegram, telegram-bot
- Language: Python
- Size: 1000 Bytes
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)
```