Skip to content

Commit

Permalink
Adding support for location whatsapp messages
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhnewatiya-plivo committed May 12, 2024
1 parent 3759a85 commit 59c7511
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Change Log

## [4.54.0](https://github.com/plivo/plivo-python/tree/v4.54.0) (2024-05-07)
**Feature - Adding support for location whatsapp messages**
- Added new param `location` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support location `whatsapp` messages
- Added new param `location` in templates to support location based templated messages

## [4.53.0](https://github.com/plivo/plivo-python/tree/v4.53.0) (2024-05-07)
**Minor enhancements**
- updated decorator version
Expand Down
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,68 @@ response = phlo.run()
print(response)
```

## WhatsApp Messaging
Plivo's WhatsApp API allows you to send different types of messages over WhatsApp, including templated messages, free form messages and interactive messages. Below are some examples on how to use the Plivo Go SDK to send these types of messages.

### Templated Messages
Templated messages are a crucial to your WhatsApp messaging experience, as businesses can only initiate WhatsApp conversation with their customers using templated messages.

WhatsApp templates support 4 components: `header` , `body`, `footer` and `button`. At the point of sending messages, the template object you see in the code acts as a way to pass the dynamic values within these components. `header` can accomodate `text` or `media` (images, video, documents) content. `body` can accomodate text content. `button` can support dynamic values in a `url` button or to specify a developer-defined payload which will be returned when the WhatsApp user clicks on the `quick_reply` button. `footer` cannot have any dynamic variables.

Example:
```python
```

### Free Form Messages
Non-templated or Free Form WhatsApp messages can be sent as a reply to a user-initiated conversation (Service conversation) or if there is an existing ongoing conversation created previously by sending a templated WhatsApp message.

#### Free Form Text Message
Example:
```python
```

#### Free Form Media Message
Example:
```python
```

### Interactive Messages
This guide shows how to send non-templated interactive messages to recipients using Plivo’s APIs.

#### Quick Reply Buttons
Quick reply buttons allow customers to quickly respond to your message with predefined options.

Example:
```python
```

#### Interactive Lists
Interactive lists allow you to present customers with a list of options.

Example:
```python
```

#### Interactive CTA URLs
CTA URL messages allow you to send links and call-to-action buttons.

Example:
```python
```

### Location Messages
This guide shows how to send templated and non-templated location messages to recipients using Plivo’s APIs.

#### Templated Location Messages
Example:
```python
```

#### Non-Templated Location Messages
Example:
```python
```

### More examples
Refer to the [Plivo API Reference](https://api-reference.plivo.com/latest/python/introduction/overview) for more examples. Also refer to the [guide to setting up dev environment](https://developers.plivo.com/getting-started/setting-up-dev-environment/) on [Plivo Developers Portal](https://developers.plivo.com) to setup a Flask server & use it to test out your integration in under 5 minutes. to get started with Plivo.

Expand Down
4 changes: 4 additions & 0 deletions plivo/resources/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Messages(PlivoResourceInterface):
message_expiry=[optional(of_type(*six.integer_types))],
template=[optional(is_template())],
interactive=[optional(is_interactive())],
location=[optional(is_location())],
dlt_entity_id=[optional(of_type(six.text_type))],
dlt_template_id=[optional(of_type(six.text_type))],
dlt_template_category=[optional(of_type(six.text_type))]
Expand All @@ -62,6 +63,7 @@ def create(self,
message_expiry=None,
template=None,
interactive=None,
location=None,
dlt_entity_id=None,
dlt_template_id=None,
dlt_template_category=None):
Expand All @@ -88,6 +90,8 @@ def create(self,
template = template.__dict__
if interactive is not None:
interactive = interactive.__dict__
if location is not None:
location = location.__dict__
return self.client.request('POST', ('Message', ),
to_param_dict(self.create, locals()))

Expand Down
14 changes: 14 additions & 0 deletions plivo/utils/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from plivo.utils.validators import validate_args, required, of_type_exact

class Location:
@validate_args(
latitude=[required(of_type_exact(str))],
longitude=[required(of_type_exact(str))],
name=[required(of_type_exact(str))],
address=[required(of_type_exact(str))]
)
def __init__(self, latitude, longitude, name, address):
self.latitude = latitude
self.longitude = longitude
self.name = name
self.address = address
5 changes: 4 additions & 1 deletion plivo/utils/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from plivo.utils.validators import *
from location import Location

class Parameter:
@validate_args(
Expand All @@ -8,14 +9,16 @@ class Parameter:
payload=[optional(of_type_exact(str))],
currency=[optional(of_type_exact(dict))],
date_time=[optional(of_type_exact(dict))],
location=[optional(of_type_exact(dict))],
)
def __init__(self, type, text=None, media=None, payload=None, currency=None, date_time=None):
def __init__(self, type, text=None, media=None, payload=None, currency=None, date_time=None, location=None):
self.type = type
self.text = text
self.media = media
self.payload = payload
self.currency = Currency(**currency) if currency else None
self.date_time = DateTime(**date_time) if date_time else None
self.location = Location(**location) if location else None

class Component:
@validate_args(
Expand Down
1 change: 1 addition & 0 deletions plivo/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,4 @@ def validator(arg_name, value):

is_template = functools.partial(of_type_exact,'plivo.utils.template.Template')
is_interactive = functools.partial(of_type_exact,'plivo.utils.interactive.Interactive')
is_location = functools.partial(of_type_exact,'plivo.utils.location.Location')
2 changes: 1 addition & 1 deletion plivo/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = '4.53.0'
__version__ = '4.54.0'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name='plivo',
version='4.53.0',
version='4.54.0',
description='A Python SDK to make voice calls & send SMS using Plivo and to generate Plivo XML',
long_description=long_description,
url='https://github.com/plivo/plivo-python',
Expand Down

0 comments on commit 59c7511

Please sign in to comment.