warb 0.1.3 → 1.0.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/.rubocop.yml +5 -12
- data/README.md +9 -32
- data/Rakefile +3 -3
- data/docs/README.md +1 -4
- data/docs/components/README.md +1 -4
- data/docs/messages/README.md +1 -2
- data/docs/messages/interactive_call_to_action_url.md +9 -9
- data/docs/messages/interactive_list.md +2 -2
- data/docs/messages/interactive_reply_button.md +9 -9
- data/examples/audio.rb +10 -10
- data/examples/document.rb +34 -34
- data/examples/image.rb +22 -22
- data/examples/interactive_call_to_action_url.rb +46 -46
- data/examples/interactive_list.rb +61 -61
- data/examples/interactive_reply_button.rb +43 -43
- data/examples/location.rb +32 -32
- data/examples/location_request.rb +11 -11
- data/examples/message.rb +8 -8
- data/examples/sticker.rb +10 -10
- data/examples/video.rb +22 -22
- data/examples/webhook.rb +42 -44
- data/lib/warb/client.rb +5 -7
- data/lib/warb/components/action.rb +8 -12
- data/lib/warb/configuration.rb +1 -4
- data/lib/warb/connection.rb +9 -15
- data/lib/warb/dispatcher.rb +3 -4
- data/lib/warb/dispatcher_concern.rb +0 -6
- data/lib/warb/indicator_dispatcher.rb +4 -4
- data/lib/warb/media_dispatcher.rb +10 -10
- data/lib/warb/resources/audio.rb +1 -1
- data/lib/warb/resources/contact.rb +20 -22
- data/lib/warb/resources/document.rb +1 -1
- data/lib/warb/resources/flow.rb +8 -10
- data/lib/warb/resources/image.rb +1 -1
- data/lib/warb/resources/interactive_call_to_action_url.rb +8 -10
- data/lib/warb/resources/interactive_list.rb +5 -7
- data/lib/warb/resources/interactive_reply_button.rb +8 -10
- data/lib/warb/resources/location.rb +1 -11
- data/lib/warb/resources/location_request.rb +3 -5
- data/lib/warb/resources/reaction.rb +1 -1
- data/lib/warb/resources/resource.rb +4 -12
- data/lib/warb/resources/sticker.rb +1 -1
- data/lib/warb/resources/text.rb +3 -21
- data/lib/warb/resources/video.rb +1 -1
- data/lib/warb/utils.rb +1 -3
- data/lib/warb/version.rb +1 -1
- data/lib/warb.rb +31 -50
- metadata +3 -29
- data/docs/components/button.md +0 -61
- data/docs/components/copy_code_button.md +0 -57
- data/docs/components/url_button.md +0 -57
- data/docs/messages/template.md +0 -327
- data/docs/resources/currency.md +0 -22
- data/docs/resources/date_time.md +0 -11
- data/docs/resources/index.md +0 -14
- data/docs/resources/text.md +0 -9
- data/lib/warb/components/button.rb +0 -29
- data/lib/warb/components/component.rb +0 -19
- data/lib/warb/components/copy_code_button.rb +0 -30
- data/lib/warb/components/quick_reply_button.rb +0 -15
- data/lib/warb/components/url_button.rb +0 -30
- data/lib/warb/components/voice_call_button.rb +0 -15
- data/lib/warb/errors.rb +0 -27
- data/lib/warb/language.rb +0 -8
- data/lib/warb/resources/currency.rb +0 -47
- data/lib/warb/resources/date_time.rb +0 -34
- data/lib/warb/resources/template.rb +0 -167
- data/lib/warb/response.rb +0 -33
- data/lib/warb/response_error_handler.rb +0 -42
- data/lib/warb/template_dispatcher.rb +0 -12
data/docs/messages/template.md
DELETED
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
# Template
|
|
2
|
-
|
|
3
|
-
Template messages are used to send a message with a specific template.
|
|
4
|
-
|
|
5
|
-
This is useful for sending messages that have a predefined structure, such as notifications or alerts.
|
|
6
|
-
|
|
7
|
-
#### Quick Examples
|
|
8
|
-
|
|
9
|
-
**Note**: For the examples below, take into account `Warb.setup` was called to configure the global client instance.
|
|
10
|
-
|
|
11
|
-
List available templates:
|
|
12
|
-
```ruby
|
|
13
|
-
Warb.template.list
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
Sending template messages:
|
|
17
|
-
```ruby
|
|
18
|
-
Warb.template.dispatch(recipient_number, **params)
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
#### Listing Templates
|
|
22
|
-
|
|
23
|
-
**Prerequisites**: In order to view templates, you need to have them available in your business account. For more details, refer to the [Meta documentation](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates/template-library). Template creation via API will be covered later in this documentation (coming soon).
|
|
24
|
-
|
|
25
|
-
You can retrieve all available message templates:
|
|
26
|
-
|
|
27
|
-
```ruby
|
|
28
|
-
Warb.template.list
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
##### Optional Parameters
|
|
32
|
-
|
|
33
|
-
You can optionally filter templates using various parameters:
|
|
34
|
-
|
|
35
|
-
Limit the number of results:
|
|
36
|
-
```ruby
|
|
37
|
-
Warb.template.list(limit: 10)
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
Specify which template fields to return:
|
|
41
|
-
```ruby
|
|
42
|
-
Warb.template.list(fields: ["name", "status", "category"])
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
For a complete list of available fields, refer to the [Meta documentation](https://developers.facebook.com/docs/graph-api/reference/whats-app-business-hsm/#fields).
|
|
46
|
-
|
|
47
|
-
##### Example Response
|
|
48
|
-
|
|
49
|
-
```ruby
|
|
50
|
-
{
|
|
51
|
-
"data" => [
|
|
52
|
-
{
|
|
53
|
-
"name" => "hello_world",
|
|
54
|
-
"status" => "APPROVED",
|
|
55
|
-
"category" => "UTILITY",
|
|
56
|
-
"language" => "en_US",
|
|
57
|
-
"components" => [ ... ],
|
|
58
|
-
"id" => "1282952826730729"
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"name" => "other_template_001",
|
|
62
|
-
"status" => "APPROVED",
|
|
63
|
-
"category" => "MARKETING",
|
|
64
|
-
"language" => "pt_BR",
|
|
65
|
-
"components" => [ ... ],
|
|
66
|
-
"id" => "1948352829250167"
|
|
67
|
-
}
|
|
68
|
-
],
|
|
69
|
-
"paging" => {
|
|
70
|
-
"cursors" => {
|
|
71
|
-
"before" => "...",
|
|
72
|
-
"after" => "..."
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
#### Sending Template Messages
|
|
79
|
-
|
|
80
|
-
To send a template message, you need to provide the template name and the parameters for the template, if any.
|
|
81
|
-
|
|
82
|
-
```ruby
|
|
83
|
-
Warb.template.dispatch(recipient_number, **params)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
Here, `**params` is a named hash parameters that will be passed to the template, as follow:
|
|
87
|
-
| Attribute | Type | Required | Description |
|
|
88
|
-
|-------------|-------------------|----------|---------------------------------------|
|
|
89
|
-
| `name` | `String` | Yes | The name of the template to use |
|
|
90
|
-
| `language` | `String` | Yes | The language to use for the template |
|
|
91
|
-
| `resources` | `Array` or `Hash` | No | The resources to use for the template |
|
|
92
|
-
|
|
93
|
-
`name` must be the name of a template that has been created in the WhatsApp Business Platform.
|
|
94
|
-
|
|
95
|
-
`language` must be a valid language code, such as `en_US` for English (United States) or `fr_FR` for French (France). Also, the specified template must support the specified language.
|
|
96
|
-
|
|
97
|
-
> You can check `Warb::Language` for a list of supported languages.
|
|
98
|
-
> If yours isn't there, you can refer to this [list with all supported languages](https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/supported-languages) by WhatsApp.
|
|
99
|
-
> Just use the value in the `code` column, and it will work.
|
|
100
|
-
|
|
101
|
-
`resouces` can be an array or a hash of resources that will be used as parameters for the template. At this point, only `text`, `date_time` and `currency` are supported.
|
|
102
|
-
|
|
103
|
-
If the template uses named parameters, then `resources` must be a hash, as follow:
|
|
104
|
-
```ruby
|
|
105
|
-
customer_name = Warb::Resources::Text.new(content: "Name")
|
|
106
|
-
purchase_date = Warb::Resources::Text.new("January 1, 2023")
|
|
107
|
-
|
|
108
|
-
Warb.template.dispatch(recipient_number, resources: {
|
|
109
|
-
customer_name: customer_name,
|
|
110
|
-
purchase_date: purchase_date
|
|
111
|
-
}, name: "testing", language: "pt_BR")
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
If the template uses positional parameters, then `resources` must be an array, as follow:
|
|
115
|
-
```ruby
|
|
116
|
-
customer_name = Warb::Resources::Text.new(content: "Name")
|
|
117
|
-
purchase_date = Warb::Resources::DateTime.new("January 1, 2023")
|
|
118
|
-
|
|
119
|
-
Warb.template.dispatch(recipient_number, resources: [
|
|
120
|
-
customer_name,
|
|
121
|
-
purchase_date
|
|
122
|
-
], name: "testing", language: "en_US")
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
In any case, under the hood, the resources instances' method `build_template_named_parameter` or `build_template_positional_parameter` will be called to build the template parameters accordingly.
|
|
126
|
-
|
|
127
|
-
Instead of instatiating the resources manually, you can use helper methods as follow:
|
|
128
|
-
```ruby
|
|
129
|
-
Warb.template.dispatch(recipient_number) do |template|
|
|
130
|
-
template.name = "testing"
|
|
131
|
-
template.language = Warb::Language::PORTUGUESE_BR
|
|
132
|
-
template.add_text_parameter(content: "Name")
|
|
133
|
-
template.add_currency_parameter(code: "USD", amount: 11.42)
|
|
134
|
-
end
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Here, `add_text_parameter` and `add_currency_parameter` will build the resources for you with the given named parameters and add them to the template.
|
|
138
|
-
|
|
139
|
-
Here's a table with all the helper methods you can use to add resources/paramters to the template message:
|
|
140
|
-
| Method Name | Resource Type | Description |
|
|
141
|
-
|---------------------------------|-----------------------------|--------------------------------------------------|
|
|
142
|
-
| `add_text_parameter` | `Warb::Resources::Text` | Adds a text parameter to the template |
|
|
143
|
-
| `add_date_time_parameter` | `Warb::Resources::DateTime` | Adds a date time parameter to the template |
|
|
144
|
-
| `add_currency_parameter` | `Warb::Resources::Currency` | Adds a currency parameter to the template |
|
|
145
|
-
|
|
146
|
-
In the example above, notice we only used named parameters (no positional parameters) as arguments to the add parameter methods.
|
|
147
|
-
|
|
148
|
-
So, the parameters will be built as positional parameters, and the `resources` will be an array.
|
|
149
|
-
|
|
150
|
-
Also, the resources will be used to substitute the corresponding parameters in your template, in the same order they were added to the parameters/resources list.
|
|
151
|
-
|
|
152
|
-
If you don't want to worry about the order of the parameters, you may use named parameters.
|
|
153
|
-
|
|
154
|
-
For that, you have to pass the parameter name (as defined in your template) as the first argument to the helper method, as follow:
|
|
155
|
-
```ruby
|
|
156
|
-
Warb.template.dispatch(recipient_number, name: "testing", language: "pt_BR") do |template|
|
|
157
|
-
template.add_text_parameter("customer_name", content: "Name")
|
|
158
|
-
template.add_date_time_parameter("purchase_date", date_time: "January 1, 2023")
|
|
159
|
-
end
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
This way, the order of the parameters names in the template and the order they were added with the `add_parameter` methods may be entirely different.
|
|
163
|
-
|
|
164
|
-
One **IMPORTANT** thing to note is that, once defined, the type of the parameters won't be changed.
|
|
165
|
-
|
|
166
|
-
So, in the following code:
|
|
167
|
-
```ruby
|
|
168
|
-
Warb.template.dispatch(recipient_number, name: "testing", language: "pt_BR") do |template|
|
|
169
|
-
template.add_date_time_parameter(date_time: "January 1, 2023")
|
|
170
|
-
template.add_text_parameter("customer_name", content: "Name")
|
|
171
|
-
end
|
|
172
|
-
```
|
|
173
|
-
Your `customer_name` parameter won't behave the way you may expect.
|
|
174
|
-
|
|
175
|
-
Since the first call to an `add_parameter` method was using the positional parameters syntax, then the internal resources attribute was set to an array, so that means any posterior calls to any `add_parameter` method will simply ignore the named parameter syntax and append the built resource to the list of positional parameters
|
|
176
|
-
|
|
177
|
-
If the order of the calls was different:
|
|
178
|
-
```ruby
|
|
179
|
-
Warb.template.dispatch(recipient_number, name: "testing", language: "pt_BR") do |template|
|
|
180
|
-
template.add_text_parameter("customer_name", content: "Name")
|
|
181
|
-
template.add_date_time_parameter(date_time: "January 1, 2023")
|
|
182
|
-
template.add_currency_parameter(code: "USD", amount: 10)
|
|
183
|
-
end
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
1. The first call to `add_parameter` method would set the internal resources/parameter to a hash, with a initial key named `customer_name`, pointing to a text resource
|
|
187
|
-
|
|
188
|
-
2. Then the `DateTime` resource (built in the second call to `add_parameter` method) would be set as value to the key `""` (empty string) in the named parameter hash.
|
|
189
|
-
|
|
190
|
-
3. Eventually, the `Currency` resource (in the third call do `add_parameter` method) would be set as value to the same key `""` (empty string) as the previous call, which would overwrite the previous resource.
|
|
191
|
-
|
|
192
|
-
In this case, the call to the api would result in an error, either due to the mismatch of the count of parameters, or due to not having all named parameters defined.
|
|
193
|
-
|
|
194
|
-
So, make sure to always use the same parameter syntax accordingly to your template.
|
|
195
|
-
|
|
196
|
-
The add parameter methods also support block building as well:
|
|
197
|
-
```ruby
|
|
198
|
-
Warb.template.dispatch(recipient_number) do |template|
|
|
199
|
-
template.name = "testing"
|
|
200
|
-
template.language = Warb::Language::ENGLISH_US
|
|
201
|
-
|
|
202
|
-
template.add_text_parameter(content: "Name")
|
|
203
|
-
|
|
204
|
-
template.add_currency_parameter do |currency|
|
|
205
|
-
currency.code = "USD"
|
|
206
|
-
currency.amount = 11.42
|
|
207
|
-
currency.fallback = "$ 11.42"
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
template.add_date_time_parameter do |purchase_date|
|
|
211
|
-
purchase_date.date_time = "Jan 1st, 2024"
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
If your template has any media header, you can set it as follow:
|
|
217
|
-
| Header Type | Template Instance Method | Params |
|
|
218
|
-
|----------------|-----------------------------|------------------------------------------------|
|
|
219
|
-
| `image` | `add_image_header` | `media_id` or `link` |
|
|
220
|
-
| `video` | `add_video_header` | `media_id` or `link` |
|
|
221
|
-
| `document` | `add_document_header` | `media_id` or `link`, `filename` |
|
|
222
|
-
| `location` | `add_location_header` | `latitude`, `longitude`, `name`, and `address` |
|
|
223
|
-
| `text` | `add_text_header` | `content`, `parameter_name` |
|
|
224
|
-
|
|
225
|
-
Every time a call is made to any `add_header` method, a new header will be set, overwriting the previous one.
|
|
226
|
-
|
|
227
|
-
If you just want to change one attribute or another, `add_header` methods return the related resource, so it is possible to set the values if you keep a hold of such instance
|
|
228
|
-
```ruby
|
|
229
|
-
Warb.template.dispatch(recipient_number) do |template|
|
|
230
|
-
header = template.add_image_header(media_id: "wrong_media_id")
|
|
231
|
-
|
|
232
|
-
header.media_id = "correct_media_id"
|
|
233
|
-
end
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
Also, either only one of `media_id` or `link` must be provided.
|
|
237
|
-
|
|
238
|
-
The `media_id` must be the id of media uploaded previously to WhatsApp Business Platform, while the `link` must be a public acessible URL.
|
|
239
|
-
|
|
240
|
-
Check the `upload` section for each media related message, like [`image`](./image.md) or [`document`](./document.md), for more info on how to upload and the supported formats.
|
|
241
|
-
|
|
242
|
-
For the `document` header, `filename` is important because its extension will determine the preview capability on the recipient's device.
|
|
243
|
-
|
|
244
|
-
For the `location` header, at least `latitude` and `longitude` must be provided.
|
|
245
|
-
|
|
246
|
-
`add_header` methods will simply instatiate the corresponding resource class with the given parameters, and then, set it as the header attribute.
|
|
247
|
-
|
|
248
|
-
For `text` header, note that, due to how the WhatsApp Business Platform works, you can't set the entire content for it (the same that happens with the body of the message).
|
|
249
|
-
|
|
250
|
-
In this case, `add_text_header`, will simply use whatever was given to it as parameter to build the final header in the WhatsApp Business Platform.
|
|
251
|
-
|
|
252
|
-
So, for example, if your tamplate header was created with `Hello, {{1}}!`, then the text passed to `add_text_header` will simply be substituted in that `{{1}}`.
|
|
253
|
-
|
|
254
|
-
If your template was defined using named parameters instead (something like `Hello, {{customer_name}}!`), then you must pass the name of the paramter to `add_text_header` as follow:
|
|
255
|
-
```ruby
|
|
256
|
-
Warb.template.dispatch(recipient_number) do |template|
|
|
257
|
-
template.add_text_header(content: "John", parameter_name: "customer_name")
|
|
258
|
-
end
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
When the template instance's `build_payload` method is called (which happens when the message is about to be dispatched), the header param will be created using the `header`'s `build_header` method.
|
|
262
|
-
|
|
263
|
-
#### Adding Buttons
|
|
264
|
-
|
|
265
|
-
If your template supports buttons, you can add them using the following methods:
|
|
266
|
-
|
|
267
|
-
| Button Type | Template Instance Method | Params |
|
|
268
|
-
|--------------------|-------------------------------|-------------------------------------------|
|
|
269
|
-
| `quick_reply` | `add_quick_reply_button` | `index` |
|
|
270
|
-
| `url` | `add_dynamic_url_button` | `index`, `text` |
|
|
271
|
-
| `url` | `add_auth_code_button` | `index`, `text` |
|
|
272
|
-
| `copy_code` | `add_copy_code_button` | `index`, `coupon_code` |
|
|
273
|
-
| `voice_call` | `add_voice_call_button` | `index` |
|
|
274
|
-
| `doesn't apply` | `add_button` | `instance`, `&block` |
|
|
275
|
-
|
|
276
|
-
You can either use the keyword parameters or set the attributes using a block:
|
|
277
|
-
|
|
278
|
-
```ruby
|
|
279
|
-
Warb.template.dispatch(recipient_number) do |template|
|
|
280
|
-
template.name = "order_confirmation"
|
|
281
|
-
template.language = Warb::Language::ENGLISH_US
|
|
282
|
-
|
|
283
|
-
# Add a quick reply button
|
|
284
|
-
template.add_quick_reply_button
|
|
285
|
-
|
|
286
|
-
# Add a dynamic URL button
|
|
287
|
-
template.add_dynamic_url_button do |button|
|
|
288
|
-
button.text = "dynamic-url-suffix"
|
|
289
|
-
end
|
|
290
|
-
|
|
291
|
-
# Add a copy auth code button
|
|
292
|
-
template.add_auth_code_button do |button|
|
|
293
|
-
button.text = "4UTHC0D3"
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
# Add a copy code button
|
|
297
|
-
template.add_copy_code_button(index: 2) do |button|
|
|
298
|
-
button.coupon_code = "SAVE20"
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
# Add a voice call button
|
|
302
|
-
template.add_voice_call_button
|
|
303
|
-
end
|
|
304
|
-
```
|
|
305
|
-
|
|
306
|
-
or if you'd rather to, you can add buttons using it's component and the `add_button` method:
|
|
307
|
-
|
|
308
|
-
```ruby
|
|
309
|
-
quick_reply_btn = Warb::Components::QuickReplyButton.new
|
|
310
|
-
|
|
311
|
-
Warb.template.dispatch(recipient_number) do |template|
|
|
312
|
-
template.name = "order_confirmation"
|
|
313
|
-
template.language = Warb::Language::ENGLISH_US
|
|
314
|
-
|
|
315
|
-
# Add a quick reply button
|
|
316
|
-
template.add_button(quick_reply_btn)
|
|
317
|
-
|
|
318
|
-
# Add a quick reply button, passing a block.
|
|
319
|
-
template.add_button(quick_reply_btn) { |button| button.index = 1 }
|
|
320
|
-
end
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
**Note**: The `index` parameter determines the order of the buttons in the template. Make sure the
|
|
324
|
-
indices match the button positions defined in your template. The `index` is automaticaly set if you
|
|
325
|
-
don't do it manually, but it is done based on the number of buttons added with the methods above,
|
|
326
|
-
so if your template has a button that doesn't need configuration like the static url button you'll
|
|
327
|
-
have provide the position of the other buttons.
|
data/docs/resources/currency.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Currency
|
|
2
|
-
|
|
3
|
-
`Warb::Resources::Currency` is a resource, but different from most other resources, it can't be sent. Instead, it's used in a template message as one of its parameters.
|
|
4
|
-
|
|
5
|
-
Please, refer to our [templates messaging documentation](../messages/template.md) for more info.
|
|
6
|
-
|
|
7
|
-
It represents an amount in a specific currency, which can be set with the following attributes:
|
|
8
|
-
| Attribute | Type | Required | Description |
|
|
9
|
-
|------------|--------------------|----------|-------------------------------------------------------------|
|
|
10
|
-
| `amount` | `Integer`, `Float` | Yes | The amount to be represented in the given currency |
|
|
11
|
-
| `code` | `String` | Yes | The code of the currency to be used |
|
|
12
|
-
| `fallback` | `String` | No | A fallback value to be used in case the code can't be found |
|
|
13
|
-
|
|
14
|
-
Since it is used in template messages, it implements both `build_template_named_parameter` and `build_template_positional_parameter`, which prepares the resource for using as parameter.
|
|
15
|
-
|
|
16
|
-
If no `fallback` value is given, then a default one, based on the given `amount` and `currency` is used.
|
|
17
|
-
|
|
18
|
-
In the WhatsApp Business Platform, the `code` will be used to represent the given `amount` according to the specific currency.
|
|
19
|
-
|
|
20
|
-
But if the given code doesn't exist, or is not supported, then the given `fallback` value will be used instead.
|
|
21
|
-
|
|
22
|
-
For the `code`, you must use one currency code like `USD` or `BRL`. `Warb::Resources::Currency` offers some of the most used currencies. You can also [check here](https://www.iso.org/iso-4217-currency-codes.html) for more detailed info and other available options.
|
data/docs/resources/date_time.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Date Time
|
|
2
|
-
|
|
3
|
-
`Warb::Resources::DateTime` is a resource, but different from most other resources, it can't be sent. Instead, it's used in a template message as one of its parameters.
|
|
4
|
-
|
|
5
|
-
Please, refer to our [templates messaging documentation](../messages/template.md) for more info.
|
|
6
|
-
|
|
7
|
-
It simply represents a date time object, with the unique param/attribute being `date_time`.
|
|
8
|
-
|
|
9
|
-
Although its name is `date_time`, its content can be any string, like `"January 1st"`, `"2020-01-01"` or `"Wednesday, Jan, 1st, 2020"`.
|
|
10
|
-
|
|
11
|
-
Since it is used in template messages, it implements both `build_template_named_parameter` and `build_template_positional_parameter`, which prepares the resource for using as parameter.
|
data/docs/resources/index.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Resources
|
|
2
|
-
|
|
3
|
-
Most of the resources can be sent as message. Check the [messages](../messages/index.md) for detailed info.
|
|
4
|
-
|
|
5
|
-
But there are some resources which act more like a component, not being used alone by themself.
|
|
6
|
-
|
|
7
|
-
There are also, resources which can be used alone, and as components for other messages types, like the `Text` resource.
|
|
8
|
-
|
|
9
|
-
Such resources, and where they are used, are listed bellow:
|
|
10
|
-
| Resource | Documentation | Used at |
|
|
11
|
-
|-----------------------------|------------------------------|--------------------------------------------------------------------------------------|
|
|
12
|
-
| `Warb::Resources::Currency` | [Currency](./currency.md) | [Template Messaging](../messages/template.md) |
|
|
13
|
-
| `Warb::Resources::DateTime` | [Date Time](./date_time.md) | [Template Messaging](../messages/template.md) |
|
|
14
|
-
| `Warb::Resources::Text` | [Text](./text.md) | [Text Messaging](../messages/text.md), [Template Messaging](../messages/template.md) |
|
data/docs/resources/text.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# Text
|
|
2
|
-
|
|
3
|
-
`Warb::Resources::Text` is a resource, which represents a text.
|
|
4
|
-
|
|
5
|
-
It can be used as a [simple message](../messages/text.md), as a text header for some interactive messages, like the [reply button message](../messages/interactive_reply_button.md) and as [parameters for templates](../messages/template.md) variables.
|
|
6
|
-
|
|
7
|
-
In the [text messaging documentation](../messages/text.md) there is a table with the corresponding attributes.
|
|
8
|
-
|
|
9
|
-
Aside from such attributes, `Text` resource also provides the `build_template_named_parameter` and `build_template_positional_parameter` methods, which are using under the hood for the template messaging feature.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Warb
|
|
4
|
-
module Components
|
|
5
|
-
class Button < Component
|
|
6
|
-
attr_accessor :index, :sub_type
|
|
7
|
-
|
|
8
|
-
def initialize(**params)
|
|
9
|
-
params[:sub_type] = button_type unless params[:sub_type]
|
|
10
|
-
|
|
11
|
-
super
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def to_h
|
|
15
|
-
{
|
|
16
|
-
type: 'button',
|
|
17
|
-
sub_type: sub_type || @params[:sub_type],
|
|
18
|
-
index: index || @params[:index]
|
|
19
|
-
}
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def button_type
|
|
25
|
-
raise NotImplementedError
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Warb
|
|
4
|
-
module Components
|
|
5
|
-
class Component
|
|
6
|
-
def initialize(**params)
|
|
7
|
-
@params = params
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def to_h
|
|
11
|
-
raise NotImplementedError
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
protected
|
|
15
|
-
|
|
16
|
-
attr_reader :params
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Warb
|
|
4
|
-
module Components
|
|
5
|
-
class CopyCodeButton < Button
|
|
6
|
-
BUTTON_TYPE = 'copy_code'
|
|
7
|
-
|
|
8
|
-
attr_accessor :coupon_code
|
|
9
|
-
|
|
10
|
-
def to_h
|
|
11
|
-
button_payload = super
|
|
12
|
-
|
|
13
|
-
if coupon_code || @params[:coupon_code]
|
|
14
|
-
button_payload[:parameters] = Array.new(1, {
|
|
15
|
-
type: 'coupon_code',
|
|
16
|
-
coupon_code: coupon_code || @params[:coupon_code]
|
|
17
|
-
})
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
button_payload
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def button_type
|
|
26
|
-
BUTTON_TYPE
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Warb
|
|
4
|
-
module Components
|
|
5
|
-
class UrlButton < Button
|
|
6
|
-
BUTTON_TYPE = 'url'
|
|
7
|
-
|
|
8
|
-
attr_accessor :text
|
|
9
|
-
|
|
10
|
-
def to_h
|
|
11
|
-
button_payload = super
|
|
12
|
-
|
|
13
|
-
if text || @params[:text]
|
|
14
|
-
button_payload[:parameters] = Array.new(1, {
|
|
15
|
-
type: 'text',
|
|
16
|
-
text: text || @params[:text]
|
|
17
|
-
})
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
button_payload
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
private
|
|
24
|
-
|
|
25
|
-
def button_type
|
|
26
|
-
BUTTON_TYPE
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
data/lib/warb/errors.rb
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'json'
|
|
4
|
-
|
|
5
|
-
module Warb
|
|
6
|
-
class RequestError < StandardError; end
|
|
7
|
-
class BadRequest < RequestError; end
|
|
8
|
-
class Unauthorized < RequestError; end
|
|
9
|
-
class Forbidden < RequestError; end
|
|
10
|
-
class NotFound < RequestError; end
|
|
11
|
-
class InternalServerError < RequestError; end
|
|
12
|
-
class ServiceUnavailable < RequestError; end
|
|
13
|
-
|
|
14
|
-
# custom error classes
|
|
15
|
-
class IntegrityError < Forbidden; end
|
|
16
|
-
class InvalidBusinessNumber < BadRequest; end
|
|
17
|
-
|
|
18
|
-
class CustomErrors
|
|
19
|
-
def build
|
|
20
|
-
{
|
|
21
|
-
400 => {
|
|
22
|
-
33 => InvalidBusinessNumber
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
data/lib/warb/language.rb
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Warb
|
|
4
|
-
module Resources
|
|
5
|
-
class Currency < Resource
|
|
6
|
-
BRL = 'BRL'
|
|
7
|
-
USD = 'USD'
|
|
8
|
-
|
|
9
|
-
attr_accessor :amount, :code, :fallback
|
|
10
|
-
|
|
11
|
-
def initialize(**params)
|
|
12
|
-
super
|
|
13
|
-
|
|
14
|
-
@code = params[:code]
|
|
15
|
-
@amount = params[:amount]
|
|
16
|
-
@fallback = params[:fallback]
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def build_template_named_parameter(parameter_name)
|
|
20
|
-
common_currency_params.merge(parameter_name: parameter_name)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def build_template_positional_parameter
|
|
24
|
-
common_currency_params
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
private
|
|
28
|
-
|
|
29
|
-
# rubocop:disable Naming/VariableNumber
|
|
30
|
-
def common_currency_params
|
|
31
|
-
{
|
|
32
|
-
type: 'currency',
|
|
33
|
-
currency: {
|
|
34
|
-
amount_1000: amount * 1000,
|
|
35
|
-
code: code,
|
|
36
|
-
fallback_value: fallback || default_fallback_value
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
end
|
|
40
|
-
# rubocop:enable Naming/VariableNumber
|
|
41
|
-
|
|
42
|
-
def default_fallback_value
|
|
43
|
-
"#{amount} (#{code})"
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Warb
|
|
4
|
-
module Resources
|
|
5
|
-
class DateTime < Resource
|
|
6
|
-
attr_accessor :date_time
|
|
7
|
-
|
|
8
|
-
def initialize(date_time = nil, **params)
|
|
9
|
-
super(**params)
|
|
10
|
-
|
|
11
|
-
@date_time = date_time || params[:date_time]
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def build_template_named_parameter(parameter_name)
|
|
15
|
-
common_date_time_params.merge(parameter_name: parameter_name)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def build_template_positional_parameter
|
|
19
|
-
common_date_time_params
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
private
|
|
23
|
-
|
|
24
|
-
def common_date_time_params
|
|
25
|
-
{
|
|
26
|
-
type: 'date_time',
|
|
27
|
-
date_time: {
|
|
28
|
-
fallback_value: date_time
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|