From 45747cdd463c93a11ddb07c77f772831b203979a Mon Sep 17 00:00:00 2001 From: Saurabh Newatiya Date: Sun, 12 May 2024 12:46:38 +0530 Subject: [PATCH 1/6] Adding support for location whatsapp messages --- CHANGELOG.md | 5 + README.md | 64 ++++++++- src/Plivo/Plivo.csproj | 2 +- src/Plivo/Plivo.nuspec | 3 +- .../Resource/Message/MessageInterface.cs | 125 ++++++++++++++++-- src/Plivo/Version.cs | 2 +- version.json | 2 +- 7 files changed, 190 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53224527..62bed943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [5.46.0](https://github.com/plivo/plivo-dotnet/tree/v5.46.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 + ## [5.45.0](https://github.com/plivo/plivo-dotnet/tree/v5.45.0) (2024-05-07) **Feature - Adding support for interactive whatsapp messages** - Added new param `interactive` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support interactive `whatsapp` messages diff --git a/README.md b/README.md index 79ad7e6a..c6b3436a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ You can install this SDK either by referencing the .dll file or using NuGet. Use the following line to install the latest SDK using the NuGet CLI. ``` -PM> Install-Package Plivo -Version 5.45.0 +PM> Install-Package Plivo -Version 5.46.0 ``` You can also use the .NET CLI to install this package as follows @@ -119,6 +119,68 @@ This generates the following XML: ``` +## 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: +```csharp +``` + +### 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: +```csharp +``` + +#### Free Form Media Message +Example: +```csharp +``` + +### 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: +```csharp +``` + +#### Interactive Lists +Interactive lists allow you to present customers with a list of options. + +Example: +```csharp +``` + +#### Interactive CTA URLs +CTA URL messages allow you to send links and call-to-action buttons. + +Example: +```csharp +``` + +### Location Messages +This guide shows how to send templated and non-templated location messages to recipients using Plivo’s APIs. + +#### Templated Location Messages +Example: +```csharp +``` + +#### Non-Templated Location Messages +Example: +```csharp +``` + ### More examples Refer to the [Plivo API Reference](https://api-reference.plivo.com/latest/net/introduction/overview) for more examples. diff --git a/src/Plivo/Plivo.csproj b/src/Plivo/Plivo.csproj index ebca8e83..63e20c18 100644 --- a/src/Plivo/Plivo.csproj +++ b/src/Plivo/Plivo.csproj @@ -1,7 +1,7 @@ netstandard2.0;netstandard1.3 - 5.45.0 + 5.46.0 Plivo SDKs Team Plivo Inc. diff --git a/src/Plivo/Plivo.nuspec b/src/Plivo/Plivo.nuspec index a5f80314..5c310c63 100644 --- a/src/Plivo/Plivo.nuspec +++ b/src/Plivo/Plivo.nuspec @@ -4,7 +4,7 @@ A .NET SDK to make voice calls and send SMS using Plivo and to generate Plivo XML A .NET SDK to make voice calls and send SMS using Plivo and to generate Plivo XML Plivo - 5.45.0 + 5.46.0 Plivo Plivo SDKs Team Plivo, Inc. @@ -12,6 +12,7 @@ http://github.com/plivo/plivo-dotnet false + * 5.46.0 Added new param `location` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support location `whatsapp` messages. Also added new param `location` in templates to support location based templated messages * 5.45.0 Added new param `interactive` to in send message API to support interactive `whatsapp` messages * 5.44.0 Added new param `payload` in templates to support dynamic payload in templates * 5.43.2 Added New Param `declined_reasons` for GET and LIST Brand. diff --git a/src/Plivo/Resource/Message/MessageInterface.cs b/src/Plivo/Resource/Message/MessageInterface.cs index 0a86896e..5857e581 100755 --- a/src/Plivo/Resource/Message/MessageInterface.cs +++ b/src/Plivo/Resource/Message/MessageInterface.cs @@ -46,11 +46,16 @@ public MessageInterface(HttpClient client) : base(client) /// template_json_string /// interactive /// interactive_json_string + /// location + /// location_json_string public MessageCreateResponse Create( List dst, string text = null, string src = null, string type = null, string url = null, string method = null, object log = null, bool? trackable = null, string powerpack_uuid = null, string[] media_urls = null, string[] media_ids = null, - string dlt_entity_id = null, string dlt_template_id = null, string dlt_template_category = null, Template template = null, string template_json_string = null, Interactive interactive = null, string interactive_json_string = null) + string dlt_entity_id = null, string dlt_template_id = null, string dlt_template_category = null, + Template template = null, string template_json_string = null, + Interactive interactive = null, string interactive_json_string = null, + Location location = null, string location_json_string = null) { // Check if log is a boolean string logString=""; @@ -114,6 +119,22 @@ public MessageInterface(HttpClient client) : base(client) { return getResponseValidation("Interactive paramater is only applicable when type is whatsapp."); } + if (location_json_string != null && location != null) + { + return getResponseValidation("Location parameter is already set."); + } + else + { + if (location_json_string != null) + { + var settings = new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore}; + location = JsonConvert.DeserializeObject(location_json_string, settings); + } + } + if (location != null && type != null && type != "whatsapp") + { + return getResponseValidation("Location paramater is only applicable when type is whatsapp."); + } if (src != null && powerpack_uuid == null) { data = CreateData( @@ -134,7 +155,8 @@ public MessageInterface(HttpClient client) : base(client) dlt_template_id, dlt_template_category, template, - interactive + interactive, + location }); } else if (powerpack_uuid != null && src == null) @@ -199,11 +221,16 @@ public MessageInterface(HttpClient client) : base(client) /// template_json_string /// interactive /// interactive_json_string + /// location + /// location_json_string public async Task CreateAsync( List dst, string text = null, string src = null, string type = null, string url = null, string method = null, object log = null, bool? trackable = null, string powerpack_uuid = null, string[] media_urls = null, string[] media_ids = null, - string dlt_entity_id = null, string dlt_template_id = null, string dlt_template_category = null, Template template = null, string template_json_string = null, Interactive interactive = null, string interactive_json_string = null) + string dlt_entity_id = null, string dlt_template_id = null, string dlt_template_category = null, + Template template = null, string template_json_string = null, + Interactive interactive = null, string interactive_json_string = null, + Location location = null, string location_json_string = null) { // Check if log is a boolean string logString=""; @@ -268,6 +295,22 @@ public MessageInterface(HttpClient client) : base(client) { return getResponseValidation("Interactive paramater is only applicable when type is whatsapp."); } + if (location_json_string != null && location != null) + { + return getResponseValidation("Location parameter is already set."); + } + else + { + if (location_json_string != null) + { + var settings = new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore}; + location = JsonConvert.DeserializeObject(location_json_string, settings); + } + } + if (location != null && type != null && type != "whatsapp") + { + return getResponseValidation("Location paramater is only applicable when type is whatsapp."); + } if (src != null && powerpack_uuid == null) { data = CreateData( @@ -288,7 +331,8 @@ public MessageInterface(HttpClient client) : base(client) dlt_template_id, dlt_template_category, template, - interactive + interactive, + locaation }); } else if (powerpack_uuid != null && src == null) @@ -355,12 +399,17 @@ public MessageInterface(HttpClient client) : base(client) /// template_json_string /// interactive /// interactive_json_string + /// location + /// location_json_string public MessageCreateResponse Create( string dst, string text = null, string src = null, string type = null, string url = null, string method = null, object log = null, bool? trackable = null, string powerpack_uuid = null, string[] media_urls = null, string[] media_ids = null, uint? message_expiry = null, string dlt_entity_id = null, string dlt_template_id = null, - string dlt_template_category = null, Template template = null, string template_json_string = null, Interactive interactive = null, string interactive_json_string = null) + string dlt_template_category = null, + Template template = null, string template_json_string = null, + Interactive interactive = null, string interactive_json_string = null, + Location location = null, string location_json_string = null) { string logString=""; if (log is bool) @@ -422,6 +471,22 @@ public MessageInterface(HttpClient client) : base(client) { return getResponseValidation("Interactive paramater is only applicable when type is whatsapp."); } + if (location_json_string != null && location != null) + { + return getResponseValidation("Location parameter is already set."); + } + else + { + if (location_json_string != null) + { + var settings = new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore}; + location = JsonConvert.DeserializeObject(location_json_string, settings); + } + } + if (location != null && type != null && type != "whatsapp") + { + return getResponseValidation("Location paramater is only applicable when type is whatsapp."); + } if (src != null && powerpack_uuid == null) { data = CreateData( @@ -443,7 +508,8 @@ public MessageInterface(HttpClient client) : base(client) dlt_template_id, dlt_template_category, template, - interactive + interactive, + location }); } else if (powerpack_uuid != null && src == null) @@ -510,12 +576,17 @@ public MessageInterface(HttpClient client) : base(client) /// template /// interactive /// interactive_json_string + /// location + /// location_json_string public async Task CreateAsync( string dst, string text = null, string src = null, string type = null, string url = null, string method = null, object log = null, bool? trackable = null, string powerpack_uuid = null, string[] media_urls = null, string[] media_ids = null, uint? message_expiry = null, string dlt_entity_id = null, string dlt_template_id = null, - string dlt_template_category = null, Template template = null, string template_json_string = null, Interactive interactive = null, string interactive_json_string = null) + string dlt_template_category = null, + Template template = null, string template_json_string = null, + Interactive interactive = null, string interactive_json_string = null, + Location location = null, string location_json_string = null) { string logString=""; if (log is bool) @@ -578,6 +649,22 @@ public MessageInterface(HttpClient client) : base(client) { return getResponseValidation("Interactive paramater is only applicable when type is whatsapp."); } + if (location_json_string != null && location != null) + { + return getResponseValidation("Location parameter is already set."); + } + else + { + if (location_json_string != null) + { + var settings = new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore}; + location = JsonConvert.DeserializeObject(location_json_string, settings); + } + } + if (location != null && type != null && type != "whatsapp") + { + return getResponseValidation("Location paramater is only applicable when type is whatsapp."); + } if (src != null && powerpack_uuid == null) { data = CreateData( @@ -599,7 +686,8 @@ public MessageInterface(HttpClient client) : base(client) dlt_template_id, dlt_template_category, template, - interactive + interactive, + loactaion }); } else if (powerpack_uuid != null && src == null) @@ -976,6 +1064,12 @@ public class Parameter /// [JsonProperty("date_time")] public DateTimeValue DateTime { get; set; } + + /// + /// Gets or sets the location value of the parameter. + /// + [JsonProperty("location")] + public Location Location { get; set; } } public class Currency @@ -1094,4 +1188,19 @@ public class Row [JsonProperty("description")] public string Description { get; set; } } + + public class Location + { + [JsonProperty("latitude")] + public string Latitude { get; set; } + + [JsonProperty("longitude")] + public string Longitude { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("address")] + public string Address { get; set; } + } } diff --git a/src/Plivo/Version.cs b/src/Plivo/Version.cs index 7ce02487..8700e756 100644 --- a/src/Plivo/Version.cs +++ b/src/Plivo/Version.cs @@ -10,7 +10,7 @@ public class Version /// /// DotNet SDK version /// - public const string SdkVersion = "5.45.0"; + public const string SdkVersion = "5.46.0"; /// /// Plivo API version /// diff --git a/version.json b/version.json index 3200e278..5e0ebe7f 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { - "version": "5.45.0", + "version": "5.46.0", "publicReleaseRefSpec": [ "^refs/heads/master$", "^refs/heads/v\\d+(?:\\.\\d+)?$" From b5ae1f761733ccb225ded93f1ae736becb00b964 Mon Sep 17 00:00:00 2001 From: Saurabh Newatiya Date: Thu, 16 May 2024 17:01:24 +0530 Subject: [PATCH 2/6] removing type check for whatsapp cases --- .../Resource/Message/MessageInterface.cs | 48 ------------------- 1 file changed, 48 deletions(-) diff --git a/src/Plivo/Resource/Message/MessageInterface.cs b/src/Plivo/Resource/Message/MessageInterface.cs index 5857e581..aaee92fd 100755 --- a/src/Plivo/Resource/Message/MessageInterface.cs +++ b/src/Plivo/Resource/Message/MessageInterface.cs @@ -91,10 +91,6 @@ public MessageInterface(HttpClient client) : base(client) template = JsonConvert.DeserializeObject