Skip to main content

Official Python SDK for KarboAI Bot API

Project description

karbo

Official Python SDK for the KarboAI Bot API.

🇬🇧 English

📚 Full documentation

The complete, always up-to-date reference lives in two places:

The snippets below are a quick taste. Refer to the docs for every endpoint, every field, error codes, rate limits, and the full inline- buttons reference.

Install

pip install -U karbo

Hello bot

import asyncio
import karbo

BOT_TOKEN = "your-bot-token"

async def main():
    bot = karbo.KarboBot(BOT_TOKEN)
    ws = karbo.KarboBotWS(BOT_TOKEN)

    me = await bot.get_me()
    print(f"Bot: {me.name} ({me.bot_id})")

    @ws.on_message
    async def on_message(message: karbo.Message):
        if message.user_id == me.bot_id:
            return
        await bot.send_message(message.chat_id, f"Echo: {message.content}")

    await ws.run_forever()

asyncio.run(main())

Inline buttons

Attach a List[List[Button]] to any message. Rows are the outer list, columns within a row are the inner list. Up to 10 rows × 5 columns, 30 buttons total per message.

import karbo as k

await bot.send_message(
    chat_id,
    "Confirm payment?",
    buttons=[
        [
            k.Button(
                "pay", "Pay",
                style=k.ButtonStyle(color="#22C55E", shape="capsule"),
                animations=[k.Pulse(speed_ms=900)],
                particles=k.SparkParticles(color="#FFD54F"),
            ),
            k.Button(
                "cancel", "Cancel",
                style=k.ButtonStyle(color="#1F2937", shape="capsule"),
            ),
        ],
    ],
)

@ws.on_button_pressed
async def on_press(press: k.ButtonPress):
    if press.button_id == "pay":
        await bot.send_message(
            press.chat_id, "Paid!", reply_to=press.message_id,
        )

Available pieces (see docs.karboai.com for the full reference):

  • StylesButtonStyle, Gradient (horizontal / vertical / diagonal / radial), shapes rectangle / circle / capsule.
  • InteractionsTapInteraction (default) or SwipeInteraction(text, fill_color) (drag-to-confirm).
  • AnimationsPulse, Neon, Glitch, Outline (up to 4 per button, no duplicate kinds).
  • ParticlesSparkParticles, ConfettiParticles, HeartParticles, PixelParticles, SmokeParticles (one per button, color + intensity 1-5).

Models & errors

BotInfo, Message, SentMessage, User, Member, Author, AvatarFrame, MessageReaction, ButtonPress.

Exceptions all inherit from karbo.KarboError: AuthenticationError, ForbiddenError, NotFoundError, ValidationError, RateLimitError, APIError.

License

MIT

🇷🇺 Русский

📚 Полная документация

Актуальный и полный референс живёт в двух местах:

Здесь — только короткие примеры для старта. За полным списком эндпоинтов, описанием полей, кодами ошибок, лимитами и описанием inline-кнопок — иди в доку.

Установка

pip install -U karbo

Минимальный бот

import asyncio
import karbo

BOT_TOKEN = "your-bot-token"

async def main():
    bot = karbo.KarboBot(BOT_TOKEN)
    ws = karbo.KarboBotWS(BOT_TOKEN)

    me = await bot.get_me()
    print(f"Bot: {me.name} ({me.bot_id})")

    @ws.on_message
    async def on_message(message: karbo.Message):
        if message.user_id == me.bot_id:
            return
        await bot.send_message(message.chat_id, f"Echo: {message.content}")

    await ws.run_forever()

asyncio.run(main())

Inline-кнопки

Прикрепляются к сообщению как List[List[Button]]: внешний список — строки, внутренний — кнопки в строке. До 10 строк × 5 колонок, 30 кнопок всего на одно сообщение.

import karbo as k

await bot.send_message(
    chat_id,
    "Подтвердить оплату?",
    buttons=[
        [
            k.Button(
                "pay", "Оплатить",
                style=k.ButtonStyle(color="#22C55E", shape="capsule"),
                animations=[k.Pulse(speed_ms=900)],
                particles=k.SparkParticles(color="#FFD54F"),
            ),
            k.Button(
                "cancel", "Отмена",
                style=k.ButtonStyle(color="#1F2937", shape="capsule"),
            ),
        ],
    ],
)

@ws.on_button_pressed
async def on_press(press: k.ButtonPress):
    if press.button_id == "pay":
        await bot.send_message(
            press.chat_id, "Оплачено!", reply_to=press.message_id,
        )

Доступные блоки (полный референс — на docs.karboai.com):

  • СтилиButtonStyle, Gradient (horizontal / vertical / diagonal / radial), формы rectangle / circle / capsule.
  • ВзаимодействияTapInteraction (по умолчанию) или SwipeInteraction(text, fill_color) (свайп-подтверждение).
  • АнимацииPulse, Neon, Glitch, Outline (до 4 на кнопку, без дублей по kind).
  • ПартиклыSparkParticles, ConfettiParticles, HeartParticles, PixelParticles, SmokeParticles (одна конфигурация на кнопку, параметры — color и intensity 1-5).

Модели и ошибки

BotInfo, Message, SentMessage, User, Member, Author, AvatarFrame, MessageReaction, ButtonPress.

Все исключения наследуют от karbo.KarboError: AuthenticationError, ForbiddenError, NotFoundError, ValidationError, RateLimitError, APIError.

Лицензия

MIT

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

karbo-0.8.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

karbo-0.8.1-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file karbo-0.8.1.tar.gz.

File metadata

  • Download URL: karbo-0.8.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for karbo-0.8.1.tar.gz
Algorithm Hash digest
SHA256 8831314de82b6b6ee97d0dd92cbd039d51dcbc4f90e99d47da4d9317eab7608f
MD5 78e95bde6c73bb84a1d0300181bd11f6
BLAKE2b-256 8a91145da8140c9286405b82474cd03f9b5866ff39ff3ce0576c398e59996e3a

See more details on using hashes here.

File details

Details for the file karbo-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: karbo-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.7

File hashes

Hashes for karbo-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9b623dfa1ade59c05fb8481d8f0394975ee9f1492e1ded59e61e5cb08e36ec
MD5 f7cb1fe14171b58ca9027572a5e2d0a7
BLAKE2b-256 af14442b99a919c52356138c27f901e2de512cc857d771d8bff9040b1db71154

See more details on using hashes here.

Supported by

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