From ac9cb3ed3dbe68f4bf9dcd9828bd7121930cf2e4 Mon Sep 17 00:00:00 2001 From: Saurabh Newatiya Date: Tue, 25 Feb 2025 12:17:52 +0530 Subject: [PATCH] SMS-7359: Adding uspport for named variables in whatsapp templates --- CHANGELOG.md | 5 ++++ README.md | 49 +++++++++++++++++++++++++++++++++++++ src/Plivo/Util/template.php | 2 ++ src/Plivo/Version.php | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae41872a..b907a200 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Change Log + +## [4.66.5](https://github.com/plivo/plivo-php/tree/v4.66.5) (2025-02-25) +**Enhancement - Supporting parameter_name in WhatsApp Template .** +- Supporting `parameter_name` in WhatsApp Template . + ## [4.66.4](https://github.com/plivo/plivo-php/tree/v4.66.4) (2025-02-18) **Enhancement** -Handle the error response from the send sms api diff --git a/README.md b/README.md index 114126ae..fb7b3543 100644 --- a/README.md +++ b/README.md @@ -271,6 +271,55 @@ print_r($response); ?> ``` +### Templated WhatsApp Messages With Named Parameter +This guide shows how to send templated WhatsApp messages with named parameters. + +Example: +```php +",""); + +$template = '{ + "name": "template_name", + "language": "en_US", + "components": [ + { + "type": "header", + "parameters": [ + { + "type": "text", + "parameter_name": "header_title", + "text": "WA-header" + } + ] + }, + { + "type": "body", + "parameters": [ + { + "type": "text", + "parameter_name": "user_name", + "text": "Saurabh" + } + ] + } + ] + }'; + +$response = $client->messages->create([ + "src" => "+14156667778", + "dst" => "+14156667777", + "type"=> "whatsapp", + "template"=> $template, + "url"=> "https://foo.com/wa_status/" +]); +print_r($response); +?> +``` + ### 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. diff --git a/src/Plivo/Util/template.php b/src/Plivo/Util/template.php index 6885294d..a6effcc2 100644 --- a/src/Plivo/Util/template.php +++ b/src/Plivo/Util/template.php @@ -54,6 +54,7 @@ class Parameter { public $currency; public $date_time; public $location; + public $parameter_name; public function __construct(array $data) { @@ -65,6 +66,7 @@ public function __construct(array $data) $this->currency = isset($data['currency'])? new Currency($data['currency']) : null; $this->date_time = isset($data['date_time']) ? new DateTime($data['date_time']) : null; $this->location = isset($data['location']) ? new Location($data['location']) : null; + $this->parameter_name = isset($data['parameter_name'])? $data['parameter_name'] : null; validateNotNullAndDataType($this->type, 'parameter', 'type', 'string', true); validateNotNullAndDataType($this->text, 'parameter', 'text', 'string'); validateNotNullAndDataType($this->media, 'parameter', 'media', 'string'); diff --git a/src/Plivo/Version.php b/src/Plivo/Version.php index b3b78598..2d4c41ec 100644 --- a/src/Plivo/Version.php +++ b/src/Plivo/Version.php @@ -26,7 +26,7 @@ class Version * @const int PHP helper library patch number */ - const PATCH = 4; + const PATCH = 5; /** * @return string