Python package for developing Viber Bots
Project description
PyViber
PyViber is a powerful asynchronous Python library for interacting with Viber Bot API.
Installation
pip install pyviber
Usage
Initializing the Bot
from pyviber.bot import Bot
from pyviber.event_type import EventType
import asyncio
# Initialize the bot with your Viber Bot token
bot = Bot("your_viber_bot_token")
Setting and Unsetting Webhook
# Set webhook URL to receive callbacks
webhook_url = "https://your-webhook-url.com/viber"
event_types = [EventType.MESSAGE, EventType.SUBSCRIBED]
async def set_webhook():
await bot.set_webhook(webhook_url, event_types)
async def unset_webhook():
await bot.unset_webhook()
Sending Messages
from pyviber.messages import TextMessage
from pyviber.sender import Sender
async def send_message_example():
sender = Sender(name="Your Bot Name", avatar="https://your-avatar-url.com/avatar.png")
message = TextMessage(text="Hello from your Viber Bot!")
receiver_id = "user_viber_id"
await bot.send_message(receiver_id, message, sender)
Getting Account Information
from pyviber.bot_info import BotInfo
async def get_account_info_example():
account_info = await bot.get_account_info()
print(account_info.name)
print(account_info.uri)
Handling Events
@bot.event("message")
async def handle_message_event(event):
# Handle incoming message event
if event.type == EventType.MESSAGE:
print("Received message:", event.message)
async def handle_events():
# Simulate receiving an event (should come from Viber)
event = {"event": "message", "message": "Test message"}
await bot.handle_event(event)
Error Handling
Exceptions are raised for API errors, ensuring robust error handling for operations like sending messages or retrieving information.
References
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
pyviber-0.2.tar.gz
(9.8 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
pyviber-0.2-py3-none-any.whl
(17.0 kB
view details)
File details
Details for the file pyviber-0.2.tar.gz.
File metadata
- Download URL: pyviber-0.2.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d6ff1e35e77af057477b90640cc5279b9810a72880cbb42557b02c9a9bb338e
|
|
| MD5 |
b83a262e614bdea448448a1a2dd43760
|
|
| BLAKE2b-256 |
ba7ec530b08c0aaca1e6b6057e77d13cfcc84d112c51bb9c655b5aa8acc7e5a1
|
File details
Details for the file pyviber-0.2-py3-none-any.whl.
File metadata
- Download URL: pyviber-0.2-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6f55581c22697026d2353320d6fb84d570dfaa3fa357cebb3cce98df896c8aa
|
|
| MD5 |
d618d74d4c24bb7057d628f36fa46cc4
|
|
| BLAKE2b-256 |
cf92dc83ae9e8e1e606b1b36e19bbd1dbf3f49440a939a7a0b0d9a355b6b2cee
|