Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PyDevNik/pyviber

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

12 Commits

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /