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.3.0.tar.gz (12.1 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.3.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pykodaribot-0.3.0.tar.gz
Algorithm Hash digest
SHA256 cc6ecaaf870616fae1c2706a39d979c6c766ec60ebd73f03eae2cfe58c889b8c
MD5 d7abc0e952079135e0bb9f9a3ae49bda
BLAKE2b-256 59646d022ba85a481876638b738f1423d17788088f28002284ab827f28bd315c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pykodaribot-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7993796778f2e0bbd110e035d1511ba5b290532b9eef394ac8fc380a95348ac5
MD5 a21009098a048afb0ea0947e8b15508a
BLAKE2b-256 60fb255a6195fda46d9069500c24aad4a23027e7de11effe551577e813a8711b

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