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.2.0.tar.gz (10.6 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.2.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pykodaribot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 75a029acf6cb5281b4c4bf15ea22b2d83770371295e9a409a598b69236ceccd6
MD5 d8a264bbda3add0e613516e07d4bb6af
BLAKE2b-256 fdfa5cbd909d27555877fdba9e2a15d0133362db3f6120da45ecd722519bf925

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykodaribot-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee2a299800dfb21c5dd6000b6b60714340e50def101f1f9d44a5308becf425ef
MD5 d506b00794c1af8fbeb64dbaab854de7
BLAKE2b-256 81ed3f9f16d3f451655e57853415a4daf43377054c4fc8ce4e7ed222ed65f3d9

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