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.
@@ -6,12 +6,20 @@ module Sendly
6
6
  @client = client
7
7
  end
8
8
 
9
- def list(limit: 20, offset: 0, status: nil)
9
+ # List conversations, most recent activity first.
10
+ #
11
+ # @param limit [Integer] Page size (max 100)
12
+ # @param offset [Integer] How many conversations to skip
13
+ # @param status [String, nil] Only conversations with this status, such as "active"
14
+ # @param label [String, nil] Only conversations with this label id
15
+ # @return [ConversationList]
16
+ def list(limit: 20, offset: 0, status: nil, label: nil)
10
17
  params = {
11
18
  limit: [limit, 100].min,
12
19
  offset: offset
13
20
  }
14
21
  params[:status] = status if status
22
+ params[:label] = label if label
15
23
 
16
24
  response = @client.get("/conversations", params.compact)
17
25
  ConversationList.new(response)
@@ -127,12 +135,12 @@ module Sendly
127
135
  SuggestRepliesResponse.new(response)
128
136
  end
129
137
 
130
- def each(status: nil, batch_size: 100, &block)
131
- return enum_for(:each, status: status, batch_size: batch_size) unless block_given?
138
+ def each(status: nil, label: nil, batch_size: 100, &block)
139
+ return enum_for(:each, status: status, label: label, batch_size: batch_size) unless block_given?
132
140
 
133
141
  offset = 0
134
142
  loop do
135
- page = list(limit: batch_size, offset: offset, status: status)
143
+ page = list(limit: batch_size, offset: offset, status: status, label: label)
136
144
  page.each(&block)
137
145
 
138
146
  break if !page.has_more || page.count.zero?
@@ -15,8 +15,39 @@ module Sendly
15
15
  @client.post("/enterprise/workspaces", body)
16
16
  end
17
17
 
18
- def list
19
- @client.get("/enterprise/workspaces")
18
+ # List the workspaces the enterprise key's owner owns, with totals over
19
+ # all of them. Every filter is optional; with none the API returns the
20
+ # first page of 50, newest first.
21
+ #
22
+ # @param limit [Integer, nil] Page size, up to 100 (default 50)
23
+ # @param page [Integer, nil] The page, starting at 1
24
+ # @param search [String, nil] Only workspaces whose name contains this, ignoring case
25
+ # @param status [String, nil] Only workspaces with this status ("all", the default, keeps all)
26
+ # @param verification [String, nil] Only workspaces whose verification has this
27
+ # status; "unverified" keeps those with none ("all", the default, keeps all)
28
+ # @param sort [String, nil] "created_desc" (the default), "created_asc",
29
+ # "name_asc", "name_desc", "credits_desc" or "credits_asc"
30
+ # @param compact [Boolean, nil] +true+ returns every workspace's id, name and
31
+ # balance instead, ignoring the other filters and paging
32
+ # @param tags [Array<String>, String, nil] Tag ids: only workspaces with at
33
+ # least one of them. Sent comma-separated
34
+ # @return [Hash]
35
+ #
36
+ # @example
37
+ # client.enterprise.workspaces.list(search: "acme", sort: "name_asc", limit: 50)
38
+ def list(limit: nil, page: nil, search: nil, status: nil, verification: nil, sort: nil,
39
+ compact: nil, tags: nil)
40
+ params = {}
41
+ params[:limit] = limit unless limit.nil?
42
+ params[:page] = page unless page.nil?
43
+ params[:search] = search unless search.nil?
44
+ params[:status] = status unless status.nil?
45
+ params[:verification] = verification unless verification.nil?
46
+ params[:sort] = sort unless sort.nil?
47
+ params[:compact] = compact unless compact.nil?
48
+ params[:tags] = Array(tags).join(",") unless tags.nil?
49
+
50
+ @client.get("/enterprise/workspaces", params)
20
51
  end
21
52
 
22
53
  def get(workspace_id)
@@ -468,18 +499,38 @@ module Sendly
468
499
  @client.post("/enterprise/business-page/generate", body)
469
500
  end
470
501
 
471
- def upload_verification_document(file_path, workspace_id: nil, verification_id: nil)
502
+ # Upload a business registration document for a toll-free verification.
503
+ #
504
+ # The API accepts a PNG, JPEG, GIF or WEBP image or a PDF, up to 10 MB,
505
+ # and reads the type from the part's content type. It is taken from the
506
+ # file's extension; pass +content_type+ when the file has no extension
507
+ # or a different one, or the upload is refused.
508
+ #
509
+ # @param file_path [String] Path to the document
510
+ # @param workspace_id [String, nil] Make it that workspace's verification document
511
+ # @param verification_id [String, nil] Make it that verification's registration document
512
+ # @param content_type [String, nil] The file's type, such as "image/png" or
513
+ # "application/pdf" (default: from the extension)
514
+ # @return [Hash] The stored document's +url+ and +id+
515
+ #
516
+ # @example
517
+ # client.enterprise.upload_verification_document("/tmp/ein-letter", content_type: "application/pdf")
518
+ def upload_verification_document(file_path, workspace_id: nil, verification_id: nil, content_type: nil)
472
519
  raise ArgumentError, "File path is required" if file_path.nil? || file_path.empty?
473
520
  raise ArgumentError, "File not found: #{file_path}" unless File.exist?(file_path)
521
+ if !content_type.nil? && (content_type.to_s.strip.empty? || content_type.to_s.match?(/[\r\n]/))
522
+ raise ArgumentError, "content_type must be a MIME type such as \"application/pdf\""
523
+ end
474
524
 
475
- content_type = case File.extname(file_path).downcase
476
- when ".jpg", ".jpeg" then "image/jpeg"
477
- when ".png" then "image/png"
478
- when ".gif" then "image/gif"
479
- when ".pdf" then "application/pdf"
480
- when ".webp" then "image/webp"
481
- else "application/octet-stream"
482
- end
525
+ content_type = content_type.nil? ? nil : content_type.to_s.strip
526
+ content_type ||= case File.extname(file_path).downcase
527
+ when ".jpg", ".jpeg" then "image/jpeg"
528
+ when ".png" then "image/png"
529
+ when ".gif" then "image/gif"
530
+ when ".pdf" then "application/pdf"
531
+ when ".webp" then "image/webp"
532
+ else "application/octet-stream"
533
+ end
483
534
 
484
535
  filename = File.basename(file_path).gsub('"', "%22").gsub("\r", "%0D").gsub("\n", "%0A")
485
536
 
@@ -392,6 +392,10 @@ module Sendly
392
392
  # @param to [String] Recipient phone number in E.164 format
393
393
  # @param text [String] Message content (max 1600 characters)
394
394
  # @param scheduled_at [String] ISO 8601 datetime for when to send
395
+ # @param timezone [String] A time zone label such as "America/New_York"
396
+ # (optional). It is stored with the message and returned as sent; it
397
+ # does not change how +scheduled_at+ is read, so give +scheduled_at+ an
398
+ # offset or +Z+. The API stores "UTC" when it is left out.
395
399
  # @param from [String] Sender ID or phone number (optional)
396
400
  # @param message_type [String] Message type: "marketing" (default) or "transactional"
397
401
  # @param metadata [Hash] Custom JSON metadata to attach to the message (max 4KB)
@@ -408,12 +412,14 @@ module Sendly
408
412
  # scheduled_at: "2025-01-20T10:00:00Z"
409
413
  # )
410
414
  # puts scheduled["id"]
411
- def schedule(to:, text:, scheduled_at:, from: nil, message_type: nil, metadata: nil, idempotency_key: nil)
415
+ def schedule(to:, text:, scheduled_at:, timezone: nil, from: nil, message_type: nil, metadata: nil,
416
+ idempotency_key: nil)
412
417
  validate_phone!(to)
413
418
  validate_text!(text)
414
419
  raise ValidationError, "scheduled_at is required" if scheduled_at.nil? || scheduled_at.empty?
415
420
 
416
421
  body = { to: to, text: text, scheduledAt: scheduled_at }
422
+ body[:timezone] = timezone if timezone
417
423
  body[:from] = from if from
418
424
  body[:messageType] = message_type if message_type
419
425
  body[:metadata] = metadata if metadata
@@ -19,7 +19,7 @@ module Sendly
19
19
  Rule.new(response)
20
20
  end
21
21
 
22
- def update(id, name: nil, conditions: nil, actions: nil, priority: nil)
22
+ def update(id, name: nil, conditions: nil, actions: nil, priority: nil, enabled: nil)
23
23
  raise ValidationError, "Rule ID is required" if id.nil? || id.empty?
24
24
 
25
25
  body = {}
@@ -27,6 +27,7 @@ module Sendly
27
27
  body[:conditions] = conditions if conditions
28
28
  body[:actions] = actions if actions
29
29
  body[:priority] = priority if priority
30
+ body[:enabled] = enabled unless enabled.nil?
30
31
 
31
32
  response = @client.patch("/rules/#{URI.encode_www_form_component(id)}", body)
32
33
  Rule.new(response)
@@ -0,0 +1,336 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sendly
4
+ # A compliance problem with a short code application. +path+ is the field
5
+ # it is about, such as "helpResponse" or "documents.loa"; +message+ says
6
+ # what to change.
7
+ class ShortCodeIssue
8
+ attr_reader :path, :message
9
+
10
+ def initialize(data)
11
+ data ||= {}
12
+ @path = data["path"]
13
+ @message = data["message"]
14
+ end
15
+
16
+ def to_h
17
+ { path: path, message: message }.compact
18
+ end
19
+ end
20
+
21
+ # A carrier form the application needs, and where it stands.
22
+ class ShortCodeDocument
23
+ attr_reader :kind, :template_ready, :signed_at, :signed_by_name, :awaiting_signature
24
+
25
+ def initialize(data)
26
+ data ||= {}
27
+ @kind = data["kind"]
28
+ @template_ready = data["templateReady"]
29
+ @signed_at = data["signedAt"]
30
+ @signed_by_name = data["signedByName"]
31
+ @awaiting_signature = data["awaitingSignature"]
32
+ end
33
+
34
+ def to_h
35
+ {
36
+ kind: kind, template_ready: template_ready, signed_at: signed_at,
37
+ signed_by_name: signed_by_name, awaiting_signature: awaiting_signature
38
+ }.compact
39
+ end
40
+ end
41
+
42
+ # The workspace's short code application. With no application yet it is
43
+ # the empty shape: +id+ is nil, the choices show their defaults and every
44
+ # answer is nil. +status+ is where the code stands (see {STATUSES}) and
45
+ # +review_status+ where Sendly's review stands (see {REVIEW_STATUSES});
46
+ # a value this SDK predates comes through unchanged.
47
+ class ShortCodeApplication
48
+ STATUSES = %w[requested provisioning parked active suspended cancelled].freeze
49
+ REVIEW_STATUSES = %w[draft awaiting_review changes_requested approved_for_filing filed rejected].freeze
50
+
51
+ FIELDS = {
52
+ id: "id", short_code: "shortCode", country_code: "countryCode", status: "status",
53
+ review_status: "reviewStatus", review_note: "reviewNote", order_type: "orderType",
54
+ code_type: "codeType", content_provider_same_as_brand: "contentProviderSameAsBrand",
55
+ sample_messages: "sampleMessages", use_case: "useCase", opt_in_flow: "optInFlow",
56
+ opt_in_confirmation: "optInConfirmation", help_response: "helpResponse",
57
+ stop_confirmation: "stopConfirmation", message_frequency: "messageFrequency",
58
+ campaign_keyword: "campaignKeyword", expected_monthly_volume: "expectedMonthlyVolume",
59
+ expected_daily_volume: "expectedDailyVolume", privacy_policy_url: "privacyPolicyUrl",
60
+ terms_url: "termsUrl", requested_digits: "requestedDigits", losing_provider: "losingProvider",
61
+ brand_contact_name: "brandContactName", brand_contact_email: "brandContactEmail",
62
+ brand_contact_phone: "brandContactPhone", content_provider_legal_name: "contentProviderLegalName",
63
+ content_provider_ein: "contentProviderEin", content_provider_contact_name: "contentProviderContactName",
64
+ content_provider_contact_email: "contentProviderContactEmail",
65
+ content_provider_contact_phone: "contentProviderContactPhone",
66
+ brand_registration_status: "brandRegistrationStatus",
67
+ content_provider_registration_status: "contentProviderRegistrationStatus",
68
+ submitted_at: "submittedAt", reviewed_at: "reviewedAt", filed_at: "filedAt",
69
+ activated_at: "activatedAt", registry_revetting_due_at: "registryRevettingDueAt",
70
+ created_at: "createdAt", updated_at: "updatedAt"
71
+ }.freeze
72
+
73
+ attr_reader(*FIELDS.keys)
74
+
75
+ def initialize(data)
76
+ data ||= {}
77
+ FIELDS.each { |attr, key| instance_variable_set("@#{attr}", data[key]) }
78
+ @sample_messages ||= []
79
+ end
80
+
81
+ def active?
82
+ status == "active"
83
+ end
84
+
85
+ def to_h
86
+ FIELDS.keys.to_h { |attr| [attr, public_send(attr)] }.compact
87
+ end
88
+ end
89
+
90
+ # The application plus everything needed to act on it. +prefill+,
91
+ # +generated_defaults+, +quote+, +billing+, +verification+, +carriers+
92
+ # and +payment+ are Hashes with snake_case Symbol keys (for example
93
+ # +quote[:setup_usd]+, +billing[:setup_fee][:status]+ and
94
+ # +carriers[:by_carrier]+). +ignored_fields+ is set on a save or a
95
+ # check; +submitted+, +already_submitted+, +notified+ and +payment+ on a
96
+ # submit (+payment+ is nil when the application was already in review).
97
+ class ShortCodeApplicationView
98
+ attr_reader :enabled, :application, :prefill, :editable, :lock_message,
99
+ :can_start_new_application, :generated_defaults,
100
+ :required_documents, :missing_documents, :documents, :quote,
101
+ :billing, :verification, :carriers, :ignored_fields,
102
+ :submitted, :already_submitted, :notified, :payment
103
+
104
+ def initialize(data)
105
+ data ||= {}
106
+ @enabled = data["enabled"]
107
+ @application = ShortCodeApplication.new(data["application"])
108
+ @prefill = RcsRegistrationInput.underscore(data["prefill"] || {})
109
+ @editable = data["editable"]
110
+ @lock_message = data["lockMessage"]
111
+ @can_start_new_application = data["canStartNewApplication"]
112
+ @generated_defaults = data["generatedDefaults"] && RcsRegistrationInput.underscore(data["generatedDefaults"])
113
+ @required_documents = data["requiredDocuments"] || []
114
+ @missing_documents = data["missingDocuments"] || []
115
+ @documents = (data["documents"] || []).map { |d| ShortCodeDocument.new(d) }
116
+ @quote = RcsRegistrationInput.underscore(data["quote"] || {})
117
+ @billing = RcsRegistrationInput.underscore(data["billing"] || {})
118
+ @verification = RcsRegistrationInput.underscore(data["verification"] || {})
119
+ @carriers = RcsRegistrationInput.underscore(data["carriers"] || {})
120
+ @ignored_fields = data["ignoredFields"]
121
+ @submitted = data["submitted"]
122
+ @already_submitted = data["alreadySubmitted"]
123
+ @notified = data["notified"]
124
+ @payment = data["payment"] && RcsRegistrationInput.underscore(data["payment"])
125
+ end
126
+
127
+ def editable?
128
+ editable == true
129
+ end
130
+
131
+ def already_submitted?
132
+ already_submitted == true
133
+ end
134
+
135
+ def to_h
136
+ {
137
+ enabled: enabled, application: application.to_h, prefill: prefill,
138
+ editable: editable, lock_message: lock_message,
139
+ can_start_new_application: can_start_new_application,
140
+ generated_defaults: generated_defaults,
141
+ required_documents: required_documents, missing_documents: missing_documents,
142
+ documents: documents.map(&:to_h), quote: quote, billing: billing,
143
+ verification: verification, carriers: carriers, ignored_fields: ignored_fields,
144
+ submitted: submitted, already_submitted: already_submitted,
145
+ notified: notified, payment: payment
146
+ }.compact
147
+ end
148
+ end
149
+
150
+ # A dry run of submitting the application. Nothing is saved. +ok+ is
151
+ # false when there is any issue; +issues+ lists every one at once.
152
+ class ShortCodePreflight
153
+ attr_reader :ok, :issues, :required_documents, :missing_documents, :documents, :ignored_fields
154
+
155
+ def initialize(data)
156
+ data ||= {}
157
+ @ok = data["ok"]
158
+ @issues = (data["issues"] || []).map { |i| ShortCodeIssue.new(i) }
159
+ @required_documents = data["requiredDocuments"] || []
160
+ @missing_documents = data["missingDocuments"] || []
161
+ @documents = (data["documents"] || []).map { |d| ShortCodeDocument.new(d) }
162
+ @ignored_fields = data["ignoredFields"]
163
+ end
164
+
165
+ def ok?
166
+ ok == true
167
+ end
168
+
169
+ def to_h
170
+ {
171
+ ok: ok, issues: issues.map(&:to_h), required_documents: required_documents,
172
+ missing_documents: missing_documents, documents: documents.map(&:to_h),
173
+ ignored_fields: ignored_fields
174
+ }.compact
175
+ end
176
+ end
177
+
178
+ # One of the workspace's short code applications, with its code once
179
+ # Sendly assigns one. +short_code+ is nil until then, and drafts,
180
+ # rejected and cancelled applications are listed too. +billing+ is a Hash
181
+ # with snake_case Symbol keys (+billing[:setup_fee][:status]+,
182
+ # +billing[:lease][:state]+).
183
+ class ShortCode
184
+ attr_reader :id, :short_code, :country_code, :status, :review_status, :use_case, :created_at, :billing
185
+
186
+ def initialize(data)
187
+ data ||= {}
188
+ @id = data["id"]
189
+ @short_code = data["shortCode"]
190
+ @country_code = data["countryCode"]
191
+ @status = data["status"]
192
+ @review_status = data["reviewStatus"]
193
+ @use_case = data["useCase"]
194
+ @created_at = data["createdAt"]
195
+ @billing = RcsRegistrationInput.underscore(data["billing"] || {})
196
+ end
197
+
198
+ def active?
199
+ status == "active"
200
+ end
201
+
202
+ def to_h
203
+ {
204
+ id: id, short_code: short_code, country_code: country_code, status: status,
205
+ review_status: review_status, use_case: use_case, created_at: created_at,
206
+ billing: billing
207
+ }.compact
208
+ end
209
+ end
210
+
211
+ # The workspace's short code application: read it, save answers, check
212
+ # it against the carrier rules and submit it. Answers are passed as
213
+ # keywords in snake_case or camelCase (+use_case:+ or +useCase:+), the
214
+ # same fields the API takes, such as +use_case+, +opt_in_flow+,
215
+ # +sample_messages+, +order_type+, +code_type+ and +brand_contact_email+.
216
+ class ShortCodeApplicationResource
217
+ def initialize(client)
218
+ @client = client
219
+ end
220
+
221
+ # Fetch the application, with the documents it needs, the quote, and
222
+ # +billing+: where the setup fee and the monthly lease stand. Requires
223
+ # the +short_codes:read+ scope.
224
+ #
225
+ # @return [ShortCodeApplicationView]
226
+ # @raise [Sendly::NotFoundError] +short_codes_not_enabled+ (404) when
227
+ # short codes aren't enabled for the account
228
+ #
229
+ # @example
230
+ # view = client.short_codes.application.get
231
+ # puts view.lock_message unless view.editable?
232
+ def get
233
+ ShortCodeApplicationView.new(@client.get("/short_codes/application"))
234
+ end
235
+
236
+ # Save answers on the application, creating it on the first call.
237
+ # Fields Sendly or the carriers own (the digits, the status, the review
238
+ # state) are ignored and named back in +ignored_fields+. Requires the
239
+ # +short_codes:write+ scope.
240
+ #
241
+ # @param idempotency_key [String, nil] Idempotency key for this operation
242
+ # (1-255 printable ASCII characters), so a repeat of the same save
243
+ # returns the first answer
244
+ # @param application [Hash] The answers to save
245
+ # @return [ShortCodeApplicationView]
246
+ # @raise [Sendly::APIError] 409 +short_code_locked+ once the application
247
+ # is with Sendly or the carriers
248
+ #
249
+ # @example
250
+ # client.short_codes.application.update(
251
+ # use_case: "Delivery alerts for Acme orders",
252
+ # message_frequency: "4 messages per month"
253
+ # )
254
+ def update(idempotency_key: nil, **application)
255
+ response = @client.put("/short_codes/application", RcsRegistrationInput.camelize(application),
256
+ idempotency_key: idempotency_key)
257
+ ShortCodeApplicationView.new(response)
258
+ end
259
+
260
+ # Check the application against the carrier rules without changing
261
+ # anything. Unsaved answers can be passed and are checked on top of
262
+ # what is saved. Requires the +short_codes:read+ scope.
263
+ #
264
+ # @param application [Hash] Optional unsaved answers to check as well
265
+ # @return [ShortCodePreflight]
266
+ #
267
+ # @example
268
+ # check = client.short_codes.application.check
269
+ # check.issues.each { |issue| puts "#{issue.path}: #{issue.message}" }
270
+ def check(**application)
271
+ response = @client.post("/short_codes/application/preflight", RcsRegistrationInput.camelize(application))
272
+ ShortCodePreflight.new(response)
273
+ end
274
+
275
+ # Submit the application to Sendly for review. Submitting charges the
276
+ # one-time $999 setup fee to the workspace's card on file, so pass
277
+ # +accept_terms: true+ to accept it, the monthly lease from go-live and
278
+ # the 3-month minimum. The fee is refunded in full if Sendly rejects
279
+ # the application before filing it. Submitting twice is safe: the
280
+ # second call reports +already_submitted+ and charges nothing. Requires
281
+ # the +short_codes:write+ scope.
282
+ #
283
+ # @param idempotency_key [String, nil] Idempotency key for this operation
284
+ # (1-255 printable ASCII characters), so a repeat of the same submit
285
+ # returns the first answer
286
+ # @param application [Hash] +accept_terms+, plus optional final answers
287
+ # saved before the check
288
+ # @return [ShortCodeApplicationView] With +submitted+, +already_submitted+,
289
+ # +notified+ and +payment+ (whether this call charged the fee)
290
+ # @raise [Sendly::APIError] 403 +verification_required+ until
291
+ # the workspace's business is verified; the answers sent are saved anyway
292
+ # @raise [Sendly::ValidationError] 422 +short_code_invalid_application+
293
+ # (with an +errors+ array naming every field, +acceptTerms+ included) or
294
+ # +short_code_ai_draft_unedited+
295
+ # @raise [Sendly::InsufficientCreditsError] 402 +payment_method_required+,
296
+ # +payment_failed+ or +payment_requires_authentication+ when the fee
297
+ # can't be charged; the application stays a draft
298
+ #
299
+ # @example
300
+ # result = client.short_codes.application.submit(accept_terms: true)
301
+ # puts result.application.review_status # "awaiting_review"
302
+ # puts result.billing[:setup_fee][:status] # "paid"
303
+ def submit(idempotency_key: nil, **application)
304
+ response = @client.post("/short_codes/application/submit", RcsRegistrationInput.camelize(application),
305
+ idempotency_key: idempotency_key)
306
+ ShortCodeApplicationView.new(response)
307
+ end
308
+ end
309
+
310
+ # Short codes: 5 or 6 digit US senders. Getting one is an application,
311
+ # not a purchase: you fill it in, Sendly reviews it, the carrier forms are
312
+ # signed, Sendly files it, and each carrier certifies the code.
313
+ class ShortCodesResource
314
+ # @return [ShortCodeApplicationResource] The workspace's application
315
+ attr_reader :application
316
+
317
+ def initialize(client)
318
+ @client = client
319
+ @application = ShortCodeApplicationResource.new(client)
320
+ end
321
+
322
+ # List every short code application of the workspace, newest first,
323
+ # with its code once Sendly assigns one. Drafts, rejected and cancelled
324
+ # applications are listed too, so filter on +status+ for the codes you
325
+ # can send from. Requires the +short_codes:read+ scope.
326
+ #
327
+ # @return [Array<ShortCode>]
328
+ #
329
+ # @example
330
+ # sendable = client.short_codes.list.select(&:active?)
331
+ def list
332
+ response = @client.get("/short_codes")
333
+ (response["shortCodes"] || []).map { |code| ShortCode.new(code) }
334
+ end
335
+ end
336
+ end
@@ -229,6 +229,27 @@ module Sendly
229
229
  Template.new(response)
230
230
  end
231
231
 
232
+ # Render one of the workspace's templates, or any preset, with the values
233
+ # you give. Nothing is sent or saved.
234
+ #
235
+ # @param id [String] Template ID
236
+ # @param variables [Hash, nil] Values by variable key:
237
+ # +{ "code" => "123456" }+ fills +{{code}}+. Without it, each variable
238
+ # renders with its fallback.
239
+ # @return [Sendly::TemplatePreview]
240
+ # @raise [Sendly::NotFoundError] if no preset and no template of the key's
241
+ # workspace has this id
242
+ #
243
+ # @example
244
+ # preview = client.templates.preview("tpl_preset_otp", variables: { code: "123456" })
245
+ # puts preview.rendered_text
246
+ def preview(id, variables: nil)
247
+ body = {}
248
+ body[:variables] = variables if variables
249
+ response = @client.post("/templates/#{URI.encode_www_form_component(id)}/preview", body)
250
+ TemplatePreview.new(response)
251
+ end
252
+
232
253
  def generate(description:, category: nil)
233
254
  body = { description: description }
234
255
  body[:category] = category if category