{"id":13464706,"url":"https://github.com/Viber/viber-bot-python","last_synced_at":"2025-03-25T11:32:04.624Z","repository":{"id":54816641,"uuid":"74022836","full_name":"Viber/viber-bot-python","owner":"Viber","description":"The Viber bot python library provides just what you need to develop intelligent bots that interact naturally with your Viber users.","archived":false,"fork":false,"pushed_at":"2024-03-10T15:44:05.000Z","size":170,"stargazers_count":179,"open_issues_count":27,"forks_count":99,"subscribers_count":33,"default_branch":"master","last_synced_at":"2025-03-03T02:18:28.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://developers.viber.com/","language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Viber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-17T11:59:17.000Z","updated_at":"2024-11-17T18:02:12.000Z","dependencies_parsed_at":"2024-01-16T05:46:14.234Z","dependency_job_id":"b56360eb-b52e-4e3d-b040-31ee37e71658","html_url":"https://github.com/Viber/viber-bot-python","commit_stats":{"total_commits":97,"total_committers":11,"mean_commits":8.818181818181818,"dds":0.5360824742268041,"last_synced_commit":"5cfe34e3b7d1c98afdf5d2c09a4c5722a61f008f"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Viber%2Fviber-bot-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Viber%2Fviber-bot-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Viber%2Fviber-bot-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Viber%2Fviber-bot-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Viber","download_url":"https://codeload.github.com/Viber/viber-bot-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245454123,"owners_count":20617984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T14:00:48.951Z","updated_at":"2025-03-25T11:31:59.595Z","avatar_url":"https://github.com/Viber.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Viber Python Bot API\n\nUse this library to develop a bot for Viber platform.\nThe library is available on **[GitHub](https://github.com/Viber/viber-bot-python)** as well as a package on [PyPI](https://pypi.python.org/pypi/viberbot/).\n\nThis package can be imported using pip by adding the following to your `requirements.txt`:\n\n```python\nviberbot==1.0.11\n```\n\n## License\n\nThis library is released under the terms of the Apache 2.0 license. See [License](https://github.com/Viber/viber-bot-python/blob/master/LICENSE.md) for more information.\n\n## Library Prerequisites\n\n1. python \u003e= 2.7.0\n1. 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.\n1. Active Public Account/ bot - Create an account [here](https://developers.viber.com/docs/general/get-started).\n1. 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.\n1. 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](https://developers.viber.com/blog/2017/05/24/test-your-bots-locally) on how to test your bot locally.\n\n\n## Contributing\n\nIf you think that there's a bug or there's anything else needed to be changed and you want to change it yourself, you can always create a new Pull request.  \nPlease make sure that your change doesn't break anything and all the unit tests passes.  \nAlso, please make sure that the current tests cover your change, if not please add tests.  \n  \nWe are using pytest, so if you want to run the tests from the commandline just follow the relevant steps after cloning the repo and creating your branch:  \n\n\n```\n# installing the dependencies:  \npython setup.py develop\n\n# run the unit tests\npython -m pytest\n``` \n\n## Let's get started!\n\n\n### Installing\n\nCreating a basic Viber bot is simple:\n\n1. Install the library with pip `pip install viberbot`\n2. Import `viberbot.api` library to your project\n3. Create a Public Account or bot and use the API key from [https://developers.viber.com](https://developers.viber.com)\n4. Configure your bot as described in the documentation below\n5. Start your web server\n6. Call `set_webhook(url)` with your web server url\n\n## A simple Echo Bot\n\n### Firstly, let's import and configure our bot\n\n```python\nfrom viberbot import Api\nfrom viberbot.api.bot_configuration import BotConfiguration\n\nbot_configuration = BotConfiguration(\n\tname='PythonSampleBot',\n\tavatar='http://viber.com/avatar.jpg',\n\tauth_token='YOUR_AUTH_TOKEN_HERE'\n)\nviber = Api(bot_configuration)\n```\n\n### Create an HTTPS server\n\nNext thing you should do is starting a https server.\nand yes, as we said in the prerequisites it has to be https server. Create a server however you like, for example with `Flask`:\n\n```python\nfrom flask import Flask, request, Response\n\napp = Flask(__name__)\n\n@app.route('/incoming', methods=['POST'])\ndef incoming():\n\tlogger.debug(\"received request. post data: {0}\".format(request.get_data()))\n\t# handle the request here\n\treturn Response(status=200)\n\ncontext = ('server.crt', 'server.key')\napp.run(host='0.0.0.0', port=443, debug=True, ssl_context=context)\n```\n\n### Setting a webhook\n\nAfter the server is up and running you can set a webhook.\nViber will push messages sent to this URL. web server should be internet-facing.\n\n```python\nviber.set_webhook('https://mybotwebserver.com:443/')\n```\n\n### Logging\n\nThis library uses the standard python logger. If you want to see its logs you can configure the logger:\n\n```python\nlogger = logging.getLogger()\nlogger.setLevel(logging.DEBUG)\nhandler = logging.StreamHandler()\nformatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')\nhandler.setFormatter(formatter)\nlogger.addHandler(handler)\n```\n\n### Do you supply a basic types of messages?\nWell, funny you ask. Yes we do. All the Message types are located in `viberbot.api.messages` package. Here's some examples:\n\n```python\nfrom viberbot.api.messages import (\n    TextMessage,\n    ContactMessage,\n    PictureMessage,\n    VideoMessage\n)\nfrom viberbot.api.messages.data_types.contact import Contact\n\n# creation of text message\ntext_message = TextMessage(text=\"sample text message!\")\n\n# creation of contact message\ncontact = Contact(name=\"Viber user\", phone_number=\"0123456789\")\ncontact_message = ContactMessage(contact=contact)\n\n# creation of picture message\npicture_message = PictureMessage(text=\"Check this\", media=\"http://site.com/img.jpg\")\n\n# creation of video message\nvideo_message = VideoMessage(media=\"http://mediaserver.com/video.mp4\", size=4324)\n```\n\nHave you noticed how we created the `TextMessage`? There's a all bunch of message types you should get familiar with.\n\n* [Text Message](#TextMessage)\n* [Url Message](#UrlMessage)\n* [Contact Message](#ContactMessage)\n* [Picture Message](#PictureMessage)\n* [Video Message](#VideoMessage)\n* [Location Message](#LocationMessage)\n* [Sticker Message](#StickerMessage)\n* [Rich Media Message](#RichMediaMessage)\n* [Keyboard Message](#KeyboardMessage)\n\nCreating them is easy! Every message object has it's own unique constructor corresponding to it's API implementation, click on them to see it!\nCheck out the full API documentation for more advanced uses.\n\n### Let's add it all up and reply with a message!\n\n```python\nfrom flask import Flask, request, Response\nfrom viberbot import Api\nfrom viberbot.api.bot_configuration import BotConfiguration\nfrom viberbot.api.messages import VideoMessage\nfrom viberbot.api.messages.text_message import TextMessage\nimport logging\n\nfrom viberbot.api.viber_requests import ViberConversationStartedRequest\nfrom viberbot.api.viber_requests import ViberFailedRequest\nfrom viberbot.api.viber_requests import ViberMessageRequest\nfrom viberbot.api.viber_requests import ViberSubscribedRequest\nfrom viberbot.api.viber_requests import ViberUnsubscribedRequest\n\napp = Flask(__name__)\nviber = Api(BotConfiguration(\n    name='PythonSampleBot',\n    avatar='http://site.com/avatar.jpg',\n    auth_token='445da6az1s345z78-dazcczb2542zv51a-e0vc5fva17480im9'\n))\n\n\n@app.route('/', methods=['POST'])\ndef incoming():\n    logger.debug(\"received request. post data: {0}\".format(request.get_data()))\n    # every viber message is signed, you can verify the signature using this method\n    if not viber.verify_signature(request.get_data(), request.headers.get('X-Viber-Content-Signature')):\n        return Response(status=403)\n\n    # this library supplies a simple way to receive a request object\n    viber_request = viber.parse_request(request.get_data())\n\n    if isinstance(viber_request, ViberMessageRequest):\n        message = viber_request.message\n        # lets echo back\n        viber.send_messages(viber_request.sender.id, [\n            message\n        ])\n    elif isinstance(viber_request, ViberSubscribedRequest):\n        viber.send_messages(viber_request.get_user.id, [\n            TextMessage(text=\"thanks for subscribing!\")\n        ])\n    elif isinstance(viber_request, ViberFailedRequest):\n        logger.warn(\"client failed receiving message. failure: {0}\".format(viber_request))\n\n    return Response(status=200)\n\nif __name__ == \"__main__\":\n    context = ('server.crt', 'server.key')\n    app.run(host='0.0.0.0', port=443, debug=True, ssl_context=context)\n```\n\nAs you can see there's a bunch of `Request` types here's a list of them.\n\n## Viber API\n\n### Api class\n\n`from viberbot import Api`\n\n* Api\n    * [init(bot\\_configuration)](#new-Api())\n    * [.set\\_webhook(url, webhook_events)](#set_webhook) ⇒ `List of registered event_types`\n    * [.unset\\_webhook()](#unset_webhook) ⇒ `None`\n    * [.get\\_account_info()](#get_account_info) ⇒ `object`\n    * [.verify\\_signature(request\\_data, signature)](#verify_signature) ⇒ `boolean`\n    * [.parse\\_request(request\\_data)](#parse_request) ⇒ `ViberRequest`\n    * [.send\\_messages(to, messages)](#send_messages) ⇒ `list of message tokens sent`\n    * [.get\\_online(viber\\_user\\_ids)](#get_online) ⇒ `dictionary of users status`\n    * [.get\\_user_details(viber\\_user\\_id)](#get_user_details) ⇒ `dictionary of user's data`\n    * [.post\\_messages\\_to\\_public\\_account(to, messages)](#post_to_pa) ⇒ `list of message tokens sent`\n\n\u003ca name=\"new-Api()\"\u003e\u003c/a\u003e\n\n### New Api()\n\n| Param | Type | Description |\n| --- | --- | --- |\n| bot\\_configuration | `object` | `BotConfiguration` |\n\n\u003ca name=\"set_webhook\"\u003e\u003c/a\u003e\n\n### Api.set\\_webhook(url)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| url | `string` | Your web server url |\n| webhook\\_events | `list` | optional list of subscribed events |\n\nReturns `List of registered event_types`. \n\n```python\nevent_types = viber.set_webhook('https://example.com/incoming')\n```\n\n\u003ca name=\"unset_webhook\"\u003e\u003c/a\u003e\n\n### Api.unset\\_webhook()\n\nReturns `None`. \n\n```python\nviber.unset_webhook()\n```\n\n\u003ca name=\"get_account_info\"\u003e\u003c/a\u003e\n\n### Api.get\\_account\\_info()\n\nReturns an `object` [with the following JSON](https://developers.viber.com/docs/api/rest-bot-api/#get-account-info). \n\n```python\naccount_info = viber.get_account_info()\n```\n\n\u003ca name=\"verify_signature\"\u003e\u003c/a\u003e\n\n### Api.verify\\_signature(request\\_data, signature)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| request\\_data | `string` | the post data from request |\n| signature | `string` | sent as header `X-Viber-Content-Signature` |\n\n\nReturns a `boolean` suggesting if the signature is valid. \n\n```python\nif not viber.verify_signature(request.get_data(), request.headers.get('X-Viber-Content-Signature')):\n\treturn Response(status=403)\n```\n\n\u003ca name=\"parse_request\"\u003e\u003c/a\u003e\n\n### Api.parse\\_request(request\\_data)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| request\\_data | `string` | the post data from request |\n\nReturns a `ViberRequest` object. \n\nThere's a list of [ViberRequest objects](#ViberRequest)\n\n```python\nviber_request = viber.parse_request(request.get_data())\n```\n\n\u003ca name=\"send_messages\"\u003e\u003c/a\u003e\n\n### Api.send\\_messages(to, messages)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| to | `string` | Viber user id |\n| messages | `list` | list of `Message` objects |\n\nReturns `list` of message tokens of the messages sent. \n\n```python\ntokens = viber.send_messages(to=viber_request.get_sender().get_id(),\n\t\t\t     messages=[TextMessage(text=\"sample message\")])\n```\n\n\u003ca name=\"post_to_pa\"\u003e\u003c/a\u003e\n\n### Api.post\\_messages\\_to\\_public\\_account(to, messages)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| sender | `string` | Viber user id |\n| messages | `list` | list of `Message` objects |\n\nReturns `list` of message tokens of the messages sent. \n\n```python\ntokens = viber.post_messages_to_public_account(sender=viber_request.get_sender().get_id(),\n\t\t\t     messages=[TextMessage(text=\"sample message\")])\n```\n\n\u003ca name=\"get_online\"\u003e\u003c/a\u003e\n\n### Api.get\\_online(viber\\_user\\_ids)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| viber\\_user\\_ids | `array of strings` | Array of Viber user ids |\n\nReturns a `dictionary of users`.\n\n```python\nusers = Api.get_online([\"user1id\", \"user2id\"])\n```\n\n\u003ca name=\"get_user_details\"\u003e\u003c/a\u003e\n\n### Api.get\\_user\\_details(viber\\_user\\_id)\n\n| Param | Type | Description |\n| --- | --- | --- |\n| viber\\_user\\_ids | `string` | Viber user id |\n\nThe `get_user_details` function will fetch the details of a specific Viber user based on his unique user ID. The user ID can be obtained from the callbacks sent to the account regarding user's actions. This request can be sent twice during a 12 hours period for each user ID.\n\n```python\nuser_data = Api.get_user_details(\"userId\")\n```\n\n\u003ca name=\"ViberRequest\"\u003e\u003c/a\u003e\n\n### Request object\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | according to `EventTypes` enum |\n| timestamp | `long` | Epoch of request time |\n\n* ViberRequest\n    * .event\\_type ⇒ `string `\n    * .timestamp ⇒ `long`\n\n\u003ca name=\"ConversationStarted\"\u003e\u003c/a\u003e\n\n#### ViberConversationStartedRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\nConversation started event fires when a user opens a conversation with the Public Account/ bot using the “message” button (found on the account’s info screen) or using a [deep link](https://developers.viber.com/docs/tools/deep-links).\n\nThis event is **not** considered a subscribe event and doesn't allow the account to send messages to the user; however, it will allow sending one \"welcome message\" to the user. See [sending a welcome message](#SendingWelcomeMessage) below for more information. \n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.CONVERSATION_STARTED` |\n| message\\_token | `string` | Unique ID of the message |\n| type | `string` | The specific type of `conversation_started` event. |\n| context | `string` | Any additional parameters added to the deep link used to access the conversation passed as a string |\n| user | `UserProfile` | the user started the conversation [UserProfile](#UserProfile) |\n| subscribed | `boolean` | Indicates whether a user is already subscribed |\n\n* ViberConversationStartedRequest\n    * message\\_token ⇒ `string`\n    * type ⇒ `string`\n    * context ⇒ `string`\n    * user ⇒ `UserProfile`\n\n#### ViberDeliveredRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.DELIVERED` |\n| message\\_token | `string` | Unique ID of the message |\n| user\\_id | `string` | Unique Viber user id |\n\n* ViberDeliveredRequest\n    * message\\_token ⇒ `string`\n    * user\\_id ⇒ `string`\n\n#### ViberFailedRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.FAILED` |\n| message\\_token | `string` | Unique ID of the message |\n| user\\_id | `string` | Unique Viber user id |\n| desc | `string` | Failure description |\n\n* ViberFailedRequest\n    * message\\_token ⇒ `string`\n    * user\\_id ⇒ `string`\n    * desc ⇒ `string`\n\n#### ViberMessageRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.MESSAGE` |\n| message\\_token | `string` | Unique ID of the message |\n| message | `Message` | `Message` object |\n| sender | `UserProfile` | the user started the conversation [UserProfile](#UserProfile) |\n\n* ViberMessageRequest\n    * message\\_token ⇒ `string`\n    * message ⇒ `Message`\n    * sender ⇒ `UserProfile`\n\n#### ViberSeenRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.SEEN` |\n| message\\_token | `string` | Unique ID of the message |\n| user\\_id | `string` | Unique Viber user id |\n\n* ViberSeenRequest\n    * message\\_token ⇒ `string`\n    * user\\_id ⇒ `string`\n\n#### ViberSubscribedRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.SUBSCRIBED` |\n| user | `UserProfile` | the user started the conversation [UserProfile](#UserProfile) |\n\n* ViberSubscribedRequest\n    * user ⇒ `UserProfile`\n\n#### ViberUnsubscribedRequest object\n\nInherits from [ViberRequest](#ViberRequest)\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| event\\_type | `string` | always equals to the value of `EventType.UNSUBSCRIBED` |\n| user\\_id | `string` | Unique Viber user id |\n\n* ViberUnsubscribedRequest\n    * get\\_user\\_id() ⇒ `string`\n\n\u003ca name=\"UserProfile\"\u003e\u003c/a\u003e\n\n### UserProfile object\n\n| Param | Type | Notes |\n| --- | --- | --- |\n| id | `string` | --- |\n| name | `string` | --- |\n| avatar | `string` | Avatar URL |\n| country | `string` | **currently set in `CONVERSATION_STARTED` event only** |\n| language | `string` | **currently set in `CONVERSATION_STARTED` event only** |\n\n\u003ca name=\"MessageObject\"\u003e\u003c/a\u003e\n\n### Message Object\n\n**Common Members for `Message` interface**:\n\n| Param | Type | Description |\n| --- | --- | --- |\n| timestamp | `long` | Epoch time |\n| keyboard | `JSON` | keyboard JSON |\n| trackingData | `JSON` | JSON Tracking Data from Viber Client |\n\n**Common Constructor Arguments `Message` interface**:\n\n| Param | Type | Description |\n| --- | --- | --- |\n| optionalKeyboard | `JSON` | [Writing Custom Keyboards](https://developers.viber.com/docs/tools/keyboards) |\n| optionalTrackingData | `JSON` | Data to be saved on Viber Client device, and sent back each time message is received |\n\n\u003ca name=\"TextMessage\"\u003e\u003c/a\u003e\n\n#### TextMessage object\n\n| Member | Type\n| --- | --- |\n| text | `string` |\n\n```python\nmessage = TextMessage(text=\"my text message\")\n```\n\n\u003ca name=\"UrlMessage\"\u003e\u003c/a\u003e\n\n#### URLMessage object\n\n| Member | Type | Description |\n| --- | --- | --- |\n| media | `string` | URL string |\n\n```python\nmessage = URLMessage(media=\"http://my.siteurl.com\")\n```\n\n\u003ca name=\"ContactMessage\"\u003e\u003c/a\u003e\n\n#### ContactMessage object\n\n| Member | Type\n| --- | --- |\n| contact | `Contact` |\n\n```python\nfrom viberbot.api.messages.data_types.contact import Contact\n\ncontact = Contact(name=\"Viber user\", phone_number=\"+0015648979\", avatar=\"http://link.to.avatar\")\ncontact_message = ContactMessage(contact=contact)\n```\n\n\u003ca name=\"PictureMessage\"\u003e\u003c/a\u003e\n\n#### PictureMessage object\n\n| Member | Type | Description |\n| --- | --- | --- |\n| media | `string` | url of the message (jpeg only) |\n| text | `string` |  |\n| thumbnail | `string` |  |\n\n```python\nmessage = PictureMessage(media=\"http://www.thehindubusinessline.com/multimedia/dynamic/01458/viber_logo_JPG_1458024f.jpg\", text=\"Viber logo\")\n```\n\n\u003ca name=\"VideoMessage\"\u003e\u003c/a\u003e\n\n#### VideoMessage object\n\n| Member | Type | Description |\n| --- | --- | --- |\n| media | `string` | url of the video |\n| size | `int` |  |\n| thumbnail | `string` |  |\n| duration | `int` |  |\n\n```python\nmessage = VideoMessage(media=\"http://site.com/video.mp4\", size=21499)\n```\n\n\u003ca name=\"LocationMessage\"\u003e\u003c/a\u003e\n\n#### LocationMessage object\n\n| Member | Type\n| --- | --- |\n| location | `Location` |\n\n```python\nfrom viberbot.api.messages.data_types.location import Location\n\nlocation = Location(lat=0.0, lon=0.0)\nlocation_message = LocationMessage(location=location)\n```\n\n\u003ca name=\"StickerMessage\"\u003e\u003c/a\u003e\n\n#### StickerMessage object\n\n| Member | Type\n| --- | --- |\n| sticker\\_id | `int` |\n\n```python\nmessage = StickerMessage(sticker_id=40100)\n```\n\n\u003ca name=\"FileMessage\"\u003e\u003c/a\u003e\n\n#### FileMessage object\n\n| Member | Type\n| --- | --- |\n| media | `string` |\n| size | `long` |\n| file\\_name | `string` |\n\n```python\nmessage = FileMessage(media=url, size=sizeInBytes, file_name=file_name)\n```\n\n\u003ca name=\"RichMediaMessage\"\u003e\u003c/a\u003e\n\n#### RichMediaMessage object\n\n| Member | Type\n| --- | --- |\n| rich\\_media | `string` (JSON) |\n\n```python\nSAMPLE_RICH_MEDIA = \"\"\"{\n  \"BgColor\": \"#69C48A\",\n  \"Buttons\": [\n    {\n      \"Columns\": 6,\n      \"Rows\": 1,\n      \"BgColor\": \"#454545\",\n      \"BgMediaType\": \"gif\",\n      \"BgMedia\": \"http://www.url.by/test.gif\",\n      \"BgLoop\": true,\n      \"ActionType\": \"open-url\",\n      \"Silent\": true,\n      \"ActionBody\": \"www.tut.by\",\n      \"Image\": \"www.tut.by/img.jpg\",\n      \"TextVAlign\": \"middle\",\n      \"TextHAlign\": \"left\",\n      \"Text\": \"\u003cb\u003eexample\u003c/b\u003e button\",\n      \"TextOpacity\": 10,\n      \"TextSize\": \"regular\"\n    }\n  ]\n}\"\"\"\n\nSAMPLE_ALT_TEXT = \"upgrade now!\"\n\nmessage = RichMediaMessage(rich_media=SAMPLE_RICH_MEDIA, alt_text=SAMPLE_ALT_TEXT)\n```\n\n\u003ca name=\"KeyboardMessage\"\u003e\u003c/a\u003e\n\n#### KeyboardMessage object\n\n| Member | Type\n| --- | --- |\n| keyboard | `JSON` |\n| tracking_data | `JSON` |\n\n```python\nmessage = KeyboardMessage(tracking_data=tracking_data, keyboard=keyboard)\n```\n\n\u003ca name=\"SendingWelcomeMessage\"\u003e\u003c/a\u003e\n\n### Sending a welcome message\n\nThe Viber API allows sending messages to users only after they subscribe to the account. However, Viber will allow the account to send one “welcome message” to a user as the user opens the conversation, before the user subscribes.\n\nThe welcome message will be sent as a response to a `conversation_started` callback, which will be received from Viber once the user opens the conversation with the account. To learn more about this event and when is it triggered see [`Conversation started`](#ConversationStarted) in the callbacks section.\n\n#### Welcome message flow\n\nSending a welcome message will be done according to the following flow:\n\n1. User opens 1-on-1 conversation with account.\n2. Viber server send `conversation_started` even to PA’s webhook.\n3. The account receives the `conversation_started` and responds with an HTTP response which includes the welcome message as the response body.\n\nThe welcome message will be a JSON constructed according to the send_message requests structure, but without the `receiver` parameter. An example welcome message would look like this:\n\n```python\n@app.route('/', methods=['POST'])\ndef incoming():\n\tviber_request = viber.parse_request(request.get_data())\n\n\tif isinstance(viber_request, ViberConversationStartedRequest) :\n\t\tviber.send_messages(viber_request.get_user().get_id(), [\n\t\t\tTextMessage(text=\"Welcome!\")\n\t\t])\n\n\treturn Response(status=200)\n```\n\n## Community\n\nJoin the conversation on **[Gitter](https://gitter.im/viber/bot-python)**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FViber%2Fviber-bot-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FViber%2Fviber-bot-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FViber%2Fviber-bot-python/lists"}