From 1de32bdf8354161aa5a981d3b757829c5b512c8b Mon Sep 17 00:00:00 2001 From: Vishnu Date: Tue, 25 Feb 2025 10:38:05 +0530 Subject: [PATCH 1/2] add new parameter for templated mesg --- CHANGELOG.md | 4 ++++ README.md | 41 +++++++++++++++++++++++++++++++++++++++++ plivo/utils/template.py | 6 ++++-- plivo/version.py | 2 +- setup.py | 2 +- 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a64ef3e7..1fe8a67f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Change Log +## [4.58.6](https://github.com/plivo/plivo-python/tree/v4.58.6) (2025-02-25) +**Enhancement - Supporting parameter_name in WhatsApp Template .** +- Supporting parameter_name in WhatsApp Template . + ## [4.58.5](https://github.com/plivo/plivo-python/tree/v4.58.5) (2025-02-18) **Feature - Throw GeoPermissionError on synchronous geopermissions error** diff --git a/README.md b/README.md index 725823a0..b3398a42 100644 --- a/README.md +++ b/README.md @@ -467,6 +467,47 @@ response= client.messages.create( print(response) ``` +#### Templated WhatsApp Messages With Named Parameter +This guide shows how to send templated WhatsApp messages with named parameters. + +Example: +```python +import plivo +from plivo.utils.template import Template + +client = plivo.RestClient('','') + +template=Template(**{ + "name": "plivo_order_pickup_named_param", + "language": "en_US", + "components": [ + { + "type": "header", + "parameters": [ + { + "type": "location", + "parameter_name": "named_param_in_header", + "location": { + "longitude": "122.148981", + "latitude": "37.483307", + "name": "Pablo Morales", + "address": "1 Hacker Way, Menlo Park, CA 94025" + } + } + ] + } + ] + }) + +response= client.messages.create( + src="the_from_number", + dst="the_to_number", + type_="whatsapp", + template=template +) +print(response) +``` + ### More examples Refer to the [Plivo API Reference](https://www.plivo.com/docs/messaging/api/overview/) for more examples. Also refer to the [guide to setting up dev environment](https://www.plivo.com/docs/messaging/quickstart/python-flask/) on [Plivo Developers Portal](https://www.plivo.com/docs/) to setup a Flask server & use it to test out your integration in under 5 minutes. to get started with Plivo. diff --git a/plivo/utils/template.py b/plivo/utils/template.py index f3b58229..eb0ad081 100644 --- a/plivo/utils/template.py +++ b/plivo/utils/template.py @@ -9,9 +9,10 @@ class Parameter: payload=[optional(of_type_exact(str))], currency=[optional(of_type_exact(dict))], date_time=[optional(of_type_exact(dict))], - location=[optional(validate_dict_items(Location))] + location=[optional(validate_dict_items(Location))], + parameter_name=[optional(of_type_exact(str))], ) - def __init__(self, type, text=None, media=None, payload=None, currency=None, date_time=None, location=None): + def __init__(self, type, text=None, media=None, payload=None, currency=None, date_time=None, location=None, parameter_name=None): self.type = type self.text = text self.media = media @@ -19,6 +20,7 @@ def __init__(self, type, text=None, media=None, payload=None, currency=None, dat self.currency = Currency(**currency) if currency else None self.date_time = DateTime(**date_time) if date_time else None self.location = location + self.parameter_name = parameter_name class Component: @validate_args( diff --git a/plivo/version.py b/plivo/version.py index 386a7835..8e4576dd 100644 --- a/plivo/version.py +++ b/plivo/version.py @@ -1,2 +1,2 @@ # -*- coding: utf-8 -*- -__version__ = '4.58.5' +__version__ = '4.58.6' diff --git a/setup.py b/setup.py index 655f6de9..48a4bcfb 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ setup( name='plivo', - version='4.58.5', + version='4.58.6', 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', From f43a403274b81f89d8a0eb5bbadb46db247449b1 Mon Sep 17 00:00:00 2001 From: Vishnu Date: Tue, 25 Feb 2025 12:21:00 +0530 Subject: [PATCH 2/2] fixing example --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b3398a42..a831b15f 100644 --- a/README.md +++ b/README.md @@ -478,23 +478,28 @@ from plivo.utils.template import Template client = plivo.RestClient('','') template=Template(**{ - "name": "plivo_order_pickup_named_param", + "name": "template_name", "language": "en_US", "components": [ { "type": "header", "parameters": [ { - "type": "location", - "parameter_name": "named_param_in_header", - "location": { - "longitude": "122.148981", - "latitude": "37.483307", - "name": "Pablo Morales", - "address": "1 Hacker Way, Menlo Park, CA 94025" - } + "type": "text", + "parameter_name": "header_title", + "text": "WA-header" } ] + }, + { + "type": "body", + "parameters": [ + { + "type": "text", + "parameter_name": "user_name", + "text": "Saurabh" + } + ] } ] })