Use this library to develop a bot for Viber platform. The library is available on GitHub as well as a package on
This package can be imported using pip by adding the following to your requirements.txt
:
This library is released under the terms of the Apache 2.0 license. See License for more information.
- python >= 2.7.0
- An Active Viber account on a platform which supports Public Accounts/ bots (iOS/Android). This account will automatically be set as the account administrator during the account creation process.
- Active Public Account/ bot - Create an account here.
- Account authentication token - unique account identifier used to validate your account in all API requests. Once your account is created your authentication token will appear in the account’s “edit info” screen (for admins only). Each request posted to Viber by the account will need to contain the token.
- Webhook - Please use a server endpoint URL that supports HTTPS. If you deploy on your own custom server, you'll need a trusted (ca.pem) certificate, not self-signed. Read our blog post on how to test your bot locally.
Param | Type | Description |
---|---|---|
bot_configuration | object |
BotConfiguration |
Param | Type | Description |
---|---|---|
url | string |
Your web server url |
webhook_events | list |
optional list of subscribed events |
Returns List of registered event_types
.
event_types = viber.set_webhook('https://example.com/incoming')
Returns None
.
viber.unset_webhook()
Returns an object
with the following JSON.
account_info = viber.get_account_info()
Param | Type | Description |
---|---|---|
request_data | string |
the post data from request |
signature | string |
sent as header X-Viber-Content-Signature |
Returns a boolean
suggesting if the signature is valid.
if not viber.verify_signature(request.get_data(), request.headers.get('X-Viber-Content-Signature')):
return Response(status=403)
Param | Type | Description |
---|---|---|
to | string |
user id |
messages | list |
list of Message objects |
Returns list
of message tokens of the messages sent.
tokens = viber.send_messages(to=viber_request.get_sender().get_id(),
messages=[TextMessage(text="sample message")])
Param | Type | Description |
---|---|---|
sender | string |
user id |
messages | list |
list of Message objects |
Returns list
of message tokens of the messages sent.
tokens = viber.post_messages_to_public_account(sender=viber_request.get_sender().get_id(),
messages=[TextMessage(text="sample message")])
Param | Type | Notes |
---|---|---|
id | string |
--- |
name | string |
--- |
avatar | string |
Avatar URL |
country | string |
currently set in CONVERSATION_STARTED event only |
language | string |
currently set in CONVERSATION_STARTED event only |
Common Members for Message
interface:
Param | Type | Description |
---|---|---|
timestamp | long |
Epoch time |
keyboard | JSON |
keyboard JSON |
trackingData | JSON |
JSON Tracking Data from Viber Client |
Common Constructor Arguments Message
interface:
Param | Type | Description |
---|---|---|
optionalKeyboard | JSON |
Writing Custom Keyboards |
optionalTrackingData | JSON |
Data to be saved on Viber Client device, and sent back each time message is received |
Member | Type |
---|---|
text | string |
message = TextMessage(text="my text message")
Member | Type | Description |
---|---|---|
media | string |
URL string |
message = URLMessage(media="http://my.siteurl.com")
Member | Type |
---|---|
contact | Contact |
from viberbot.api.messages.data_types.contact import Contact
contact = Contact(name="Viber user", phone_number="+0015648979", avatar="http://link.to.avatar")
contact_message = ContactMessage(contact=contact)
Member | Type | Description |
---|---|---|
media | string |
url of the message (jpeg only) |
text | string |
|
thumbnail | string |
message = PictureMessage(media="http://www.thehindubusinessline.com/multimedia/dynamic/01458/viber_logo_JPG_1458024f.jpg", text="Viber logo")
Member | Type | Description |
---|---|---|
media | string |
url of the video |
size | int |
|
thumbnail | string |
|
duration | int |
message = VideoMessage(media="http://site.com/video.mp4", size=21499)
Member | Type |
---|---|
location | Location |
from viberbot.api.messages.data_types.location import Location
location = Location(lat=0.0, lon=0.0)
location_message = LocationMessage(location=location)
Member | Type |
---|---|
sticker_id | int |
message = StickerMessage(sticker_id=40100)
Member | Type |
---|---|
media | string |
size | long |
file_name | string |
message = FileMessage(media=url, size=sizeInBytes, file_name=file_name)
Member | Type |
---|---|
rich_media | string (JSON) |
SAMPLE_RICH_MEDIA = """{
"BgColor": "#69C48A",
"Buttons": [
{
"Columns": 6,
"Rows": 1,
"BgColor": "#454545",
"BgMediaType": "gif",
"BgMedia": "http://www.url.by/test.gif",
"BgLoop": true,
"ActionType": "open-url",
"Silent": true,
"ActionBody": "www.tut.by",
"Image": "www.tut.by/img.jpg",
"TextVAlign": "middle",
"TextHAlign": "left",
"Text": "<b>example</b> button",
"TextOpacity": 10,
"TextSize": "regular"
}
]
}"""
SAMPLE_ALT_TEXT = "upgrade now!"
message = RichMediaMessage(rich_media=SAMPLE_RICH_MEDIA, alt_text=SAMPLE_ALT_TEXT)