Skip to content

xerion0712/Python-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Bot API

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:

License

This library is released under the terms of the Apache 2.0 license. See License for more information.

Library Prerequisites

  1. python >= 2.7.0
  2. 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.
  3. Active Public Account/ bot - Create an account here.
  4. 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.
  5. 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.

Let's get started!

New Api()

Param Type Description
bot_configuration object BotConfiguration

Api.set_webhook(url)

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')

Api.unset_webhook()

Returns None.

viber.unset_webhook()

Api.get_account_info()

Returns an object with the following JSON.

account_info = viber.get_account_info()

Api.verify_signature(request_data, signature)

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)

Api.send_messages(to, messages)

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")])

Api.post_messages_to_public_account(to, messages)

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")])

UserProfile object

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

Message Object

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

TextMessage object

Member Type
text string
message = TextMessage(text="my text message")

URLMessage object

Member Type Description
media string URL string
message = URLMessage(media="http://my.siteurl.com")

ContactMessage object

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)

PictureMessage object

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")

VideoMessage object

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)

LocationMessage object

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)

StickerMessage object

Member Type
sticker_id int
message = StickerMessage(sticker_id=40100)

FileMessage object

Member Type
media string
size long
file_name string
message = FileMessage(media=url, size=sizeInBytes, file_name=file_name)

RichMediaMessage object

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)

About

No description or website provided.

Topics

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE.md
Unknown
License.txt

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages