Skip to main content

Python SDK для создания ботов в Kodari Messenger

Project description

pykodaribot

Python SDK для создания ботов в Kodari Messenger.

Документация: docs.kodari.ru

Установка

pip install pykodaribot

Требования: Python 3.9+

Быстрый старт

import asyncio
from pykodaribot import Bot, Dispatcher, filters

bot = Bot("bot_ВАШ_ТОКЕН")
dp = Dispatcher()

@dp.message(filters.command("start"))
async def start(msg):
    await msg.answer("Привет!")

@dp.message()
async def echo(msg):
    if msg.text:
        await msg.reply(msg.text)

asyncio.run(dp.start_polling(bot))

Токен

Напишите @BotFather в мессенджере, введите /newbot и следуйте инструкциям.

API

Bot

Метод Описание
get_me() Информация о боте
send_message(chat_id, text, reply_to_message_id, reply_markup) Отправить текст
send_photo(chat_id, media, caption, reply_to_message_id) Отправить фото
send_document(chat_id, media, caption, reply_to_message_id) Отправить файл
send_video(chat_id, media, caption, reply_to_message_id) Отправить видео
send_audio(chat_id, media, caption, reply_to_message_id) Отправить аудио
edit_message_text(chat_id, message_id, text, reply_markup) Редактировать сообщение
delete_message(chat_id, message_id) Удалить сообщение
get_updates(offset, timeout, limit) Получить апдейты
answer_callback_query(callback_query_id) Ответить на callback
set_my_commands(commands) Установить команды меню
get_my_commands() Получить команды меню
set_my_name(name) Изменить имя бота
set_my_description(description) Изменить описание
set_my_short_description(short_description) Изменить краткое описание
get_chat(chat_id) Информация о чате

Dispatcher

dp = Dispatcher()

@dp.message(*filters)          # новое сообщение
@dp.edited_message(*filters)   # изменённое сообщение
@dp.callback_query(*filters)   # нажатие inline-кнопки

Фильтры

from pykodaribot import filters

filters.command("start", "help")        # команды /start или /help
filters.text(r"привет|hello")           # regex по тексту
filters.callback_data("yes")            # точное совпадение callback_data
filters.callback_data_prefix("action:") # callback_data начинается с префикса

Inline-клавиатура

from pykodaribot import InlineKeyboardMarkup, InlineKeyboardButton

keyboard = InlineKeyboardMarkup(inline_keyboard=[
    [
        InlineKeyboardButton(text="Да", callback_data="yes"),
        InlineKeyboardButton(text="Нет", callback_data="no"),
    ],
    [
        InlineKeyboardButton(text="Открыть сайт", url="https://kodari.ru"),
    ],
])

await msg.answer("Выберите:", reply_markup=keyboard)

Отправка медиа

media принимает путь к файлу, Path, bytes или file-like объект:

await bot.send_photo(chat_id, "photo.jpg", caption="Смотри!")
await bot.send_photo(chat_id, Path("/tmp/image.png"))
await bot.send_document(chat_id, open("report.pdf", "rb"))

with open("clip.mp4", "rb") as f:
    await bot.send_video(chat_id, f, caption="Видео")

Примеры

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

pykodaribot-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

pykodaribot-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pykodaribot-0.1.0.tar.gz.

File metadata

  • Download URL: pykodaribot-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pykodaribot-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6804cde44db81de6541f392ccaa31a6ff8addd53e9b0ec5a15d3bd19d0f8b643
MD5 abb3c7d34d8930df951ea2fed8473b67
BLAKE2b-256 8a039d403fd982e43e59b9d831acb14340a27049b8c461a9433326d31c67a379

See more details on using hashes here.

File details

Details for the file pykodaribot-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pykodaribot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for pykodaribot-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a870f642ca4cd3d4495079cad070003f3b4ac7b23ef21d6a03fc74bd71da8af6
MD5 2a06856fc954343726ffd361fd66096e
BLAKE2b-256 e8644da527eae01af7cd8fa01b669065c957b8b862c531901d79f2a014b584f2

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