whatsapp_sdk 0.9.2 → 0.11.0
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 +11 -1
- data/Gemfile +0 -6
- data/Gemfile.lock +16 -16
- data/README.md +19 -0
- data/example.rb +67 -1
- data/lib/whatsapp_sdk/api/api_configuration.rb +1 -1
- data/lib/whatsapp_sdk/api/business_profile.rb +8 -8
- data/lib/whatsapp_sdk/api/medias.rb +18 -18
- data/lib/whatsapp_sdk/api/messages.rb +67 -71
- data/lib/whatsapp_sdk/api/phone_numbers.rb +16 -16
- data/lib/whatsapp_sdk/api/response.rb +4 -4
- data/lib/whatsapp_sdk/api/responses/generic_error_response.rb +49 -0
- data/lib/whatsapp_sdk/api/responses/message_data_response.rb +8 -8
- data/lib/whatsapp_sdk/api/responses/message_error_response.rb +2 -38
- data/lib/whatsapp_sdk/api/responses/message_template_namespace_data_response.rb +37 -0
- data/lib/whatsapp_sdk/api/responses/template_data_response.rb +51 -0
- data/lib/whatsapp_sdk/api/responses/templates_data_response.rb +39 -0
- data/lib/whatsapp_sdk/api/templates.rb +201 -0
- data/lib/whatsapp_sdk/configuration.rb +2 -2
- data/lib/whatsapp_sdk/resource/component.rb +2 -2
- data/lib/whatsapp_sdk/resource/errors.rb +68 -0
- data/lib/whatsapp_sdk/resource/interactive_action.rb +5 -5
- data/lib/whatsapp_sdk/resource/interactive_action_reply_button.rb +2 -2
- data/lib/whatsapp_sdk/resource/interactive_action_section.rb +2 -2
- data/lib/whatsapp_sdk/resource/interactive_action_section_row.rb +5 -5
- data/lib/whatsapp_sdk/resource/interactive_body.rb +1 -1
- data/lib/whatsapp_sdk/resource/interactive_footer.rb +1 -1
- data/lib/whatsapp_sdk/resource/interactive_header.rb +1 -1
- data/lib/whatsapp_sdk/resource/languages.rb +86 -0
- data/lib/whatsapp_sdk/resource/parameter_object.rb +2 -2
- data/lib/whatsapp_sdk/resource/template.rb +64 -0
- data/lib/whatsapp_sdk/version.rb +1 -1
- data/whatsapp_sdk.gemspec +8 -8
- metadata +22 -15
- data/lib/whatsapp_sdk/resource/error.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3afc828e9c913c0aa1988b1ec75dcbd6453f13f67d46f3a25c77ef2558aacf8c
|
4
|
+
data.tar.gz: 64d8ea9e6c36c6d37c8dad014ee1dab10d906df4dcb7777206f6fc7300af44b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c4e910413ddf8366abd12b1aaed78e8a47d69b1cc979f7afaae00fc644ff9f735f6c1f594749de242fc87c70f6c2c7c9ccf6c215c2e85bda40f0f6540fc3a55
|
7
|
+
data.tar.gz: 5a2bac9b5b4f416af7abbfbdf07c91717b517f7c030fcb47c767c4d2863c538e2b03402ff3a0968b7a889b4748f3c5a14d1e4b75f1cbc75f238a1888d5cc78d1
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
-
# Unreleased
|
1
|
+
# Unreleased
|
2
|
+
|
3
|
+
# v 0.11.0
|
4
|
+
- Bumped API version to v19. @paulomcnally https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/116
|
5
|
+
|
6
|
+
# v 0.10.0
|
7
|
+
- Implement Templates API @emersonu, @ignacio-chiazzo [#90](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/90)
|
8
|
+
- Using compatible Gem versions instead of fixed dependency versions @nbluis [#108](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/108)
|
9
|
+
- [Breaking Change] Rename `error` module with `errors`. @ignacio-chiazzo [#101](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/pull/101)
|
10
|
+
|
11
|
+
If you are calling an error using `WhatsappSdk::Resource::Error`, you should update it to `WhatsappSdk::Resource::Errors`, e.g. `WhatsappSdk::Resource::Errors::MissingArgumentError`
|
2
12
|
|
3
13
|
# v 0.9.2
|
4
14
|
- Add Support to image/webp sticker media. @renatovico [#94](https://github.com/ignacio-chiazzo/ruby_whatsapp_sdk/issues/94)
|
data/Gemfile
CHANGED
@@ -5,12 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
|
6
6
|
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
7
7
|
|
8
|
-
gem("faraday")
|
9
|
-
gem("faraday-multipart")
|
10
|
-
gem("rake", ">= 12.3.3")
|
11
|
-
gem('sorbet-runtime')
|
12
|
-
gem("zeitwerk", ">= 2.6.0")
|
13
|
-
|
14
8
|
group(:test) do
|
15
9
|
gem('mocha')
|
16
10
|
gem('rubocop', require: false)
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whatsapp_sdk (0.
|
5
|
-
faraday (~> 2
|
6
|
-
faraday-multipart (~> 1
|
7
|
-
sorbet-runtime (~> 0.5
|
8
|
-
zeitwerk (~> 2
|
4
|
+
whatsapp_sdk (0.11.0)
|
5
|
+
faraday (~> 2)
|
6
|
+
faraday-multipart (~> 1)
|
7
|
+
sorbet-runtime (~> 0.5)
|
8
|
+
zeitwerk (~> 2)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
@@ -13,21 +13,23 @@ GEM
|
|
13
13
|
addressable (2.8.1)
|
14
14
|
public_suffix (>= 2.0.2, < 6.0)
|
15
15
|
ast (2.4.2)
|
16
|
+
base64 (0.2.0)
|
16
17
|
coderay (1.1.3)
|
17
18
|
crack (0.4.5)
|
18
19
|
rexml
|
19
20
|
diff-lcs (1.5.0)
|
20
|
-
faraday (2.
|
21
|
-
|
21
|
+
faraday (2.7.12)
|
22
|
+
base64
|
23
|
+
faraday-net_http (>= 2.0, < 3.1)
|
22
24
|
ruby2_keywords (>= 0.0.4)
|
23
25
|
faraday-multipart (1.0.4)
|
24
26
|
multipart-post (~> 2)
|
25
|
-
faraday-net_http (
|
27
|
+
faraday-net_http (3.0.2)
|
26
28
|
hashdiff (1.0.1)
|
27
29
|
method_source (1.0.0)
|
28
30
|
minitest (5.16.1)
|
29
31
|
mocha (1.14.0)
|
30
|
-
multipart-post (2.
|
32
|
+
multipart-post (2.3.0)
|
31
33
|
netrc (0.11.0)
|
32
34
|
parallel (1.22.1)
|
33
35
|
parser (3.1.2.0)
|
@@ -39,7 +41,7 @@ GEM
|
|
39
41
|
pry (>= 0.9.10, < 0.15)
|
40
42
|
public_suffix (5.0.0)
|
41
43
|
rainbow (3.1.1)
|
42
|
-
rake (
|
44
|
+
rake (12.3.3)
|
43
45
|
rbi (0.0.15)
|
44
46
|
ast
|
45
47
|
parser (>= 2.6.4.0)
|
@@ -70,6 +72,7 @@ GEM
|
|
70
72
|
sorbet (0.5.10346)
|
71
73
|
sorbet-static (= 0.5.10346)
|
72
74
|
sorbet-runtime (0.5.10346)
|
75
|
+
sorbet-static (0.5.10346-universal-darwin-19)
|
73
76
|
sorbet-static (0.5.10346-universal-darwin-21)
|
74
77
|
sorbet-static (0.5.10346-x86_64-linux)
|
75
78
|
sorbet-static-and-runtime (0.5.10346)
|
@@ -104,33 +107,30 @@ GEM
|
|
104
107
|
yard-sorbet (0.7.0)
|
105
108
|
sorbet-runtime (>= 0.5)
|
106
109
|
yard (>= 0.9)
|
107
|
-
zeitwerk (2.6.
|
110
|
+
zeitwerk (2.6.12)
|
108
111
|
|
109
112
|
PLATFORMS
|
110
113
|
arm64-darwin-21
|
114
|
+
x86_64-darwin-19
|
111
115
|
x86_64-darwin-21
|
112
116
|
x86_64-linux
|
113
117
|
|
114
118
|
DEPENDENCIES
|
115
119
|
bundler (~> 2.3)
|
116
|
-
faraday
|
117
|
-
faraday-multipart
|
118
120
|
minitest (~> 5.0)
|
119
121
|
mocha
|
120
122
|
pry
|
121
123
|
pry-nav
|
122
|
-
rake (
|
124
|
+
rake (~> 12.3)
|
123
125
|
rubocop
|
124
126
|
rubocop-minitest
|
125
127
|
rubocop-performance
|
126
128
|
rubocop-sorbet
|
127
129
|
sorbet
|
128
|
-
sorbet-runtime
|
129
130
|
spoom
|
130
131
|
tapioca
|
131
132
|
webmock
|
132
133
|
whatsapp_sdk!
|
133
|
-
zeitwerk (>= 2.6.0)
|
134
134
|
|
135
135
|
BUNDLED WITH
|
136
136
|
2.3.22
|
data/README.md
CHANGED
@@ -124,12 +124,31 @@ messages_api = WhatsappSdk::Api::Messages.new
|
|
124
124
|
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
125
125
|
medias_api = WhatsappSdk::Api::Medias.new
|
126
126
|
business_profile_api = WhatsappSdk::Api::BusinessProfile.new
|
127
|
+
templates_api = WhatsappSdk::Api::Templates.new
|
127
128
|
```
|
128
129
|
|
129
130
|
Note: Remember to initialize the client first!
|
130
131
|
|
131
132
|
## APIs
|
132
133
|
|
134
|
+
### Templates
|
135
|
+
<details>
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# Get list of templates
|
139
|
+
templates_api.templates(business_id: BUSINESS_ID)
|
140
|
+
|
141
|
+
# Create a template
|
142
|
+
new_template = templates_api.create(
|
143
|
+
business_id: BUSINESS_ID, name: "seasonal_promotion", language: "en_US", category: "MARKETING",
|
144
|
+
components_json: components_json, allow_category_change: true
|
145
|
+
)
|
146
|
+
|
147
|
+
# Delete a template
|
148
|
+
templates_api.delete(business_id: BUSINESS_ID, name: "my_name") # delete by name
|
149
|
+
```
|
150
|
+
</details>
|
151
|
+
|
133
152
|
### Business Profile API
|
134
153
|
<details>
|
135
154
|
|
data/example.rb
CHANGED
@@ -48,10 +48,76 @@ def print_message_sent(message_response)
|
|
48
48
|
end
|
49
49
|
##################################################
|
50
50
|
|
51
|
+
|
51
52
|
medias_api = WhatsappSdk::Api::Medias.new
|
52
53
|
messages_api = WhatsappSdk::Api::Messages.new
|
53
54
|
phone_numbers_api = WhatsappSdk::Api::PhoneNumbers.new
|
54
55
|
business_profile_api = WhatsappSdk::Api::BusinessProfile.new
|
56
|
+
templates_api = WhatsappSdk::Api::Templates.new
|
57
|
+
|
58
|
+
############################## Templates API ##############################
|
59
|
+
|
60
|
+
## Get list of templates
|
61
|
+
templates_api.templates(business_id: BUSINESS_ID)
|
62
|
+
|
63
|
+
## Get message templates namespace
|
64
|
+
templates_api.get_message_template_namespace(business_id: BUSINESS_ID)
|
65
|
+
|
66
|
+
# Create a template
|
67
|
+
components_json = [
|
68
|
+
{
|
69
|
+
"type": "BODY",
|
70
|
+
"text": "Thank you for your order, {{1}}! Your confirmation number is {{2}}. If you have any questions, please use the buttons below to contact support. Thank you for being a customer!",
|
71
|
+
"example": {
|
72
|
+
"body_text": [
|
73
|
+
[
|
74
|
+
"Ignacio","860198-230332"
|
75
|
+
]
|
76
|
+
]
|
77
|
+
}
|
78
|
+
},
|
79
|
+
{
|
80
|
+
"type": "BUTTONS",
|
81
|
+
"buttons": [
|
82
|
+
{
|
83
|
+
"type": "PHONE_NUMBER",
|
84
|
+
"text": "Call",
|
85
|
+
"phone_number": "59898400766"
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"type": "URL",
|
89
|
+
"text": "Contact Support",
|
90
|
+
"url": "https://www.luckyshrub.com/support"
|
91
|
+
}
|
92
|
+
]
|
93
|
+
}
|
94
|
+
]
|
95
|
+
|
96
|
+
new_template = templates_api.create(
|
97
|
+
business_id: BUSINESS_ID, name: "seasonal_promotion", language: "ka", category: "MARKETING",
|
98
|
+
components_json: components_json, allow_category_change: true
|
99
|
+
)
|
100
|
+
|
101
|
+
# Update a template
|
102
|
+
components_json = [
|
103
|
+
{
|
104
|
+
"type" => "header",
|
105
|
+
"parameters" => [
|
106
|
+
{
|
107
|
+
"type" => "image",
|
108
|
+
"image" => {
|
109
|
+
"link" => "https://www.google.com/imgres?imgurl=https%3A%2F%2Fqph.cf2.quoracdn.net%2Fmain-qimg-6d977408fdd90a09a1fee7ba9e2f777c-lq&imgrefurl=https%3A%2F%2Fwww.quora.com%2FHow-can-I-find-my-WhatsApp-ID&tbnid=lDAx1vzXwqCakM&vet=12ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ..i&docid=s-DNQVCrZmhJYM&w=602&h=339&q=example%20whatsapp%20image%20id&ved=2ahUKEwjKupLviJX4AhVrrHIEHQpGD9MQMygAegUIARC9AQ"
|
110
|
+
}
|
111
|
+
}
|
112
|
+
]
|
113
|
+
}
|
114
|
+
]
|
115
|
+
templates_api.update(template_id: "1624560287967996", category: "UTILITY")
|
116
|
+
|
117
|
+
## Delete a template
|
118
|
+
templates_api.delete(business_id: BUSINESS_ID, name: "seasonal_promotion") # delete by name
|
119
|
+
# templates_api.delete(business_id: BUSINESS_ID, name: "name2", hsm_id: "243213188351928") # delete by name and id
|
120
|
+
|
55
121
|
############################## Business API ##############################
|
56
122
|
business_profile = business_profile_api.details(SENDER_ID)
|
57
123
|
business_profile_api.update(phone_number_id: SENDER_ID, params: { about: "A very cool business" } )
|
@@ -107,7 +173,7 @@ message_id = message_sent.data.messages.first.id
|
|
107
173
|
messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "\u{1f550}")
|
108
174
|
messages_api.send_reaction(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message_id: message_id, emoji: "⛄️")
|
109
175
|
|
110
|
-
######### Reply to a message
|
176
|
+
######### Reply to a message
|
111
177
|
message_to_reply_id = message_sent.data.messages.first.id
|
112
178
|
reply = messages_api.send_text(sender_id: SENDER_ID, recipient_number: RECIPIENT_NUMBER, message: "I'm a reply", message_id: message_to_reply_id)
|
113
179
|
print_message_sent(reply)
|
@@ -12,17 +12,17 @@ module WhatsappSdk
|
|
12
12
|
# Get the details of business profile.
|
13
13
|
#
|
14
14
|
# @param phone_number_id [Integer] Phone Number Id.
|
15
|
-
# @return [
|
16
|
-
sig { params(phone_number_id: Integer).returns(
|
15
|
+
# @return [Api::Response] Response object.
|
16
|
+
sig { params(phone_number_id: Integer).returns(Api::Response) }
|
17
17
|
def details(phone_number_id)
|
18
18
|
response = send_request(
|
19
19
|
http_method: "get",
|
20
20
|
endpoint: "#{phone_number_id}/whatsapp_business_profile?fields=#{DEFAULT_FIELDS}"
|
21
21
|
)
|
22
22
|
|
23
|
-
|
23
|
+
Api::Response.new(
|
24
24
|
response: response,
|
25
|
-
data_class_type:
|
25
|
+
data_class_type: Api::Responses::BusinessProfileDataResponse
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
@@ -30,11 +30,11 @@ module WhatsappSdk
|
|
30
30
|
#
|
31
31
|
# @param phone_number_id [Integer] Phone Number Id.
|
32
32
|
# @param params [Hash] Params to update.
|
33
|
-
# @return [
|
33
|
+
# @return [Api::Response] Response object.
|
34
34
|
sig do
|
35
35
|
params(
|
36
36
|
phone_number_id: Integer, params: T::Hash[T.untyped, T.untyped]
|
37
|
-
).returns(
|
37
|
+
).returns(Api::Response)
|
38
38
|
end
|
39
39
|
def update(phone_number_id:, params:)
|
40
40
|
# this is a required field
|
@@ -46,9 +46,9 @@ module WhatsappSdk
|
|
46
46
|
params: params
|
47
47
|
)
|
48
48
|
|
49
|
-
|
49
|
+
Api::Response.new(
|
50
50
|
response: response,
|
51
|
-
data_class_type:
|
51
|
+
data_class_type: Api::Responses::SuccessResponse
|
52
52
|
)
|
53
53
|
end
|
54
54
|
end
|
@@ -46,17 +46,17 @@ module WhatsappSdk
|
|
46
46
|
# Get Media by ID.
|
47
47
|
#
|
48
48
|
# @param media_id [String] Media Id.
|
49
|
-
# @return [
|
50
|
-
sig { params(media_id: String).returns(
|
49
|
+
# @return [Api::Response] Response object.
|
50
|
+
sig { params(media_id: String).returns(Api::Response) }
|
51
51
|
def media(media_id:)
|
52
52
|
response = send_request(
|
53
53
|
http_method: "get",
|
54
54
|
endpoint: "/#{media_id}"
|
55
55
|
)
|
56
56
|
|
57
|
-
|
57
|
+
Api::Response.new(
|
58
58
|
response: response,
|
59
|
-
data_class_type:
|
59
|
+
data_class_type: Api::Responses::MediaDataResponse
|
60
60
|
)
|
61
61
|
end
|
62
62
|
|
@@ -66,8 +66,8 @@ module WhatsappSdk
|
|
66
66
|
# @param file_path [String] The file_path to download the media e.g. "tmp/downloaded_image.png".
|
67
67
|
# @param media_type [String] The media type e.g. "audio/mp4". See the supported types in the official
|
68
68
|
# documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types.
|
69
|
-
# @return [
|
70
|
-
sig { params(url: String, file_path: String, media_type: String).returns(
|
69
|
+
# @return [Api::Response] Response object.
|
70
|
+
sig { params(url: String, file_path: String, media_type: String).returns(Api::Response) }
|
71
71
|
def download(url:, file_path:, media_type:)
|
72
72
|
raise InvalidMediaTypeError.new(media_type: media_type) unless valid_media_type?(media_type)
|
73
73
|
|
@@ -80,10 +80,10 @@ module WhatsappSdk
|
|
80
80
|
{ "error" => true, "status" => response.code }
|
81
81
|
end
|
82
82
|
|
83
|
-
|
83
|
+
Api::Response.new(
|
84
84
|
response: response,
|
85
|
-
data_class_type:
|
86
|
-
error_class_type:
|
85
|
+
data_class_type: Api::Responses::SuccessResponse,
|
86
|
+
error_class_type: Api::Responses::ErrorResponse
|
87
87
|
)
|
88
88
|
end
|
89
89
|
|
@@ -93,8 +93,8 @@ module WhatsappSdk
|
|
93
93
|
# @param type [String] Media type e.g. text/plain, video/3gp, image/jpeg, image/png. For more information,
|
94
94
|
# see the official documentation https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#supported-media-types.
|
95
95
|
#
|
96
|
-
# @return [
|
97
|
-
sig { params(sender_id: Integer, file_path: String, type: String).returns(
|
96
|
+
# @return [Api::Response] Response object.
|
97
|
+
sig { params(sender_id: Integer, file_path: String, type: String).returns(Api::Response) }
|
98
98
|
def upload(sender_id:, file_path:, type:)
|
99
99
|
raise FileNotFoundError.new(file_path: file_path) unless File.file?(file_path)
|
100
100
|
|
@@ -106,26 +106,26 @@ module WhatsappSdk
|
|
106
106
|
|
107
107
|
response = send_request(http_method: "post", endpoint: "#{sender_id}/media", params: params)
|
108
108
|
|
109
|
-
|
109
|
+
Api::Response.new(
|
110
110
|
response: response,
|
111
|
-
data_class_type:
|
111
|
+
data_class_type: Api::Responses::MediaDataResponse
|
112
112
|
)
|
113
113
|
end
|
114
114
|
|
115
115
|
# Delete a Media by ID.
|
116
116
|
#
|
117
117
|
# @param media_id [String] Media Id.
|
118
|
-
# @return [
|
119
|
-
sig { params(media_id: String).returns(
|
118
|
+
# @return [Api::Response] Response object.
|
119
|
+
sig { params(media_id: String).returns(Api::Response) }
|
120
120
|
def delete(media_id:)
|
121
121
|
response = send_request(
|
122
122
|
http_method: "delete",
|
123
123
|
endpoint: "/#{media_id}"
|
124
124
|
)
|
125
125
|
|
126
|
-
|
126
|
+
Api::Response.new(
|
127
127
|
response: response,
|
128
|
-
data_class_type:
|
128
|
+
data_class_type: Api::Responses::SuccessResponse
|
129
129
|
)
|
130
130
|
end
|
131
131
|
|
@@ -140,7 +140,7 @@ module WhatsappSdk
|
|
140
140
|
end
|
141
141
|
|
142
142
|
def valid_media_type?(media_type)
|
143
|
-
|
143
|
+
Resource::MediaTypes::SUPPORTED_MEDIA_TYPES.include?(media_type)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|