Unofficial Client for Yandex Messenger Bot API
Project description
Unofficial Yandex Messenger Bot API library
Obtaining Messenger bot token: link
Usage:
pip install yambot-client
# Add handlers to MessengerBot
# Supported handlers: text, command, button, server_action, regex, any
from yambot import MessengerBot
yb = MessengerBot('bot_token')
# Add command handler ex. when user sends /my_command
@yb.add_handler(command='/my_command')
def my_handler1(update):
yb.send_message('test1', update)
# Add text handler ex. when user sends some_text
@yb.add_handler(text='some_text')
def my_handler2(update):
yb.send_message('test2', update)
# Add button handler. Button must have callback_data with 'cmd': '/my_button' JSON object
# For more details about CallbackData see API description: https://yandex.ru/dev/messenger/doc/ru/data-types#button
@yb.add_handler(button='/my_button')
def my_handler3(update):
yb.send_message('test3', update)
# Add regex handler. Provide regular expression that will be tested against user text message
@yb.add_handler(regex='\d{5}')
def my_handler3(update):
yb.send_message('test4', update)
# Handler that will be applied when no other handlers match
@yb.add_handler(any=True)
def process_any(update):
yb.send_message('Unknown text', update)
Available Bot methods:
# Send text message
yb.send_message('text', update)
# Send image
yb.send_image(image_data, update)
# Send buttons
yb.send_inline_keyboard('Choose:', buttons, update)
# Delete message (from group chat)
yb.delete_message(message_id=123, chat_id='0/0/group-id')
# Delete message (from private chat)
yb.delete_message(message_id=456, login='user@example.com')
# Delete message (from thread)
yb.delete_message(message_id=789, chat_id='0/0/group-id', thread_id=100)
Button example for send_inline_keyboard():
button1 = {'text': 'Button 1', 'callback_data': {'cmd': '/button_1'}}
button2 = {'text': 'Button 2', 'callback_data': {'cmd': '/button_2'}}
buttons = [button1, button2]
Example: link
Update 0.2.1 (Latest)
New Features:
- ✅ Added edit message support via
message_idparameter insend_message()andsend_suggest_buttons()
When message_id is provided, the existing message is replaced instead of sending a new one.
Edit message example:
# Edit existing text message
response = yb.send_message('Original text', update)
yb.send_message('Updated text', update, message_id=response['message_id'])
# Edit message with suggest buttons
yb.send_suggest_buttons('Updated options:', buttons, update, message_id=response['message_id'])
Update 0.2.0
New Features:
- ✅ Added SuggestButtons support — new button type replacing deprecated
inline_keyboard - ✅ Added Directive types:
OpenUriDirective,SendMessageDirective,ServerActionDirective,SetElementsStateDirective - ✅ Added
send_suggest_buttons()method - ✅ Added
server_actionhandler type for routing button callbacks - ✅ Added inbound types:
BotRequest,ServerAction,BotRequestError
Deprecations:
Buttontype andsend_inline_keyboard()are deprecated in favor ofSuggestButtonsandsend_suggest_buttons()
SuggestButtons example:
from yambot import (
MessengerBot, SuggestButtons, InlineSuggestButton,
ServerActionDirective, OpenUriDirective
)
yb = MessengerBot('bot_token')
buttons = SuggestButtons(
layout="true",
persist=False,
buttons=[
[
InlineSuggestButton(
id="btn1",
title="Action Button",
directives=[
ServerActionDirective(name="do_something", payload={"key": "value"})
]
),
InlineSuggestButton(
id="btn2",
title="Open Link",
directives=[
OpenUriDirective(uri="https://example.com")
]
)
]
]
)
yb.send_suggest_buttons("Choose an option:", buttons, update)
# Handle server_action callback
@yb.add_handler(server_action='do_something')
def handle_action(update):
payload = update.bot_request.server_action.payload
yb.send_message(f"Received: {payload}", update)
Update 0.1.0
Improvements:
- ✅ Fixed bugs
- ✅ Added error handling
- ✅ Implemented rate limiting
- ✅ Added support for Polls API (
create_poll,get_poll_results,get_poll_voters) - ✅ Added support for Chat Management API (
create_chat,create_channel,update_members,get_user_link) - ✅ Added new type models:
Button,User,Vote,Sticker,ForwardedMessage - ✅ Enhanced
send_message()with additional parameters:payload_id,reply_message_id,disable_notification,important,thread_id - ✅ Fixed naming:
pooling→polling
New Methods:
# Polls
yb.create_poll(title, answers, update)
yb.get_poll_results(message_id, update)
yb.get_poll_voters(message_id, answer_id, update)
# Chat Management
yb.create_chat(name, description, members, admins)
yb.create_channel(name, description, subscribers, admins)
yb.update_members(chat_id, members, admins, remove)
yb.get_user_link(login)
Important Changes:
Update.chatis now required (not Optional)Update.imagestype changed fromList[Tuple[...]]toList[List[Image]]
Deprecations:
start_pooling()→ usestart_polling()insteadpool_intervalparameter → usepoll_intervalinstead
Update 0.0.5
- Added bot send gallery method
yb.send_gallery(images, update)whereimagesis a list of image objects same as insend_imagemethod - Bot send methods will return JSON response with
message_id - Added optional argument
disable_web_page_previewtoyb.send_message(images, update, disable_web_page_preview=True)method. Default value isTrue
Update 0.0.4
- Added logger support.
Create bot instance with
log_level=logging.DEBUGargument for debug output. By default log level is INFO.
yb = MessengerBot('bot_token', log_level=logging.DEBUG)
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 yambot_client-0.2.1.tar.gz.
File metadata
- Download URL: yambot_client-0.2.1.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b62ae75e98d3fd3fb194a95f097e12649c47a12745b6d655e1f176252cad44da
|
|
| MD5 |
754cc8c63c7038c718dbbbdcbc16f0bf
|
|
| BLAKE2b-256 |
cd553601be1b9e56de123c5add2669dee8af5410c17a473ca75e24be28dfa932
|
File details
Details for the file yambot_client-0.2.1-py3-none-any.whl.
File metadata
- Download URL: yambot_client-0.2.1-py3-none-any.whl
- Upload date:
- Size: 16.5 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 |
fe44fc9c958d8afb584d9080870ada8b25f073fc9811802a9c5ef81d4eabf1f4
|
|
| MD5 |
68121dddf6584711905bb36a74836541
|
|
| BLAKE2b-256 |
9243df906e79eb3c6bf5c6be1363546daecc575a93c2c0a0415f2c30fdf85e00
|