Class: Courier::Resources::Journeys::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/journeys/templates.rb,
sig/courier/resources/journeys/templates.rbs

Overview

Build, version, publish, invoke, and cancel multi-step notification workflows, along with the templates scoped to them.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Templates

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Templates.

Parameters:



356
357
358
# File 'lib/courier/resources/journeys/templates.rb', line 356

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(notification_id, template_id:, request_options: {}) ⇒ nil

Archives one journey's notification template, preventing further sends. Detach any send node referencing it beforehand.

Parameters:

  • notification_id (String) —

    Notification template id

  • template_id (String) —

    Journey id

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/courier/resources/journeys/templates.rb', line 127

def archive(notification_id, params)
  parsed, options = Courier::Journeys::TemplateArchiveParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["journeys/%1$s/templates/%2$s", template_id, notification_id],
    model: NilClass,
    options: options
  )
end

#create(template_id, channel:, notification:, provider_key: nil, state: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::JourneyTemplateGetResponse

Some parameter documentations has been truncated, see Models::Journeys::TemplateCreateParams for more details.

Create a notification template scoped to this journey. Defaults to DRAFT state; pass state: "PUBLISHED" to publish on create.

The content tree must contain exactly one channel block whose channel matches the channel on the request — a journey-scoped template carries a single channel. Top-level elements, or a block for a different channel, return 400. The template designer renders only the channel block matching the tab it draws, so content stored without one cannot be opened. An empty elements array is accepted.

Parameters:

  • template_id (String) —

    Path param: Journey id

  • channel (String) —

    Body param

  • notification (Courier::Models::JourneyTemplateCreateRequest::Notification) —

    Body param

  • provider_key (String) —

    Body param

  • state (String) —

    Body param

  • idempotency_key (String) —

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String) —

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/courier/resources/journeys/templates.rb', line 43

def create(template_id, params)
  parsed, options = Courier::Journeys::TemplateCreateParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: ["journeys/%1$s/templates", template_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::JourneyTemplateGetResponse,
    options: options
  )
end

#list(template_id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::JourneyTemplateListResponse

List notification templates scoped to this journey. Journey-scoped notification templates can only be referenced from send nodes within the same journey.

Parameters:

  • template_id (String) —

    Journey id

  • cursor (String) —

    Pagination cursor from a prior response.

  • limit (Integer) —

    Page size. Minimum 1, maximum 100.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/courier/resources/journeys/templates.rb', line 101

def list(template_id, params = {})
  parsed, options = Courier::Journeys::TemplateListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["journeys/%1$s/templates", template_id],
    query: query,
    model: Courier::JourneyTemplateListResponse,
    options: options
  )
end

#list_versions(notification_id, template_id:, request_options: {}) ⇒ Courier::Models::NotificationTemplateVersionListResponse

Lists the published versions of a template that belongs to a journey, most recent first. Paged by cursor.

Parameters:

  • notification_id (String) —

    Notification template id

  • template_id (String) —

    Journey id

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/courier/resources/journeys/templates.rb', line 155

def list_versions(notification_id, params)
  parsed, options = Courier::Journeys::TemplateListVersionsParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["journeys/%1$s/templates/%2$s/versions", template_id, notification_id],
    model: Courier::NotificationTemplateVersionListResponse,
    options: options
  )
end

#publish(notification_id, template_id:, version: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::Journeys::TemplatePublishParams for more details.

Publishes a journey-scoped template's draft as a new version. Pass a version instead to roll back the template to an earlier publish.

Parameters:

  • notification_id (String) —

    Path param: Notification template id

  • template_id (String) —

    Path param: Journey id

  • version (String) —

    Body param

  • idempotency_key (String) —

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String) —

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/courier/resources/journeys/templates.rb', line 192

def publish(notification_id, params)
  parsed, options = Courier::Journeys::TemplatePublishParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: ["journeys/%1$s/templates/%2$s/publish", template_id, notification_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: NilClass,
    options: options
  )
end

#put_content(notification_id, template_id:, content:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse

Some parameter documentations has been truncated, see Models::Journeys::TemplatePutContentParams for more details.

Replace the elemental content of a journey-scoped notification template. Overwrites all elements in the template draft with the provided content.

Parameters:

Returns:

See Also:



231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/courier/resources/journeys/templates.rb', line 231

def put_content(notification_id, params)
  parsed, options = Courier::Journeys::TemplatePutContentParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["journeys/%1$s/templates/%2$s/content", template_id, notification_id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

#put_locale(locale_id, template_id:, notification_id:, elements:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse

Set locale-specific content overrides for a journey-scoped notification template. Each element override must reference an existing element by ID.

Parameters:

Returns:

See Also:



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'lib/courier/resources/journeys/templates.rb', line 266

def put_locale(locale_id, params)
  parsed, options = Courier::Journeys::TemplatePutLocaleParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  notification_id =
    parsed.delete(:notification_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["journeys/%1$s/templates/%2$s/locales/%3$s", template_id, notification_id, locale_id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

#replace(notification_id, template_id:, notification:, state: nil, request_options: {}) ⇒ Courier::Models::JourneyTemplateGetResponse

Replaces the draft content of one journey's notification template. Publish it before send nodes referencing it render the change.

Parameters:

Returns:

See Also:



303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/courier/resources/journeys/templates.rb', line 303

def replace(notification_id, params)
  parsed, options = Courier::Journeys::TemplateReplaceParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["journeys/%1$s/templates/%2$s", template_id, notification_id],
    body: parsed,
    model: Courier::JourneyTemplateGetResponse,
    options: options
  )
end

#retrieve(notification_id, template_id:, request_options: {}) ⇒ Courier::Models::JourneyTemplateGetResponse

Returns a journey's own notification template with its name, brand, subscription topic, and content. Defaults to the published version.

Parameters:

  • notification_id (String) —

    Notification template id

  • template_id (String) —

    Journey id

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/courier/resources/journeys/templates.rb', line 71

def retrieve(notification_id, params)
  parsed, options = Courier::Journeys::TemplateRetrieveParams.dump_request(params)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["journeys/%1$s/templates/%2$s", template_id, notification_id],
    model: Courier::JourneyTemplateGetResponse,
    options: options
  )
end

#retrieve_content(notification_id, template_id:, version: nil, request_options: {}) ⇒ Courier::Models::NotificationContentGetResponse

Some parameter documentations has been truncated, see Models::Journeys::TemplateRetrieveContentParams for more details.

Returns the Elemental elements and version of a journey-scoped template's content. Compare versions to see what changed between publishes.

Parameters:

  • notification_id (String) —

    Path param: Notification template id

  • template_id (String) —

    Path param: Journey id

  • version (String) —

    Query param: Accepts draft, published, or a version string (e.g., v001). D

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/courier/resources/journeys/templates.rb', line 337

def retrieve_content(notification_id, params)
  parsed, options = Courier::Journeys::TemplateRetrieveContentParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  template_id =
    parsed.delete(:template_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["journeys/%1$s/templates/%2$s/content", template_id, notification_id],
    query: query,
    model: Courier::NotificationContentGetResponse,
    options: options
  )
end