Skip to content

Asynchronous TamTam messenger's cool BotAPI python wrapper

License

Notifications You must be signed in to change notification settings

botseller11/tamtam.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

👮‍♂️ tamtam.py

tamtam.py-code-style tamtam.py-python-version

💥 TamTam.py is about performance, so it requires ujson for serialization and deserialization, pydantic for models management, aiohttp for web requests

pip install https://github.com/uwinx/tamtam.py/archive/master.zip

ℹ️ Setting bot-info:

from tamtam import Bot, types, run_async

Bot("put token @PrimeBot gave")

async def func():
    info = await types.BotInfoSetter(
        name="MyBotsName",
        description="smth...",
    )
    print(info)

run_async(func())

❓ Polling TamTam for updates

from tamtam import Bot, Dispatcher, types, run_poller

bot = Bot("put token @PrimeBot gave")
dp = Dispatcher(bot)

@dp.message_handler()
async def msg_handler(msg: types.Message):
    await msg.reply("Hello!")

run_poller(func())

☂️ Write fancy decorators

@dp.bot_started()
async def start_handler(upd: types.BotStarted):
    await upd.respond("you started bot")

👟 ⇒ 👞 Easily switch from polling to webhook

from tamtam import Bot, Dispatcher, types, run_sever

bot = Bot("token")
dp = Dispatcher(bot)

@dp.bot_started()
async def handler(upd: types.BotStarted):
    await upd.respond("Sup!")

run_server()

If not configured:

# better example in repo/examples/
async def sub(url):
    if not (await bot.subscribe(url))["success"]:
        # something went wrong
        ...
    ...

url = "https://my.domain/path"  # or use yarl.URL.build

from tamtam import run_async
run_async(sub(url))

Easy function based message filters

@dp.message_handler(MessageFilters.match(r"^.ban \d$"))
async def ban_user_handler(message: types.Message):
    ...

Buttons

You can use tamtam.types.attachments::InlineKeyboardAttachment, but ... I find it quite inconvenient to utilize and, that's why we have tamtam.types.attachments::ButtonsArray Think of ButtonsArray as an abstraction from list[list[button]].

from tamtam.types import ButtonsArray, CallbackButton, InlineKeyboardAttachment

array = ButtonsArray()
row, index = array.add_row(1)  # pass None for dynamic row
row.add(CallbackButton("text", "payload", "negative"))
row2, index2 = array.add_row(1)

array.delete_row(index2)

# further actions, e.g send message
attachments = (InlineKeyboardAttachment.from_array(array), )

Bots using tamtam.py

GetJson this bot returns sent message's json (useful for developers or no)

See examples for more.

If your bot using tamtam.py, let me know!

Some advices from author

  • Try to avoid using webhooks :) For safety, first of all.
  • Don't use another library-wrapper for tamtam.py.
  • async/await syntax is easy. asyncio does not eat people. Stay modern.

About

Asynchronous TamTam messenger's cool BotAPI python wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages