Vonage messages package
Project description
Vonage Messages Package
This package contains the code to use Vonage's Messages API in Python.
Usage
It is recommended to use this as part of the main vonage package. The examples below assume you've created an instance of the vonage.Vonage class called vonage_client.
How to Construct a Message
In order to send a message, you must construct a message object of the correct type.
from vonage_messages import Sms
message = Sms(
from_='Vonage APIs',
to='1234567890',
text='This is a test message sent from the Vonage Python SDK',
)
This message can now be sent with
vonage_client.messages.send(message)
All possible message types from every message channel have their own message model. They are named following this rule: {Channel}{MessageType}, e.g. Sms, MmsImage, RcsFile, MessengerAudio, WhatsappSticker, ViberVideo, etc.
The different message models are listed at the bottom of the page.
Some message types have submodels with additional fields. In this case, import the submodels as well and use them to construct the overall options.
e.g.
from vonage_messages import MessengerImage, MessengerOptions, MessengerResource
messenger = MessengerImage(
to='1234567890',
from_='1234567890',
image=MessengerResource(url='https://example.com/image.jpg'),
messenger=MessengerOptions(category='message_tag', tag='invalid_tag'),
)
Send a message
To send a message, access the Messages.send method via the main Vonage object, passing in an instance of a subclass of BaseMessage like this:
from vonage import Auth, Vonage
from vonage_messages import Sms
vonage_client = Vonage(Auth(application_id='my-application-id', private_key='my-private-key'))
message = Sms(
from_='Vonage APIs',
to='1234567890',
text='This is a test message sent from the Vonage Python SDK',
)
vonage_client.messages.send(message)
Mark a WhatsApp Message as Read
Note: to use this method, update the api_host attribute of the vonage_http_client.HttpClientOptions object to the API endpoint corresponding to the region where the WhatsApp number is hosted.
For example, to use the EU API endpoint, set the api_host attribute to 'api-eu.vonage.com'.
from vonage import Vonage, Auth, HttpClientOptions
auth = Auth(application_id='MY-APP-ID', private_key='MY-PRIVATE-KEY')
options = HttpClientOptions(api_host='api-eu.vonage.com')
vonage_client = Vonage(auth, options)
vonage_client.messages.mark_whatsapp_message_read('MESSAGE_UUID')
Revoke an RCS Message
Note: as above, to use this method you need to update the api_host attribute of the vonage_http_client.HttpClientOptions object to the API endpoint corresponding to the region where the WhatsApp number is hosted.
For example, to use the EU API endpoint, set the api_host attribute to 'api-eu.vonage.com'.
from vonage import Vonage, Auth, HttpClientOptions
auth = Auth(application_id='MY-APP-ID', private_key='MY-PRIVATE-KEY')
options = HttpClientOptions(api_host='api-eu.vonage.com')
vonage_client = Vonage(auth, options)
vonage_client.messages.revoke_rcs_message('MESSAGE_UUID')
Message Models
To send a message, instantiate a message model of the correct type as described above. This is a list of message models that can be used:
Sms
MmsImage, MmsVcard, MmsAudio, MmsVideo
RcsText, RcsImage, RcsVideo, RcsFile, RcsCustom
WhatsappText, WhatsappImage, WhatsappAudio, WhatsappVideo, WhatsappFile, WhatsappTemplate, WhatsappSticker, WhatsappCustom
MessengerText, MessengerImage, MessengerAudio, MessengerVideo, MessengerFile
ViberText, ViberImage, ViberVideo, ViberFile
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
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
File details
Details for the file vonage_messages-1.6.1.tar.gz.
File metadata
- Download URL: vonage_messages-1.6.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b290862f26ab1b860fcca49cd0e610dc33c55604c4e13599da93d81a96d9ea30
|
|
| MD5 |
e5d9ceffeab40a02858ba86599011e1c
|
|
| BLAKE2b-256 |
b460ae23a949150ddd51a2cbe5c16efeaad6f7de9b8bf10aa5fc1dacb7b435f6
|
File details
Details for the file vonage_messages-1.6.1-py3-none-any.whl.
File metadata
- Download URL: vonage_messages-1.6.1-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56afaa989842a7fc907b6fabdd4a653d0bd5706efd79d8283db122a02c64df45
|
|
| MD5 |
a4099e454bb3df1a48c6bb35cd801ea6
|
|
| BLAKE2b-256 |
900b098724fcaeb5d4bdfff5bc701d9d86a44bbf1cb7bf4412f2ed59eaf75fa4
|