whatsapp_sdk 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/example.rb +8 -4
- data/lib/whatsapp_sdk/api/templates.rb +22 -3
- data/lib/whatsapp_sdk/resource/errors.rb +10 -0
- data/lib/whatsapp_sdk/resource/parameter_object.rb +13 -0
- data/lib/whatsapp_sdk/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17de6b59f97c39b0d49c911d4e153d241f60d7f92727a10ec895ff4dc4d9822b
|
|
4
|
+
data.tar.gz: f2f25357ffa9d35972e157f57abfaa4a3ac2b2a9debb0f86fdb15230581c6ce6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ef8af8f454441f188633dab7295b20da476d8692af1bf6602032b7504c08d1931bc9fbb9544452f981b3b58111ed0bec034de6138540c3445d6379a50f813ac
|
|
7
|
+
data.tar.gz: ead1a38b14a8d5d16539e61ba4b65c36c6652525ca10d7aab554dd3b83a8cd1b11fff52dc38e0c121f574db108ce3ea64546bf62a386b46078dfc369dd559710
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Unreleased
|
|
2
2
|
|
|
3
|
+
# v 1.0.5
|
|
4
|
+
- Added GET template endpoint. @osvaldo-santos [185](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/185)
|
|
5
|
+
- Adding support for named paremeters in Templates API. @osvaldo-santos [184](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/184)
|
|
6
|
+
- Fixed bug for empty templates. @osvaldo-santos [183](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/183)
|
|
7
|
+
|
|
3
8
|
# v 1.0.4
|
|
4
9
|
- Support for version 23 and 24 API. [180](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/180)
|
|
5
10
|
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -196,6 +196,9 @@ client.templates.list(business_id: BUSINESS_ID)
|
|
|
196
196
|
# The message template namespace is required to send messages using the message templates.
|
|
197
197
|
client.templates.get_message_template_namespace(business_id: BUSINESS_ID)
|
|
198
198
|
|
|
199
|
+
# Get template by id
|
|
200
|
+
template = client.templates.get(template_id: id)
|
|
201
|
+
|
|
199
202
|
# Create a template
|
|
200
203
|
client.templates.create(
|
|
201
204
|
business_id: BUSINESS_ID, name: "seasonal_promotion", language: "en_US", category: "MARKETING",
|
data/example.rb
CHANGED
|
@@ -14,6 +14,7 @@ gemfile(true) do
|
|
|
14
14
|
gem "whatsapp_sdk", path: "../"
|
|
15
15
|
gem "pry"
|
|
16
16
|
gem "pry-nav"
|
|
17
|
+
gem "debug"
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
require 'whatsapp_sdk'
|
|
@@ -56,12 +57,8 @@ end
|
|
|
56
57
|
|
|
57
58
|
client = WhatsappSdk::Api::Client.new
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
60
|
# ############################## Templates API ##############################
|
|
63
61
|
puts "\n\n ------------------ Testing Templates API ------------------------"
|
|
64
|
-
|
|
65
62
|
# ## Get list of templates
|
|
66
63
|
templates = client.templates.list(business_id: BUSINESS_ID)
|
|
67
64
|
puts "GET Templates list : #{ templates.records.map(&:name) }"
|
|
@@ -70,6 +67,13 @@ puts "GET Templates list : #{ templates.records.map(&:name) }"
|
|
|
70
67
|
template_namespace = client.templates.get_message_template_namespace(business_id: BUSINESS_ID)
|
|
71
68
|
puts "GET template by namespace: #{template_namespace.id}"
|
|
72
69
|
|
|
70
|
+
## GET
|
|
71
|
+
id = templates.records.first.id
|
|
72
|
+
if id
|
|
73
|
+
template = client.templates.get(template_id: id)
|
|
74
|
+
puts "GET template by id: #{template.id}"
|
|
75
|
+
end
|
|
76
|
+
|
|
73
77
|
# Create a template
|
|
74
78
|
components_json = [
|
|
75
79
|
{
|
|
@@ -18,6 +18,18 @@ module WhatsappSdk
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
# Get a template
|
|
22
|
+
# @param template_id [String] Required. The template ID.
|
|
23
|
+
# @return [Template] Template object.
|
|
24
|
+
def get(template_id:)
|
|
25
|
+
response = send_request(
|
|
26
|
+
endpoint: template_id,
|
|
27
|
+
http_method: "get"
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
Resource::Template.from_hash(response)
|
|
31
|
+
end
|
|
32
|
+
|
|
21
33
|
# Create a template
|
|
22
34
|
#
|
|
23
35
|
# @param business_id [Integer] Business Id.
|
|
@@ -28,11 +40,13 @@ module WhatsappSdk
|
|
|
28
40
|
# @param components_json [Component] Components that make up the template. See the list of possible components:
|
|
29
41
|
# https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components
|
|
30
42
|
# @param allow_category_change [Boolean] Optional Allow category change.
|
|
43
|
+
# @param parameter_format [String] Optional Parameter format. Possible values: named, positional.
|
|
31
44
|
# Set to true to allow us to assign a category based on the template guidelines and the template's contents.
|
|
32
45
|
# This can prevent your template from being rejected for miscategorization.
|
|
33
46
|
# @return [Template] Template object.
|
|
34
47
|
def create(
|
|
35
|
-
business_id:, name:, category:, language:, components_json: nil, allow_category_change: nil
|
|
48
|
+
business_id:, name:, category:, language:, components_json: nil, allow_category_change: nil,
|
|
49
|
+
parameter_format: nil
|
|
36
50
|
)
|
|
37
51
|
unless WhatsappSdk::Resource::Template::Category.valid?(category)
|
|
38
52
|
raise InvalidCategoryError.new(category: category)
|
|
@@ -42,6 +56,10 @@ module WhatsappSdk
|
|
|
42
56
|
raise WhatsappSdk::Resource::Errors::InvalidLanguageError.new(language: language)
|
|
43
57
|
end
|
|
44
58
|
|
|
59
|
+
if parameter_format && !WhatsappSdk::Resource::ParameterObject::Format.valid?(parameter_format)
|
|
60
|
+
raise WhatsappSdk::Resource::Errors::InvalidParameterFormatError.new(format: parameter_format)
|
|
61
|
+
end
|
|
62
|
+
|
|
45
63
|
params = {
|
|
46
64
|
name: name,
|
|
47
65
|
category: category,
|
|
@@ -49,6 +67,7 @@ module WhatsappSdk
|
|
|
49
67
|
components: components_json
|
|
50
68
|
}
|
|
51
69
|
params["allow_category_change"] = allow_category_change if allow_category_change
|
|
70
|
+
params["parameter_format"] = parameter_format if parameter_format
|
|
52
71
|
|
|
53
72
|
response = send_request(
|
|
54
73
|
endpoint: "#{business_id}/message_templates",
|
|
@@ -77,8 +96,8 @@ module WhatsappSdk
|
|
|
77
96
|
|
|
78
97
|
Api::Responses::PaginationRecords.new(
|
|
79
98
|
records: parse_templates(response['data']),
|
|
80
|
-
before: response
|
|
81
|
-
after: response
|
|
99
|
+
before: response.dig('paging', 'cursors', 'before'),
|
|
100
|
+
after: response.dig('paging', 'cursors', 'after')
|
|
82
101
|
)
|
|
83
102
|
end
|
|
84
103
|
|
|
@@ -49,6 +49,16 @@ module WhatsappSdk
|
|
|
49
49
|
class InvalidInteractiveActionSectionRow < Error; end
|
|
50
50
|
|
|
51
51
|
class InvalidInteractiveFooter < Error; end
|
|
52
|
+
|
|
53
|
+
class InvalidParameterFormatError < StandardError
|
|
54
|
+
attr_reader :format
|
|
55
|
+
|
|
56
|
+
def initialize(format:)
|
|
57
|
+
@format = format
|
|
58
|
+
|
|
59
|
+
super("Invalid Parameter Format. The possible values are: named and positional.")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
52
62
|
end
|
|
53
63
|
end
|
|
54
64
|
end
|
|
@@ -42,6 +42,19 @@ module WhatsappSdk
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
module Format
|
|
46
|
+
NAMED = "named"
|
|
47
|
+
POSITIONAL = "positional"
|
|
48
|
+
|
|
49
|
+
FORMATS = [
|
|
50
|
+
NAMED,
|
|
51
|
+
POSITIONAL
|
|
52
|
+
].freeze
|
|
53
|
+
|
|
54
|
+
def self.valid?(format)
|
|
55
|
+
FORMATS.include?(format)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
45
58
|
# Returns Text string if the parameter object type is text.
|
|
46
59
|
# For the header component, the character limit is 60 characters.
|
|
47
60
|
# For the body component, the character limit is 1024 characters.
|
data/lib/whatsapp_sdk/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: whatsapp_sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ignacio-chiazzo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|