vatio-sdk 0.7.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74e75fcd7ef82ab7bf6ba02da68a175e7345fb55d8d2cb5921f34990d0a9d4f9
4
- data.tar.gz: '08f6d5cef5a92586543490fbc26c0954c716a47a0b363cdd77c30b53f4aaf800'
3
+ metadata.gz: 8c921c47af7fe3fc6252679275a7717a2c3df5651c2772af28bb99202a8d11bb
4
+ data.tar.gz: 243719a522e1007183c248e847067f975ac727063edba7d561b85c941aecc596
5
5
  SHA512:
6
- metadata.gz: 238c07a9e0f23466337769097f3d426b24c8b050acaf95984ca86cf905c30f7b121d762510ec0d441977c71435829b8ead29a5d0f7ccd99af125cc514b5ea4d1
7
- data.tar.gz: a31fd505377fc32c91a49cc0dbdd873b9cb6fcb113d795e6bb97ceff4faa2f883d7f7a299d2129009a596792d77c009075a3c20649da13ffa290eba51773cd32
6
+ metadata.gz: 733e344de538c7430bbb5c85f51152aa87949a0fa70e0ac0bc01dd2fdffc29bb620887105c3e00e2c604b75506e44bc4bc606e361e7713f095bf5aee1f6393e5
7
+ data.tar.gz: 344d942247e4a56f60fd2a601a917eb4305668d628d40ac8c658b02f092d234c179ad6506b61d40cb4a8cb924b44603fe729f912391c7ce5e4a3553c8c315791
data/README.md CHANGED
@@ -198,8 +198,10 @@ end
198
198
  ```
199
199
 
200
200
  A secret key belongs to one workspace and one environment, and a preview key
201
- can only write to a test phone verified in the inbox's Try the agent panel (WhatsApp). Keep
202
- it on your server: it can message your customers. Net::HTTP does the talking
201
+ can only write, from Vatio's shared WhatsApp number, to someone on the
202
+ workspace's team with their WhatsApp verified, or to a customer phone added in
203
+ the inbox's Try the agent panel (WhatsApp). Keep it on your server: it can
204
+ message your customers. Net::HTTP does the talking
203
205
  (`base_url`, `open_timeout` and `read_timeout` are there if you need them);
204
206
  there is no other dependency.
205
207
 
@@ -233,6 +235,13 @@ you:
233
235
  Vatio::Server.send_message(to: phone, brief: brief, template: shipped.with_params("Ana", "#1042"))
234
236
  ```
235
237
 
238
+ A URL button whose link ends in `{{1}}` takes its value per message, by
239
+ the button's position (`template.buttons` lists them):
240
+
241
+ ```ruby
242
+ template: offer.with_params("Ana").merge(buttons: [{ index: 0, params: [offer.code] }])
243
+ ```
244
+
236
245
  The response only says it is queued: the agent's turn and Meta's delivery
237
246
  both happen after it. `Vatio::Server.message_status(id)` reads it back,
238
247
  with `content` (what reached the phone) once it is sent, and
@@ -292,10 +301,10 @@ end
292
301
  | `OutsideWindow` | `outside_window`, with `last_inbound_at` |
293
302
  | `OptedOut` | `opted_out` |
294
303
  | `HumanAnswering` | `human_takeover`, `handoff_pending` |
295
- | `TemplateError` | `template_not_found` (often created in Meta a minute ago: Vatio is syncing, retry shortly), `template_not_approved`, `template_params`, `template_required` |
304
+ | `TemplateError` | `template_not_found` (often created in Meta a minute ago: Vatio is syncing, retry shortly), `template_not_approved`, `template_params`, `template_buttons`, `template_required` |
296
305
  | `InvalidRequest` | Any other 422: `invalid_recipient`, `content_required`, `invalid_identity`, `not_a_test_phone`… |
297
306
  | `Unauthorized` | 401 / 403: the key is wrong, revoked, or another workspace's |
298
- | `Conflict` | Any other 409: `idempotency_conflict` (`details["message_id"]`), `identity_conflict`, `whatsapp_not_connected`, `whatsapp_paused` |
307
+ | `Conflict` | Any other 409: `idempotency_conflict` (`details["message_id"]`), `identity_conflict`, `whatsapp_not_connected`, `whatsapp_paused`, `whatsapp_number_unhealthy` (Meta refuses every send from the number; `details["issue"]` says why and the fix) |
299
308
  | `NotFound` | `message_status` with an id this key cannot see |
300
309
  | `RateLimited` | 429, more than 60 a minute on one key |
301
310
  | `Unavailable` | 5xx, timeouts, refused connections |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Vatio
4
4
  module Identity
5
- VERSION = "0.7.0"
5
+ VERSION = "0.8.0"
6
6
  end
7
7
  end
@@ -35,8 +35,10 @@ module Vatio
35
35
  # Needs no `to` or `channel`.
36
36
  # brief: what the agent should write about, and the facts to use.
37
37
  # text: your own words, sent as is.
38
- # template: { name:, language:, params: [] }, used only when the 24-hour
39
- # window is closed -- send it too to always reach the person.
38
+ # template: { name:, language:, params: [], buttons: [{ index:, params: [] }] },
39
+ # used only when the 24-hour window is closed -- send it too
40
+ # to always reach the person. `buttons` fills URL buttons
41
+ # whose link ends in {{1}}.
40
42
  # An authentication template takes `code:` instead of params,
41
43
  # with no brief or text, and is sent whatever the window.
42
44
  #
@@ -149,7 +151,18 @@ module Vatio
149
151
  def normalize_template(template)
150
152
  hash = template.to_h.transform_keys(&:to_s)
151
153
  { name: hash["name"], language: hash["language"], params: Array(hash["params"]).map(&:to_s),
152
- code: hash["code"]&.to_s }.compact
154
+ code: hash["code"]&.to_s, buttons: normalize_buttons(hash["buttons"]) }.compact
155
+ end
156
+
157
+ # [{ index: 0, params: ["ABC123"] }]: the value of each URL button whose
158
+ # link ends in {{1}}, by its position.
159
+ def normalize_buttons(buttons)
160
+ return nil if buttons.nil? || buttons.empty?
161
+
162
+ buttons.map do |button|
163
+ button = button.to_h.transform_keys(&:to_s)
164
+ { index: button["index"], params: Array(button["params"]).map(&:to_s) }
165
+ end
153
166
  end
154
167
 
155
168
  def present(value)
@@ -3,15 +3,19 @@
3
3
  module Vatio
4
4
  module Server
5
5
  # A WhatsApp template the key's number can send, from Vatio's mirror of
6
- # Meta's: its body, how many `{{n}}` parameters that body takes, and the
7
- # object `send_message` expects as `template:`.
6
+ # Meta's: its body, how many `{{n}}` parameters that body takes, its
7
+ # buttons, and the object `send_message` expects as `template:`.
8
8
  #
9
9
  # shipped = Vatio::Server.templates.find { |t| t.name == "order_shipped" }
10
10
  # Vatio::Server.send_message(to: phone, brief: brief, template: shipped.with_params("Ana", "#1042"))
11
11
  #
12
+ # A URL button whose link ends in {{1}} takes its value by position:
13
+ #
14
+ # template: offer.with_params("Ana").merge(buttons: [{ index: 0, params: ["ABC123"] }])
15
+ #
12
16
  # Empty on a preview key: the preview number's templates are Vatio's.
13
17
  Template = Struct.new(
14
- :name, :language, :category, :status, :rejected_reason, :body, :parameter_count, :example,
18
+ :name, :language, :category, :status, :rejected_reason, :body, :parameter_count, :buttons, :example,
15
19
  keyword_init: true
16
20
  ) do
17
21
  def self.from(hash) = Value.build(self, hash)
@@ -47,6 +47,7 @@ module Vatio
47
47
  "template_params" => 422, "content_required" => 422, "brief_too_long" => 422, "text_too_long" => 422,
48
48
  "invalid_recipient" => 422, "not_a_test_phone" => 422, "identity_not_configured" => 422,
49
49
  "invalid_identity" => 422, "whatsapp_not_connected" => 409, "whatsapp_paused" => 409,
50
+ "whatsapp_number_unhealthy" => 409,
50
51
  "idempotency_conflict" => 409, "identity_conflict" => 409, "invalid_key" => 401,
51
52
  "workspace_forbidden" => 403, "not_found" => 404, "rate_limited" => 429, "unavailable" => 503,
52
53
  "instagram_not_connected" => 409, "unknown_recipient" => 422, "templates_not_supported" => 422,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vatio-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Urcalab