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=...)
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)
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
pulsar_bot-0.1.0.tar.gz
(5.2 kB
view details)
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.1.0.tar.gz.
File metadata
- Download URL: pulsar_bot-0.1.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e033f7bd71f586712d42855638b41fe38a59bb07c53dbf6a614cfce86566ff2
|
|
| MD5 |
93779c27e6413b74292e693b4c4f34eb
|
|
| BLAKE2b-256 |
0f7ba0be042de184b0324acb3971f9a32866a754bd0220c78f0cc6d8404f8788
|
File details
Details for the file pulsar_bot-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pulsar_bot-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd0cb76a4b300a3f34b2e7cbc497ea2aaa68a0535eec03040ceffb0374abbd74
|
|
| MD5 |
fe1ffa9f92d67623dd31b7339b23fe2d
|
|
| BLAKE2b-256 |
6d64be7c53bdb6e503ff6e7c2cba1c4415afc482173b21fb7edad4326b2f1075
|