Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lonami/dumbot
dumb telegram bot for python.
https://github.com/lonami/dumbot
api bot dumb python telegram
Last synced: about 17 hours ago
JSON representation
dumb telegram bot for python.
- Host: GitHub
- URL: https://github.com/lonami/dumbot
- Owner: Lonami
- License: mit
- Created: 2018-04-21T13:43:14.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T17:44:42.000Z (about 1 year ago)
- Last Synced: 2024-05-02T02:18:29.103Z (7 months ago)
- Topics: api, bot, dumb, python, telegram
- Language: Python
- Homepage:
- Size: 47.9 KB
- Stars: 32
- Watchers: 4
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dumbot
dumb async telegram bot for python 3.
# installation
add `dumbot.py` to your project or `pip install dumbot`.
# usage
## basic
```python
import asyncio
from dumbot import Botasync def main():
bot = Bot(token)
print(await bot.getMe())
msg = await bot.sendMessage(chat_id=10885151, text='hi lonami')
if msg.ok:
print('message sent', msg)
else:
print('something went wrong!', msg)loop = asyncio.get_event_loop()
loop.run_until_complete(main())
```## files
```python
async def main():
...
await bot.sendDocument(chat_id=10885151, file=dict(
type='document',
file='/home/lonami/holiday.jpg'
))
```## updates
```python
async def on_update(update):
await bot.sendMessage(
chat_id=update.message.chat.id,
text=update.message.text[::-1]
)...
bot.on_update = on_update
bot.run()
```## subclassing
```python
class Subbot(Bot):
async def init(self):
self.me = await self.getMe()async def on_update(self, update):
await self.sendMessage(
chat_id=update.message.chat.id,
text='i am {}'.format(self.me.username)
)Subbot(token).run()
```# faq
## what methods are available?
https://core.telegram.org/bots/api.
## can i send opened files or bytes directly?
yes.
## can i change a document's filename or mime?
yes, with `name` or `mime` fields in the `dict`.
## how can i handle exceptions?
there aren't, simply check the `.ok` property.
## what's the return value?
a magic object, accessing unknown properties returns a false-y magic object:
```python
from dumbot import Objlonami = Obj(name='lonami', hobby='developer')
print(lonami.name, 'is', lonami.age or 20)lonami.friend.name = 'kate'
print(lonami.friend)
```## no dependencies?
python alone is enough dependencies.
## how does this work without urllib or aiohttp?
it's simple, we construct http requests manually.
## why would you reimplement http?
it's a fun good learning experience, and avoids bloat dependencies.
## what do you have against uppercase?
scary. there would be less upper case if it weren't for
python's naming conventions or telegram's for that matter.