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.1.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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pykodaribot-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6074b90c4222fc027cf85e9490dd0f25608ba6a2adde7d7b2f3e61d7b41eccdd
MD5 07fdf7f834b4f84c2942a87b7f1fe994
BLAKE2b-256 03db634cb874b765fd2b079fe4ff179badfe547609f99798214d83cfa2cee76e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykodaribot-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 83197e52969e8c218d6537f299f85abad592882823d26a121800e87e273fe141
MD5 5d33e13008ced5c18cfc9d0a1fe01a4f
BLAKE2b-256 313b3677adec872d55334925bb3e8cfaafe02d9d4bd2b4d22af01efd74309a92

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