sendly 3.39.0 → 4.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/CHANGELOG.md +148 -1
- data/Gemfile.lock +3 -3
- data/README.md +133 -0
- data/lib/sendly/account_resource.rb +4 -4
- data/lib/sendly/campaigns_resource.rb +8 -8
- data/lib/sendly/contacts_resource.rb +9 -9
- data/lib/sendly/enterprise.rb +26 -26
- data/lib/sendly/templates_resource.rb +6 -6
- data/lib/sendly/verify.rb +3 -3
- data/lib/sendly/version.rb +1 -1
- data/lib/sendly/webhooks.rb +369 -78
- data/lib/sendly/webhooks_resource.rb +10 -10
- 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: 40344d4fa41e8c72544b0b5327b7bc4d717285c38d244397bf0f93ad21ce5b1a
|
|
4
|
+
data.tar.gz: d0bf2bd2c6256ccdbdea1f8c9319c5891b5a030b798a091e7afc59d33752b543
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 20aa959ad9bd7f630c1e26b0a511648aecbfb02d095a789d2d17500e2e035eb02b79fad1c9ae6dc9e0959c41dda68d73c97b1a3d1a795f2dedacd41f8ef03262
|
|
7
|
+
data.tar.gz: 70f56c72f0b628b86e5ea964de3653b7e16d00fa9c4a5214ef14038dbf3da30feedf84b3b489bbfdfd316c42d70f4116ff6b914fe358d7204498d41601a8213a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,151 @@
|
|
|
1
1
|
# sendly (Ruby)
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
**Upgrading from 3.40.0:** that release already contained the breaking changes below, published by mistake as a minor version. 4.0.0 carries them under the correct major. Relative to 3.40.0, the only new changes are under **Security**.
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
- **A webhook that is not a message is no longer presented as one.** `parse_event` built a `Sendly::WebhookMessageData` out of every `data.object`, whatever the event was. For an `rcs_*`, `whatsapp_*`, `call.*`, `brand.*`, `campaign.*`, `assignment.*`, `number.*`, `port*`, `contact*`, `conversation.*` or `draft.*` payload that dropped every field the event actually carried — `agent_id`, `stage`, `port_request_id`, `duration_secs` and the rest were unreachable — and filled the gaps with message fields that were never sent. `event.data` is now a `Sendly::WebhookObject`, a hash-like view of `data.object`: read a key with `[]` (String or Symbol), a reader method of the same name, or `to_h`. `event.message` is the message view and is `nil` for all of the above; `message.*` events are unchanged, and `event.data` is still the `WebhookMessageData` there.
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
# before — "" for every RCS event, and the agent was unreachable
|
|
13
|
+
event.data.from
|
|
14
|
+
# after
|
|
15
|
+
event.data[:agent_id] # => "bb22cc33-..."
|
|
16
|
+
event.message # => nil
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **Absent fields are `nil` instead of a plausible-looking default.** `WebhookMessageData` defaulted `segments` to `1`, `credits_used` to `0`, `direction` to `"outbound"`, `from` to `""` and `id` to `""`, none of which a handler could tell from a real value. They are now `nil` when the payload did not carry them, and `data.key?(:segments)` says which case you are in. `WebhookVerificationData` loses the same kind of defaults (`delivery_status` `"queued"`, `attempts` `0`, `max_attempts` `3`), though nothing could reach that class before this release.
|
|
20
|
+
|
|
21
|
+
- **JSON `null` survives as `nil`.** `from` and `to` on a `call.*` event are `null` for every in-app call; `from` used to arrive as `""`. Code branching on `from.empty?` should branch on `nil` now.
|
|
22
|
+
|
|
23
|
+
- **`event.data.to_h` returns `data.object` as it arrived.** It used to return a compacted subset of the typed message fields, which dropped `text`, `metadata`, `media_urls`, `message_format` and `organization_id`, renamed `message_id` to `id`, and emitted the invented `segments`/`credits_used` defaults. `event.to_h[:data]` is the same hash. For a current-shape payload the familiar keys are all still there.
|
|
24
|
+
|
|
25
|
+
- **`id` is no longer filled from an unrelated `id` key.** `contact.auto_flagged` carries the contact under `id` and the message that failed under `message_id`, so `event.data.message_id` returned the *contact* id — a handler that marked that message failed acted on the wrong row. Contact events have no message view at all now; read the message with `event.data[:message_id]`.
|
|
26
|
+
|
|
27
|
+
### Migrating from 3.x
|
|
28
|
+
|
|
29
|
+
Nothing outside webhook handling changed. The client, every resource and every
|
|
30
|
+
`message.*` handler you already have keep working as written; the list below is
|
|
31
|
+
the whole edit.
|
|
32
|
+
|
|
33
|
+
**1. Reading a message field off a lifecycle event now raises.** 3.x decoded
|
|
34
|
+
every `data.object` into a `Sendly::WebhookMessageData`, so an `rcs_agent.live`
|
|
35
|
+
handler that asked for `event.data.from` was handed `""`, `event.data.segments`
|
|
36
|
+
`1` and `event.data.credits_used` `0` — values the event never carried, not
|
|
37
|
+
distinguishable from real ones, and no error was raised. The same calls raise
|
|
38
|
+
`NoMethodError` in 4.0, naming the keys that did arrive. That failure is the
|
|
39
|
+
point of this release rather than an accident of it: the value it replaces was
|
|
40
|
+
wrong, and silently so.
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
# 3.x — silently wrong, on every RCS event
|
|
44
|
+
event.data.from # => ""
|
|
45
|
+
event.data.segments # => 1
|
|
46
|
+
|
|
47
|
+
# 4.0 — the same call
|
|
48
|
+
event.data.from
|
|
49
|
+
# => NoMethodError: undefined method 'from' for Sendly::WebhookObject:
|
|
50
|
+
# this event's data.object carries agent_id, name, stage, organization_id
|
|
51
|
+
|
|
52
|
+
# 4.0 — the edit: read the object the event actually carries
|
|
53
|
+
event.data[:agent_id] # => "bb22cc33-dd44-4e55-9f66-001122334455"
|
|
54
|
+
event.data.stage # => "live"
|
|
55
|
+
event.raw_object # => the whole data.object Hash, untouched
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**2. `event.data` is a message view only on `message.*` events.** In 3.x it was
|
|
59
|
+
a `WebhookMessageData` whatever the event was, so `event.data.id` and
|
|
60
|
+
`event.data.status` answered for anything — with the payload's value when the
|
|
61
|
+
key happened to exist, and with `''` or `nil` when it did not. In 4.0 a
|
|
62
|
+
lifecycle event's `event.data` is a `Sendly::WebhookObject`: the keys the
|
|
63
|
+
payload carried are readable and nothing else is. `event.message` is new in 4.0
|
|
64
|
+
and is the message view; it is `nil` outside `message.*`, so guard it with
|
|
65
|
+
`event.message?` rather than calling into it unconditionally.
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
# 3.x — answered for every event type; "" when the payload had no id
|
|
69
|
+
mark_delivered(event.data.id)
|
|
70
|
+
|
|
71
|
+
# 4.0 — split the branches
|
|
72
|
+
case event.type
|
|
73
|
+
when Sendly::Webhooks::EVENT_MESSAGE_DELIVERED
|
|
74
|
+
mark_delivered(event.message.id) # same value as 3.x
|
|
75
|
+
when Sendly::Webhooks::EVENT_NUMBER_ACTIVATED
|
|
76
|
+
number_active(event.data[:id]) # the number's id, as it always was
|
|
77
|
+
when Sendly::Webhooks::EVENT_RCS_AGENT_LIVE
|
|
78
|
+
agent_went_live(event.data[:agent_id]) # unreachable in 3.x
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**3. `contact.auto_flagged` no longer reports the contact as the message.** The
|
|
83
|
+
payload carries the contact under `id` and the message that failed under
|
|
84
|
+
`message_id`; 3.x filled the message view's `id` from the contact, so a handler
|
|
85
|
+
that marked "the message" failed acted on the wrong record.
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
# 3.x — the CONTACT id, presented as a message id
|
|
89
|
+
event.data.message_id # => "ct_9"
|
|
90
|
+
|
|
91
|
+
# 4.0
|
|
92
|
+
event.data[:id] # => "ct_9" the contact
|
|
93
|
+
event.data[:message_id] # => "msg_77" the message that failed
|
|
94
|
+
event.message # => nil
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**4. Message fields the payload omitted are `nil`, not a default.** On a
|
|
98
|
+
`message.*` event the readers still exist, so this raises nothing — it changes
|
|
99
|
+
what you get. `key?` separates "absent" from "arrived as null".
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
# message.delivered, on a payload that carried no segments
|
|
103
|
+
event.data.segments # 3.x => 1 4.0 => nil
|
|
104
|
+
event.data.credits_used # 3.x => 0 4.0 => nil
|
|
105
|
+
event.data.direction # 3.x => "outbound" 4.0 => nil
|
|
106
|
+
event.data.key?(:segments) # => false when absent, true when it arrived as null
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**5. `event.data.to_h` is now `data.object` as it arrived.** It used to be a
|
|
110
|
+
compacted subset of the typed message fields, dropping `text`, `metadata`,
|
|
111
|
+
`media_urls`, `message_format` and `organization_id` and renaming `message_id`
|
|
112
|
+
to `id`. Code that persisted `to_h` will start seeing the full object.
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
event.data.to_h == event.raw_object # => true, for every event type
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**6. If you want a typed object for a lifecycle event, ask for one.**
|
|
119
|
+
`#object_as` fills a Struct or Data class from the members it declares and
|
|
120
|
+
ignores the rest of the payload, so a field added to the event later cannot
|
|
121
|
+
break the call.
|
|
122
|
+
|
|
123
|
+
```ruby
|
|
124
|
+
AgentLive = Struct.new(:agent_id, :name, :stage)
|
|
125
|
+
agent = event.object_as(AgentLive)
|
|
126
|
+
agent.stage # => "live"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Deprecations
|
|
130
|
+
|
|
131
|
+
- **`Sendly::Webhooks::EVENT_MESSAGE_QUEUED` is deprecated.** The API has never
|
|
132
|
+
emitted `message.queued`, and subscribing to it fails: `client.webhooks.create`
|
|
133
|
+
and `client.webhooks.update` reject any event outside the API's list with a
|
|
134
|
+
400, raised here as `Sendly::ValidationError`. The constant stays exported in
|
|
135
|
+
4.0 so existing code still loads, and will be removed in the next major.
|
|
136
|
+
`message.undelivered` is rejected on subscribe the same way and has never had
|
|
137
|
+
a constant in this SDK. Subscribe to `message.sent`, `message.failed` and
|
|
138
|
+
`message.bounced` instead. Every other `EVENT_*` constant matches the API's
|
|
139
|
+
list exactly.
|
|
4
140
|
|
|
5
141
|
### Minor Changes
|
|
6
142
|
|
|
143
|
+
- **`Sendly::WebhookEvent#raw_object`** carries `data.object` exactly as it arrived, for every event type, and **`#object_as(klass)`** reads it as a type of your choosing (`event.object_as(AgentLive)`). `#object` is an alias for `raw_object`.
|
|
144
|
+
|
|
145
|
+
- **`Sendly::WebhookVerificationData` is reachable.** Nothing ever constructed it, and it read String keys while `parse_event` symbolizes names, so it could not have worked if anything had. `verification.*` events now build one, as `event.verification` and `event.data`, and every reader takes String or Symbol keys.
|
|
146
|
+
|
|
147
|
+
- **`Sendly::WebhookEvent` gains `#message?` and `#verification?`** for the two cases that have a typed view.
|
|
148
|
+
|
|
7
149
|
- **`Sendly::ValidationError#field_errors` is now populated.** It was always `nil` before, because the API path never passed it. It now carries the response body's `errors` array on any 400 or 422, on every resource rather than just RCS: `client.contacts.import` already returns one, for example. Each entry is a Hash. Code that treats a truthy `field_errors` as "this only happens for X" should be rechecked.
|
|
8
150
|
|
|
9
151
|
|
|
@@ -22,6 +164,11 @@
|
|
|
22
164
|
|
|
23
165
|
- **`Sendly::ValidationError#field_errors` carries the API's `errors` list** (`[{ "path", "message" }, ...]`) when a 400 or 422 response includes one, instead of always being `nil`. RCS registration uses it to say which brand, agent, campaign or device field needs attention.
|
|
24
166
|
|
|
167
|
+
|
|
168
|
+
### Security
|
|
169
|
+
|
|
170
|
+
- **Path parameters are percent-encoded.** Every id you pass is now encoded (`URI.encode_www_form_component`) before it goes into the request path. An id containing `/`, `?` or `#` used to change which endpoint the request reached: an id of `../../account/keys` left its collection and hit another endpoint carrying your API key. Ordinary ids are sent byte-for-byte as before.
|
|
171
|
+
|
|
25
172
|
## 3.38.0
|
|
26
173
|
|
|
27
174
|
### Minor Changes
|
data/Gemfile.lock
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
sendly (
|
|
4
|
+
sendly (4.0.0)
|
|
5
5
|
faraday (~> 2.0)
|
|
6
6
|
faraday-retry (~> 2.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
addressable (2.
|
|
11
|
+
addressable (2.8.8)
|
|
12
12
|
public_suffix (>= 2.0.2, < 8.0)
|
|
13
13
|
ast (2.4.3)
|
|
14
14
|
bigdecimal (3.3.1)
|
|
@@ -74,7 +74,7 @@ GEM
|
|
|
74
74
|
unicode-emoji (~> 4.1)
|
|
75
75
|
unicode-emoji (4.1.0)
|
|
76
76
|
uri (1.1.1)
|
|
77
|
-
webmock (3.26.
|
|
77
|
+
webmock (3.26.1)
|
|
78
78
|
addressable (>= 2.8.0)
|
|
79
79
|
crack (>= 0.3.2)
|
|
80
80
|
hashdiff (>= 0.4.0, < 2.0.0)
|
data/README.md
CHANGED
|
@@ -308,6 +308,8 @@ Full details: https://sendly.live/docs/idempotency
|
|
|
308
308
|
|
|
309
309
|
## Webhooks
|
|
310
310
|
|
|
311
|
+
### Managing endpoints
|
|
312
|
+
|
|
311
313
|
```ruby
|
|
312
314
|
# Create a webhook endpoint
|
|
313
315
|
webhook = client.webhooks.create(
|
|
@@ -340,6 +342,137 @@ rotation = client.webhooks.rotate_secret("whk_xxx")
|
|
|
340
342
|
client.webhooks.delete("whk_xxx")
|
|
341
343
|
```
|
|
342
344
|
|
|
345
|
+
Subscribe with the `Sendly::Webhooks::EVENT_*` constants rather than string
|
|
346
|
+
literals — a typo then fails at load time instead of in a 400. Every constant
|
|
347
|
+
but one names an event the API accepts on subscribe. The exception is
|
|
348
|
+
`EVENT_MESSAGE_QUEUED`: `message.queued` has never been emitted and is
|
|
349
|
+
rejected on subscribe with a 400 (`Sendly::ValidationError`). It is
|
|
350
|
+
deprecated, kept only so existing code still loads, and will be removed in the
|
|
351
|
+
next major. `message.undelivered` is rejected in the same way and has never had
|
|
352
|
+
a constant here. Subscribe to `message.sent`, `message.failed` and
|
|
353
|
+
`message.bounced` instead.
|
|
354
|
+
|
|
355
|
+
### Receiving events
|
|
356
|
+
|
|
357
|
+
`Sendly::Webhooks.parse_event` verifies the signature and returns a
|
|
358
|
+
`Sendly::WebhookEvent`. Pass the raw request body — not a re-serialized hash,
|
|
359
|
+
which would no longer match the signature.
|
|
360
|
+
|
|
361
|
+
```ruby
|
|
362
|
+
event = Sendly::Webhooks.parse_event(
|
|
363
|
+
request.raw_post,
|
|
364
|
+
request.headers["X-Sendly-Signature"],
|
|
365
|
+
ENV.fetch("SENDLY_WEBHOOK_SECRET"),
|
|
366
|
+
timestamp: request.headers["X-Sendly-Timestamp"]
|
|
367
|
+
)
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
`event.raw_object` is `data.object` exactly as it arrived, for every event
|
|
371
|
+
type. `event.data` is a hash-like view of the same object: read a key with
|
|
372
|
+
`[]` (String or Symbol), a reader method of the same name, or `to_h`.
|
|
373
|
+
|
|
374
|
+
```ruby
|
|
375
|
+
case event.type
|
|
376
|
+
when Sendly::Webhooks::EVENT_MESSAGE_DELIVERED
|
|
377
|
+
# message.* events also get a typed message view
|
|
378
|
+
puts "#{event.message.id} -> #{event.message.to}"
|
|
379
|
+
when Sendly::Webhooks::EVENT_RCS_AGENT_LIVE
|
|
380
|
+
puts event.data[:agent_id]
|
|
381
|
+
puts event.data.stage
|
|
382
|
+
when Sendly::Webhooks::EVENT_CALL_COMPLETED
|
|
383
|
+
puts event.data[:duration_secs]
|
|
384
|
+
end
|
|
385
|
+
|
|
386
|
+
# Or read data.object as a type of your own. A Struct or Data class is filled
|
|
387
|
+
# from the members it declares and ignores the rest of the payload, so a field
|
|
388
|
+
# added to the event later cannot break the call.
|
|
389
|
+
AgentLive = Struct.new(:agent_id, :name, :stage)
|
|
390
|
+
agent = event.object_as(AgentLive)
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Two things the SDK will not do, because both make a handler act on data that
|
|
394
|
+
was never sent:
|
|
395
|
+
|
|
396
|
+
- **Nothing is invented.** A field the payload did not carry is `nil`, and
|
|
397
|
+
`event.data.key?(:segments)` is `false`. `segments`, `credits_used`,
|
|
398
|
+
`direction`, `to` and `from` are no longer defaulted to `1`, `0`,
|
|
399
|
+
`"outbound"` and `""`.
|
|
400
|
+
- **`nil` stays `nil`.** An in-app `call.*` event carries `from` and `to` as
|
|
401
|
+
JSON `null`; they come back as `nil`, not `""`.
|
|
402
|
+
|
|
403
|
+
`event.message` is the message view and is `nil` for every event that is not a
|
|
404
|
+
message — `rcs_*`, `whatsapp_*`, `call.*`, `brand.*`, `campaign.*`,
|
|
405
|
+
`assignment.*`, `number.*`, `port*`, `contact*`, `conversation.*` and
|
|
406
|
+
`draft.*`, whose payloads are not message-shaped. `verification.*` events get
|
|
407
|
+
`event.verification`, a `Sendly::WebhookVerificationData`. `event.data` is the
|
|
408
|
+
typed view where one exists and a plain `Sendly::WebhookObject` otherwise, so
|
|
409
|
+
reading `data.object` works the same way for all of them, including an event
|
|
410
|
+
type this SDK predates.
|
|
411
|
+
|
|
412
|
+
Note that `contact.auto_flagged` carries the contact under `id` and the message
|
|
413
|
+
that failed under `message_id`; read the message with
|
|
414
|
+
`event.data[:message_id]`.
|
|
415
|
+
|
|
416
|
+
### Handling a lifecycle event
|
|
417
|
+
|
|
418
|
+
Only `message.*` events carry a message. A lifecycle event — `rcs_*`,
|
|
419
|
+
`whatsapp_*`, `call.*`, `brand.*`, `campaign.*`, `assignment.*`, `number.*`,
|
|
420
|
+
`port*`, `contact*`, `conversation.*`, `draft.*` — carries a different object,
|
|
421
|
+
so `event.message` is `nil` and you read `data.object` off `event.data` or
|
|
422
|
+
`event.raw_object`.
|
|
423
|
+
|
|
424
|
+
```ruby
|
|
425
|
+
require "sendly"
|
|
426
|
+
|
|
427
|
+
# Framework-neutral: hand it the raw request body and a headers Hash.
|
|
428
|
+
def handle_sendly_webhook(raw_body, headers)
|
|
429
|
+
event = Sendly::Webhooks.parse_event(
|
|
430
|
+
raw_body,
|
|
431
|
+
headers["X-Sendly-Signature"],
|
|
432
|
+
ENV.fetch("SENDLY_WEBHOOK_SECRET"),
|
|
433
|
+
timestamp: headers["X-Sendly-Timestamp"]
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
case event.type
|
|
437
|
+
when Sendly::Webhooks::EVENT_RCS_AGENT_LIVE
|
|
438
|
+
# data.object is the agent: agent_id, name, stage
|
|
439
|
+
puts "RCS agent #{event.data[:name]} is #{event.data.stage}"
|
|
440
|
+
puts event.data[:agent_id]
|
|
441
|
+
when Sendly::Webhooks::EVENT_NUMBER_ACTIVATED
|
|
442
|
+
# data.object is the number: id, phone, status, country_code, source
|
|
443
|
+
puts "#{event.data[:phone]} active in #{event.data[:country_code]}"
|
|
444
|
+
when Sendly::Webhooks::EVENT_CONTACT_AUTO_FLAGGED
|
|
445
|
+
# the contact is `id`; the message that failed is `message_id`
|
|
446
|
+
puts "flagged #{event.data[:id]} (#{event.data[:invalid_reason]})"
|
|
447
|
+
puts "from message #{event.data[:message_id]}"
|
|
448
|
+
when Sendly::Webhooks::EVENT_MESSAGE_DELIVERED
|
|
449
|
+
# message.* events, and only these, also get the typed message view
|
|
450
|
+
puts "#{event.message.id} delivered to #{event.message.to}"
|
|
451
|
+
else
|
|
452
|
+
# An event type this SDK predates still parses; raw_object holds all of it.
|
|
453
|
+
puts "unhandled #{event.type}: #{event.raw_object.inspect}"
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
:ok
|
|
457
|
+
rescue Sendly::WebhookSignatureError
|
|
458
|
+
:unauthorized
|
|
459
|
+
end
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Reading a message field off a lifecycle event fails loudly rather than
|
|
463
|
+
answering with a value the event never carried:
|
|
464
|
+
|
|
465
|
+
```ruby
|
|
466
|
+
event.data.from
|
|
467
|
+
# => NoMethodError: undefined method 'from' for Sendly::WebhookObject:
|
|
468
|
+
# this event's data.object carries agent_id, name, stage, organization_id
|
|
469
|
+
event.message # => nil
|
|
470
|
+
event.message.id # => NoMethodError — nil has no #id
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
Branch on `event.type`, or on `event.message?` / `event.verification?`, before
|
|
474
|
+
reaching for a typed view.
|
|
475
|
+
|
|
343
476
|
## Account & Credits
|
|
344
477
|
|
|
345
478
|
```ruby
|
|
@@ -55,7 +55,7 @@ module Sendly
|
|
|
55
55
|
# @param key_id [String] API key ID
|
|
56
56
|
# @return [Sendly::ApiKey]
|
|
57
57
|
def api_key(key_id)
|
|
58
|
-
response = @client.get("/account/keys/#{key_id}")
|
|
58
|
+
response = @client.get("/account/keys/#{URI.encode_www_form_component(key_id)}")
|
|
59
59
|
ApiKey.new(response)
|
|
60
60
|
end
|
|
61
61
|
|
|
@@ -64,7 +64,7 @@ module Sendly
|
|
|
64
64
|
# @param key_id [String] API key ID
|
|
65
65
|
# @return [Hash] Usage statistics
|
|
66
66
|
def api_key_usage(key_id)
|
|
67
|
-
@client.get("/account/keys/#{key_id}/usage")
|
|
67
|
+
@client.get("/account/keys/#{URI.encode_www_form_component(key_id)}/usage")
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
# Create a new API key
|
|
@@ -96,7 +96,7 @@ module Sendly
|
|
|
96
96
|
body = {}
|
|
97
97
|
body[:reason] = reason if reason
|
|
98
98
|
|
|
99
|
-
@client.patch("/account/keys/#{key_id}/revoke", body)
|
|
99
|
+
@client.patch("/account/keys/#{URI.encode_www_form_component(key_id)}/revoke", body)
|
|
100
100
|
end
|
|
101
101
|
|
|
102
102
|
# Rotate an API key.
|
|
@@ -127,7 +127,7 @@ module Sendly
|
|
|
127
127
|
body = {}
|
|
128
128
|
body[:gracePeriodHours] = grace_period_hours unless grace_period_hours.nil?
|
|
129
129
|
|
|
130
|
-
@client.post("/account/keys/#{key_id}/rotate", body)
|
|
130
|
+
@client.post("/account/keys/#{URI.encode_www_form_component(key_id)}/rotate", body)
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def transfer_credits(target_organization_id:, amount:)
|
|
@@ -131,7 +131,7 @@ module Sendly
|
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
def get(id)
|
|
134
|
-
response = @client.get("/campaigns/#{id}")
|
|
134
|
+
response = @client.get("/campaigns/#{URI.encode_www_form_component(id)}")
|
|
135
135
|
Campaign.new(response)
|
|
136
136
|
end
|
|
137
137
|
|
|
@@ -142,21 +142,21 @@ module Sendly
|
|
|
142
142
|
body[:templateId] = template_id unless template_id.nil?
|
|
143
143
|
body[:contactListIds] = contact_list_ids if contact_list_ids
|
|
144
144
|
|
|
145
|
-
response = @client.patch("/campaigns/#{id}", body)
|
|
145
|
+
response = @client.patch("/campaigns/#{URI.encode_www_form_component(id)}", body)
|
|
146
146
|
Campaign.new(response)
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
def delete(id)
|
|
150
|
-
@client.delete("/campaigns/#{id}")
|
|
150
|
+
@client.delete("/campaigns/#{URI.encode_www_form_component(id)}")
|
|
151
151
|
end
|
|
152
152
|
|
|
153
153
|
def preview(id)
|
|
154
|
-
response = @client.get("/campaigns/#{id}/preview")
|
|
154
|
+
response = @client.get("/campaigns/#{URI.encode_www_form_component(id)}/preview")
|
|
155
155
|
CampaignPreview.new(response)
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
def send_campaign(id)
|
|
159
|
-
response = @client.post("/campaigns/#{id}/send")
|
|
159
|
+
response = @client.post("/campaigns/#{URI.encode_www_form_component(id)}/send")
|
|
160
160
|
Campaign.new(response)
|
|
161
161
|
end
|
|
162
162
|
|
|
@@ -164,17 +164,17 @@ module Sendly
|
|
|
164
164
|
body = { scheduledAt: scheduled_at }
|
|
165
165
|
body[:timezone] = timezone if timezone
|
|
166
166
|
|
|
167
|
-
response = @client.post("/campaigns/#{id}/schedule", body)
|
|
167
|
+
response = @client.post("/campaigns/#{URI.encode_www_form_component(id)}/schedule", body)
|
|
168
168
|
Campaign.new(response)
|
|
169
169
|
end
|
|
170
170
|
|
|
171
171
|
def cancel(id)
|
|
172
|
-
response = @client.post("/campaigns/#{id}/cancel")
|
|
172
|
+
response = @client.post("/campaigns/#{URI.encode_www_form_component(id)}/cancel")
|
|
173
173
|
Campaign.new(response)
|
|
174
174
|
end
|
|
175
175
|
|
|
176
176
|
def clone(id)
|
|
177
|
-
response = @client.post("/campaigns/#{id}/clone")
|
|
177
|
+
response = @client.post("/campaigns/#{URI.encode_www_form_component(id)}/clone")
|
|
178
178
|
Campaign.new(response)
|
|
179
179
|
end
|
|
180
180
|
end
|
|
@@ -114,7 +114,7 @@ module Sendly
|
|
|
114
114
|
params[:limit] = limit if limit
|
|
115
115
|
params[:offset] = offset if offset
|
|
116
116
|
|
|
117
|
-
response = @client.get("/contact-lists/#{id}", params)
|
|
117
|
+
response = @client.get("/contact-lists/#{URI.encode_www_form_component(id)}", params)
|
|
118
118
|
ContactList.new(response)
|
|
119
119
|
end
|
|
120
120
|
|
|
@@ -131,21 +131,21 @@ module Sendly
|
|
|
131
131
|
body[:name] = name if name
|
|
132
132
|
body[:description] = description unless description.nil?
|
|
133
133
|
|
|
134
|
-
response = @client.patch("/contact-lists/#{id}", body)
|
|
134
|
+
response = @client.patch("/contact-lists/#{URI.encode_www_form_component(id)}", body)
|
|
135
135
|
ContactList.new(response)
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
def delete(id)
|
|
139
|
-
@client.delete("/contact-lists/#{id}")
|
|
139
|
+
@client.delete("/contact-lists/#{URI.encode_www_form_component(id)}")
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
def add_contacts(list_id, contact_ids)
|
|
143
|
-
response = @client.post("/contact-lists/#{list_id}/contacts", { contact_ids: contact_ids })
|
|
143
|
+
response = @client.post("/contact-lists/#{URI.encode_www_form_component(list_id)}/contacts", { contact_ids: contact_ids })
|
|
144
144
|
{ added_count: response["added_count"] || response["addedCount"] }
|
|
145
145
|
end
|
|
146
146
|
|
|
147
147
|
def remove_contact(list_id, contact_id)
|
|
148
|
-
@client.delete("/contact-lists/#{list_id}/contacts/#{contact_id}")
|
|
148
|
+
@client.delete("/contact-lists/#{URI.encode_www_form_component(list_id)}/contacts/#{URI.encode_www_form_component(contact_id)}")
|
|
149
149
|
end
|
|
150
150
|
end
|
|
151
151
|
|
|
@@ -175,7 +175,7 @@ module Sendly
|
|
|
175
175
|
end
|
|
176
176
|
|
|
177
177
|
def get(id)
|
|
178
|
-
response = @client.get("/contacts/#{id}")
|
|
178
|
+
response = @client.get("/contacts/#{URI.encode_www_form_component(id)}")
|
|
179
179
|
Contact.new(response)
|
|
180
180
|
end
|
|
181
181
|
|
|
@@ -195,12 +195,12 @@ module Sendly
|
|
|
195
195
|
body[:email] = email unless email.nil?
|
|
196
196
|
body[:metadata] = metadata unless metadata.nil?
|
|
197
197
|
|
|
198
|
-
response = @client.patch("/contacts/#{id}", body)
|
|
198
|
+
response = @client.patch("/contacts/#{URI.encode_www_form_component(id)}", body)
|
|
199
199
|
Contact.new(response)
|
|
200
200
|
end
|
|
201
201
|
|
|
202
202
|
def delete(id)
|
|
203
|
-
@client.delete("/contacts/#{id}")
|
|
203
|
+
@client.delete("/contacts/#{URI.encode_www_form_component(id)}")
|
|
204
204
|
end
|
|
205
205
|
|
|
206
206
|
# Clear the invalid flag on a contact so future campaigns include it again.
|
|
@@ -208,7 +208,7 @@ module Sendly
|
|
|
208
208
|
# error (landline, invalid number) or when a carrier lookup reports they
|
|
209
209
|
# can't receive SMS.
|
|
210
210
|
def mark_valid(id)
|
|
211
|
-
response = @client.post("/contacts/#{id}/mark-valid", {})
|
|
211
|
+
response = @client.post("/contacts/#{URI.encode_www_form_component(id)}/mark-valid", {})
|
|
212
212
|
Contact.new(response)
|
|
213
213
|
end
|
|
214
214
|
|