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, 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. If update has chat or thread id message will be sent to chat or thread
# Otherwise message will be sent directly to user
yb.send_message('text', update)
# Send image. image_data can be either ASCII string or bytes object
yb.send_image(image_data, update)
# Send buttons. buttons must be a list of Button objects
yb.send_inline_keyboard(buttons, update)
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.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
yambot_client-0.0.7.tar.gz
(7.0 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 yambot_client-0.0.7.tar.gz.
File metadata
- Download URL: yambot_client-0.0.7.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4a8eacf6d0282a6d5c8929111c718e63f9d33decf75388de8d76c90eb6b0fb5
|
|
| MD5 |
11488cb4fcbd620da71bb7120e6a552b
|
|
| BLAKE2b-256 |
0aa49bce0a8516de9336e533ef72330815091c0210174e4388e0a878c7645752
|
File details
Details for the file yambot_client-0.0.7-py3-none-any.whl.
File metadata
- Download URL: yambot_client-0.0.7-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
078613807a92c1111a5117e21580d58d2c61d452c736fa3b5f0d12f99785b8f5
|
|
| MD5 |
073ce71ecdbe5bbb98ff40650cb4aa0f
|
|
| BLAKE2b-256 |
6c1e34a21446bd7954c7250a0a726241bbb3360f57c420c877f0519a850e1242
|