Official Pulsar messenger Bot SDK for Python — Telegram-style API
Project description
pulsar-bot
Официальный Python SDK для ботов мессенджера Pulsar. Стиль — как python-telegram-bot/aiogram, async из коробки.
Установка
pip install pulsar-bot
Требуется Python 3.9+.
Быстрый старт
- Создайте бота через @pulsarbot →
/newbot→ получите токен. - Напишите бота:
from pulsar_bot import Bot, Keyboard
bot = Bot("YOUR_TOKEN")
@bot.command("start")
async def start(ctx):
await ctx.reply(
"Привет! Выбери опцию:",
buttons=Keyboard.inline([
[{"text": "✅ Да", "data": "yes"}, {"text": "❌ Нет", "data": "no"}],
]),
)
@bot.on_callback("yes")
async def on_yes(ctx):
await ctx.reply("Отлично!")
@bot.on_callback("no")
async def on_no(ctx):
await ctx.reply("Как скажете.")
@bot.on_message()
async def echo(ctx):
if ctx.text and not ctx.text.startswith("/"):
await ctx.reply(f"Echo: {ctx.text}")
if __name__ == "__main__":
bot.run()
python bot.py— готово.
API
Декораторы
@bot.command("start") # /start
@bot.on_message() # любое текстовое сообщение
@bot.on_callback("yes") # точное совпадение callback_data
@bot.on_callback("item_*") # префикс (item_1, item_2, …)
@bot.on_callback("*") # fallback для всех callback
Context
ctx.text— текст сообщенияctx.from_user— отправитель{"id": ...}ctx.chat_id— ID чатаawait ctx.reply(text, buttons=..., reply_to_id=...)await ctx.answer_callback(text)
Методы бота
await bot.send_message(chat_id, text, buttons=..., reply_to_id=..., reply_keyboard=...)
await bot.edit_message(chat_id, message_id, text=..., buttons=..., reply_keyboard=...)
await bot.send_audio(chat_id, audio_url, file_name=..., caption=...)
await bot.delete_message(chat_id, message_id)
await bot.kick_member(chat_id, user_id)
await bot.set_commands([{"command": "start", "description": "Начать"}])
await bot.set_webhook("https://mybot.com/hook", secret="...")
await bot.get_chats()
await bot.leave_chat(chat_id)
Reply Keyboard (приклеенные кнопки)
Persistent кнопки над полем ввода — как в Telegram. Клик отправляет текст кнопки как обычное сообщение.
@bot.command("start")
async def start(ctx):
await ctx.bot.send_message(
ctx.chat_id,
"Главное меню",
reply_keyboard=[
["▶️ Старт", "🆘 Поддержка"],
["💎 Профиль"],
],
)
# Чтобы убрать клавиатуру — передайте пустой список:
await bot.send_message(chat_id, "Готово", reply_keyboard=[])
Edit Message (редактирование сообщений)
Меняет текст / inline-кнопки / reply-keyboard уже отправленного ботом сообщения. Удобно для wizard-флоу — одно сообщение перерисовывается шаг за шагом, чат не засоряется.
msg = await bot.send_message(chat_id, "Шаг 1 из 3", buttons=[[{"text": "Далее", "data": "step2"}]])
@bot.on_callback("step2")
async def step2(ctx):
await ctx.bot.edit_message(
ctx.chat_id,
ctx.callback_query["message"]["id"],
text="Шаг 2 из 3",
buttons=[[{"text": "Далее", "data": "step3"}]],
)
Send Audio (отправка аудио)
Сервер скачает MP3 по URL, загрузит в хранилище и прикрепит к сообщению с встроенным плеером.
await bot.send_audio(
chat_id,
"https://example.com/song.mp3",
file_name="my-song.mp3",
caption="🎵 Готово!",
)
Keyboard
Keyboard.inline([
[{"text": "Да", "data": "yes"}, {"text": "Нет", "data": "no"}],
[{"text": "Отмена", "data": "cancel"}],
])
# или builder-style:
Keyboard().row({"text": "Да", "data": "yes"}, {"text": "Нет", "data": "no"}) \
.row({"text": "Отмена", "data": "cancel"}).build()
Документация
Полная документация API: https://pulsar-chat.fun/developers
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pulsar_bot-0.2.0.tar.gz.
File metadata
- Download URL: pulsar_bot-0.2.0.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfc8305881a024922a29a21d5f9af2b3360bfe65a545d5f0e0cad231489295e0
|
|
| MD5 |
9f052e4dd0940f4d6078db050b1d1c87
|
|
| BLAKE2b-256 |
7ef91ee9ad8115cb8c268d76f96c523a61ff4034ac32d7898d09df6c7127b6cc
|
File details
Details for the file pulsar_bot-0.2.0-py3-none-any.whl.
File metadata
- Download URL: pulsar_bot-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ab0ff0eb23f11cc37b782e8e44956ad109ed9573cdd62216de5a2b1eacd2409
|
|
| MD5 |
fa768aa56cb565275ab7802cbeabb7e9
|
|
| BLAKE2b-256 |
be54d70156028b64014959f6373018cc357a10683611e4daaecf1d7541c5b6e0
|