sendly 4.5.1 → 4.7.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 +20 -0
- data/Gemfile.lock +1 -1
- data/README.md +182 -38
- data/lib/sendly/calls_resource.rb +122 -12
- data/lib/sendly/client.rb +11 -0
- data/lib/sendly/conversations_resource.rb +12 -4
- data/lib/sendly/enterprise.rb +62 -11
- data/lib/sendly/messages.rb +7 -1
- data/lib/sendly/rules_resource.rb +2 -1
- data/lib/sendly/short_codes_resource.rb +336 -0
- data/lib/sendly/templates_resource.rb +21 -0
- data/lib/sendly/types.rb +155 -4
- data/lib/sendly/version.rb +1 -1
- data/lib/sendly/voice_resource.rb +314 -17
- data/lib/sendly/webhooks_resource.rb +20 -0
- data/lib/sendly/whatsapp_resource.rb +20 -7
- data/lib/sendly.rb +1 -0
- metadata +3 -2
data/lib/sendly/types.rb
CHANGED
|
@@ -77,6 +77,10 @@ module Sendly
|
|
|
77
77
|
# message it replaced
|
|
78
78
|
attr_reader :fallback_of
|
|
79
79
|
|
|
80
|
+
# @return [String, nil] The batch that sent the message; nil unless it is
|
|
81
|
+
# a batch message
|
|
82
|
+
attr_reader :batch_id
|
|
83
|
+
|
|
80
84
|
# Message status constants (sending removed - doesn't exist in database)
|
|
81
85
|
STATUSES = %w[queued sent delivered failed bounced retrying].freeze
|
|
82
86
|
|
|
@@ -108,6 +112,7 @@ module Sendly
|
|
|
108
112
|
@message_format = data["messageFormat"] || data["message_format"] || "sms"
|
|
109
113
|
@fallback = data["fallback"].is_a?(Hash) ? WhatsAppSmsFallback.new(data["fallback"]) : nil
|
|
110
114
|
@fallback_of = data["fallbackOf"] || data["fallback_of"]
|
|
115
|
+
@batch_id = data["batchId"] || data["batch_id"]
|
|
111
116
|
end
|
|
112
117
|
|
|
113
118
|
# Check if message was delivered
|
|
@@ -155,7 +160,8 @@ module Sendly
|
|
|
155
160
|
media_urls: media_urls,
|
|
156
161
|
message_format: message_format,
|
|
157
162
|
fallback: fallback&.to_h,
|
|
158
|
-
fallback_of: fallback_of
|
|
163
|
+
fallback_of: fallback_of,
|
|
164
|
+
batch_id: batch_id
|
|
159
165
|
}.compact
|
|
160
166
|
end
|
|
161
167
|
|
|
@@ -368,7 +374,7 @@ module Sendly
|
|
|
368
374
|
@circuit_state = data["circuit_state"] || data["circuitState"] || "closed"
|
|
369
375
|
@circuit_opened_at = parse_time(data["circuit_opened_at"] || data["circuitOpenedAt"])
|
|
370
376
|
@api_version = data["api_version"] || data["apiVersion"] || "2024-01"
|
|
371
|
-
@metadata = data["metadata"]
|
|
377
|
+
@metadata = data["metadata"].is_a?(Hash) ? data["metadata"] : {}
|
|
372
378
|
@created_at = parse_time(data["created_at"] || data["createdAt"])
|
|
373
379
|
@updated_at = parse_time(data["updated_at"] || data["updatedAt"])
|
|
374
380
|
@total_deliveries = data["total_deliveries"] || data["totalDeliveries"] || 0
|
|
@@ -548,6 +554,98 @@ module Sendly
|
|
|
548
554
|
end
|
|
549
555
|
end
|
|
550
556
|
|
|
557
|
+
# What a webhook recovery would do for a window, without sending anything
|
|
558
|
+
#
|
|
559
|
+
# Returned by {Sendly::WebhooksResource#recovery_preview}. The API sends
|
|
560
|
+
# its keys in camelCase; the readers are snake_case and nested values are
|
|
561
|
+
# Hashes with symbol keys. Count maps keep the API's string keys, such as
|
|
562
|
+
# "failed" or "message.delivered".
|
|
563
|
+
class WebhookRecoveryPreview
|
|
564
|
+
# @return [String] "closed", "open" or "half_open"
|
|
565
|
+
attr_reader :circuit_state
|
|
566
|
+
|
|
567
|
+
# @return [Time, nil] When the circuit opened
|
|
568
|
+
attr_reader :circuit_opened_at
|
|
569
|
+
|
|
570
|
+
# @return [Integer] Failed deliveries in the current streak
|
|
571
|
+
attr_reader :failure_count
|
|
572
|
+
|
|
573
|
+
# @return [Hash] Failed and cancelled deliveries in the window, what
|
|
574
|
+
# {Sendly::WebhooksResource#redeliver} would send:
|
|
575
|
+
# +{ total:, by_status:, by_event_type: }+
|
|
576
|
+
attr_reader :audit_failures
|
|
577
|
+
|
|
578
|
+
# @return [Hash] Message events with no delivery in the window, what
|
|
579
|
+
# {Sendly::WebhooksResource#backfill} would send: +{ total:, by_event_type: }+
|
|
580
|
+
attr_reader :missing_from_messages
|
|
581
|
+
|
|
582
|
+
# @return [Array<Hash>] The window in up to 24 equal buckets, oldest
|
|
583
|
+
# first: +{ bucket:, missing:, failed: }+
|
|
584
|
+
attr_reader :histogram
|
|
585
|
+
|
|
586
|
+
# @return [Array<Hash>] Up to 5 affected events:
|
|
587
|
+
# +{ id:, to_masked:, event_type:, occurred_at: }+
|
|
588
|
+
attr_reader :samples
|
|
589
|
+
|
|
590
|
+
# @return [Hash, nil] The outage window, +{ since:, until: }+, when the
|
|
591
|
+
# circuit has an opening time
|
|
592
|
+
attr_reader :window_suggestion
|
|
593
|
+
|
|
594
|
+
# @return [Time, nil] The window's start
|
|
595
|
+
attr_reader :since
|
|
596
|
+
|
|
597
|
+
# @return [Time, nil] The window's end
|
|
598
|
+
attr_reader :until
|
|
599
|
+
|
|
600
|
+
# @return [Hash] The raw parsed response
|
|
601
|
+
attr_reader :raw
|
|
602
|
+
|
|
603
|
+
def initialize(data)
|
|
604
|
+
@raw = data
|
|
605
|
+
@circuit_state = data["circuitState"]
|
|
606
|
+
@circuit_opened_at = parse_time(data["circuitOpenedAt"])
|
|
607
|
+
@failure_count = data["failureCount"] || 0
|
|
608
|
+
audit = data["auditFailures"] || {}
|
|
609
|
+
@audit_failures = {
|
|
610
|
+
total: audit["total"] || 0,
|
|
611
|
+
by_status: audit["byStatus"] || {},
|
|
612
|
+
by_event_type: audit["byEventType"] || {}
|
|
613
|
+
}
|
|
614
|
+
missing = data["missingFromMessages"] || {}
|
|
615
|
+
@missing_from_messages = {
|
|
616
|
+
total: missing["total"] || 0,
|
|
617
|
+
by_event_type: missing["byEventType"] || {}
|
|
618
|
+
}
|
|
619
|
+
@histogram = (data["histogram"] || []).map do |b|
|
|
620
|
+
{ bucket: parse_time(b["bucket"]), missing: b["missing"], failed: b["failed"] }
|
|
621
|
+
end
|
|
622
|
+
@samples = (data["samples"] || []).map do |s|
|
|
623
|
+
{ id: s["id"], to_masked: s["toMasked"], event_type: s["eventType"],
|
|
624
|
+
occurred_at: parse_time(s["occurredAt"]) }
|
|
625
|
+
end
|
|
626
|
+
suggestion = data["windowSuggestion"]
|
|
627
|
+
@window_suggestion = suggestion && {
|
|
628
|
+
since: parse_time(suggestion["since"]),
|
|
629
|
+
until: parse_time(suggestion["until"])
|
|
630
|
+
}
|
|
631
|
+
@since = parse_time(data["since"])
|
|
632
|
+
@until = parse_time(data["until"])
|
|
633
|
+
end
|
|
634
|
+
|
|
635
|
+
def circuit_open?
|
|
636
|
+
circuit_state == "open"
|
|
637
|
+
end
|
|
638
|
+
|
|
639
|
+
private
|
|
640
|
+
|
|
641
|
+
def parse_time(value)
|
|
642
|
+
return nil if value.nil?
|
|
643
|
+
Time.parse(value)
|
|
644
|
+
rescue ArgumentError
|
|
645
|
+
nil
|
|
646
|
+
end
|
|
647
|
+
end
|
|
648
|
+
|
|
551
649
|
# ============================================================================
|
|
552
650
|
# Account & Credits
|
|
553
651
|
# ============================================================================
|
|
@@ -854,10 +952,24 @@ module Sendly
|
|
|
854
952
|
# @return [String, nil] Model that generated the suggestions
|
|
855
953
|
attr_reader :model
|
|
856
954
|
|
|
955
|
+
# @return [Boolean] True when the workspace's enterprise account turned
|
|
956
|
+
# AI suggestions off; {#suggestions} is then empty
|
|
957
|
+
attr_reader :disabled
|
|
958
|
+
|
|
959
|
+
# @return [String, nil] Why suggestions are off: "enterprise_policy".
|
|
960
|
+
# Nil unless {#disabled} is true
|
|
961
|
+
attr_reader :reason
|
|
962
|
+
|
|
857
963
|
def initialize(data)
|
|
858
964
|
@suggestions = (data["suggestions"] || []).map { |s| SuggestedReply.new(s) }
|
|
859
965
|
@based_on_message_id = data["basedOnMessageId"] || data["based_on_message_id"]
|
|
860
966
|
@model = data["model"]
|
|
967
|
+
@disabled = data["disabled"] == true
|
|
968
|
+
@reason = data["reason"]
|
|
969
|
+
end
|
|
970
|
+
|
|
971
|
+
def disabled?
|
|
972
|
+
disabled
|
|
861
973
|
end
|
|
862
974
|
|
|
863
975
|
def each(&block)
|
|
@@ -883,7 +995,9 @@ module Sendly
|
|
|
883
995
|
{
|
|
884
996
|
suggestions: suggestions.map(&:to_h),
|
|
885
997
|
based_on_message_id: based_on_message_id,
|
|
886
|
-
model: model
|
|
998
|
+
model: model,
|
|
999
|
+
disabled: (disabled || nil),
|
|
1000
|
+
reason: reason
|
|
887
1001
|
}.compact
|
|
888
1002
|
end
|
|
889
1003
|
end
|
|
@@ -1087,7 +1201,7 @@ module Sendly
|
|
|
1087
1201
|
# ============================================================================
|
|
1088
1202
|
|
|
1089
1203
|
class Rule
|
|
1090
|
-
attr_reader :id, :name, :conditions, :actions, :priority, :created_at, :updated_at
|
|
1204
|
+
attr_reader :id, :name, :conditions, :actions, :priority, :enabled, :created_at, :updated_at
|
|
1091
1205
|
|
|
1092
1206
|
def initialize(data)
|
|
1093
1207
|
@id = data["id"]
|
|
@@ -1095,6 +1209,7 @@ module Sendly
|
|
|
1095
1209
|
@conditions = data["conditions"] || {}
|
|
1096
1210
|
@actions = data["actions"] || {}
|
|
1097
1211
|
@priority = data["priority"]
|
|
1212
|
+
@enabled = data["enabled"]
|
|
1098
1213
|
@created_at = parse_time(data["createdAt"] || data["created_at"])
|
|
1099
1214
|
@updated_at = parse_time(data["updatedAt"] || data["updated_at"])
|
|
1100
1215
|
end
|
|
@@ -1121,6 +1236,42 @@ module Sendly
|
|
|
1121
1236
|
# Generated Template
|
|
1122
1237
|
# ============================================================================
|
|
1123
1238
|
|
|
1239
|
+
# A template rendered with the values you gave. Nothing is sent or saved.
|
|
1240
|
+
class TemplatePreview
|
|
1241
|
+
# @return [String] The template's id
|
|
1242
|
+
attr_reader :template_id
|
|
1243
|
+
|
|
1244
|
+
# @return [String] The template's text, unrendered
|
|
1245
|
+
attr_reader :original_text
|
|
1246
|
+
|
|
1247
|
+
# @return [String] The text with each +{{key}}+ replaced by the value you
|
|
1248
|
+
# sent, else the variable's fallback. A variable with neither stays as
|
|
1249
|
+
# +{{key}}+.
|
|
1250
|
+
attr_reader :rendered_text
|
|
1251
|
+
|
|
1252
|
+
# @return [Integer, nil] The rendered text's length, in UTF-16 code units
|
|
1253
|
+
attr_reader :character_count
|
|
1254
|
+
|
|
1255
|
+
# @return [Integer, nil] How many SMS segments the rendered text needs
|
|
1256
|
+
attr_reader :segment_count
|
|
1257
|
+
|
|
1258
|
+
def initialize(data)
|
|
1259
|
+
@template_id = data["template_id"] || data["templateId"]
|
|
1260
|
+
@original_text = data["original_text"] || data["originalText"]
|
|
1261
|
+
@rendered_text = data["rendered_text"] || data["renderedText"]
|
|
1262
|
+
@character_count = data["character_count"] || data["characterCount"]
|
|
1263
|
+
@segment_count = data["segment_count"] || data["segmentCount"]
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1266
|
+
def to_h
|
|
1267
|
+
{
|
|
1268
|
+
template_id: template_id, original_text: original_text,
|
|
1269
|
+
rendered_text: rendered_text, character_count: character_count,
|
|
1270
|
+
segment_count: segment_count
|
|
1271
|
+
}.compact
|
|
1272
|
+
end
|
|
1273
|
+
end
|
|
1274
|
+
|
|
1124
1275
|
class GeneratedTemplate
|
|
1125
1276
|
attr_reader :name, :text, :variables, :category
|
|
1126
1277
|
|
data/lib/sendly/version.rb
CHANGED