Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMS-7359: Adding support for named variables in whatsapp templates #253

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Change Log

## [4.61.4](https://github.com/plivo/plivo-ruby/tree/v4.61.4) (2025-02-25)
**Feature - Supporting parameter_name in WhatsApp Template .**
- Supporting `parameter_name` in WhatsApp Template .

## [4.61.3](https://github.com/plivo/plivo-ruby/tree/v4.61.3) (2025-02-18)
**Feature - Throw GeoPermissionsError Exception on synchronous geo permissions error**

50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ The Plivo Ruby SDK makes it simpler to integrate communications into your Ruby a
Add this line to your application's Gemfile:

```ruby
gem 'plivo', '>= 4.61.3'
gem 'plivo', '>= 4.61.4'
```

And then execute:
@@ -246,6 +246,54 @@ puts response
```
> Note: It is also possible to create and manage objects directly within the SDK for whatsapp, providing a structured approach to message creation.


### Templated WhatsApp Messages With Named Parameter
This guide shows how to send templated WhatsApp messages with named parameters.

Example:
```ruby
require "plivo"
include Plivo

api = RestClient.new("<auth_id>","<auth_token>")

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 = api.messages.create(
src: "+14156667778",
dst:"+14156667777",
type:"whatsapp",
template:template,
url: "https://<yourdomain>.com/whatsapp_status/",
)
puts 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.

8 changes: 5 additions & 3 deletions lib/plivo/template.rb
Original file line number Diff line number Diff line change
@@ -42,16 +42,17 @@ def to_hash
end

class Parameter
attr_accessor :type, :text, :media, :payload, :currency, :date_time, :location
attr_accessor :type, :text, :media, :payload, :currency, :date_time, :location, :parameter_name

def initialize(type: nil, text: nil, media: nil, payload: nil, currency: nil, date_time: nil, location: nil)
def initialize(type: nil, text: nil, media: nil, payload: nil, currency: nil, date_time: nil, location: nil, parameter_name: nil)
@type = type
@text = text
@media = media
@payload = payload
@currency = currency
@date_time = date_time
@location = location
@parameter_name = parameter_name
end

def to_hash
@@ -62,7 +63,8 @@ def to_hash
payload: @payload,
currency: @currency&.to_hash,
date_time: @date_time&.to_hash,
location: @location&.to_hash
location: @location&.to_hash,
parameter_name: @parameter_name
}.reject { |_, v| v.nil? }
end
end
2 changes: 1 addition & 1 deletion lib/plivo/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Plivo
VERSION = "4.61.3".freeze
VERSION = "4.61.4".freeze
end