Class: Courier::Resources::Notifications

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

Defined Under Namespace

Classes: Checks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Notifications

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 Notifications.

Parameters:



358
359
360
361
# File 'lib/courier/resources/notifications.rb', line 358

def initialize(client:)
  @client = client
  @checks = Courier::Resources::Notifications::Checks.new(client: client)
end

Instance Attribute Details

#checksCourier::Resources::Notifications::Checks (readonly)



7
8
9
# File 'lib/courier/resources/notifications.rb', line 7

def checks
  @checks
end

Instance Method Details

#archive(id, request_options: {}) ⇒ nil

Archive a notification template.

Parameters:

  • id (String)

    Template ID (nt_ prefix).

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

Returns:

  • (nil)

See Also:



104
105
106
107
108
109
110
111
# File 'lib/courier/resources/notifications.rb', line 104

def archive(id, params = {})
  @client.request(
    method: :delete,
    path: ["notifications/%1$s", id],
    model: NilClass,
    options: params[:request_options]
  )
end

#create(notification:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse

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

Create a notification template. Requires all fields in the notification object. Templates are created in draft state by default.

Parameters:

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
# File 'lib/courier/resources/notifications.rb', line 26

def create(params)
  parsed, options = Courier::NotificationCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "notifications",
    body: parsed,
    model: Courier::NotificationTemplateResponse,
    options: options
  )
end

#duplicate(id, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse

Duplicate a notification template. Creates a standalone copy within the same workspace and environment, with " COPY" appended to the title. The copy clones the source draft's tags, brand, subscription topic, routing strategy, channels, and content, and is always created as a standalone template (it is not linked to any journey or broadcast, even if the source was). Templates that are scoped to a journey or a broadcast cannot be duplicated through this endpoint.

Parameters:

Returns:

See Also:



129
130
131
132
133
134
135
136
# File 'lib/courier/resources/notifications.rb', line 129

def duplicate(id, params = {})
  @client.request(
    method: :post,
    path: ["notifications/%1$s/duplicate", id],
    model: Courier::NotificationTemplateResponse,
    options: params[:request_options]
  )
end

#list(cursor: nil, event_id: nil, notes: nil, request_options: {}) ⇒ Courier::Models::NotificationListResponse

List notification templates in your workspace.

Parameters:

  • cursor (String, nil)

    Opaque pagination cursor from a previous response. Omit for the first page.

  • event_id (String)

    Filter to templates linked to this event map ID.

  • notes (Boolean, nil)

    Include template notes in the response. Only applies to legacy templates.

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

Returns:

See Also:



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/courier/resources/notifications.rb', line 81

def list(params = {})
  parsed, options = Courier::NotificationListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "notifications",
    query: query,
    model: Courier::Models::NotificationListResponse,
    options: options
  )
end

#list_versions(id, cursor: nil, limit: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateVersionListResponse

List versions of a notification template.

Parameters:

  • id (String)

    Template ID (nt_ prefix).

  • cursor (String)

    Opaque pagination cursor from a previous response. Omit for the first page.

  • limit (Integer)

    Maximum number of versions to return per page. Default 10, max 10.

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

Returns:

See Also:



153
154
155
156
157
158
159
160
161
162
163
# File 'lib/courier/resources/notifications.rb', line 153

def list_versions(id, params = {})
  parsed, options = Courier::NotificationListVersionsParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["notifications/%1$s/versions", id],
    query: query,
    model: Courier::NotificationTemplateVersionListResponse,
    options: options
  )
end

#publish(id, version: nil, request_options: {}) ⇒ nil

Publish a notification template. Publishes the current draft by default. Pass a version in the request body to publish a specific historical version.

Parameters:

  • id (String)

    Template ID (nt_ prefix).

  • version (String)

    Historical version to publish (e.g. "v001"). Omit to publish the current draft.

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

Returns:

  • (nil)

See Also:



179
180
181
182
183
184
185
186
187
188
# File 'lib/courier/resources/notifications.rb', line 179

def publish(id, params = {})
  parsed, options = Courier::NotificationPublishParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["notifications/%1$s/publish", id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

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

Replace the elemental content of a notification template. Overwrites all elements in the template with the provided content. Only supported for V2 (elemental) templates.

Parameters:

Returns:

See Also:



207
208
209
210
211
212
213
214
215
216
# File 'lib/courier/resources/notifications.rb', line 207

def put_content(id, params)
  parsed, options = Courier::NotificationPutContentParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["notifications/%1$s/content", id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

#put_element(element_id, id:, type:, channels: nil, data: nil, if_: nil, loop_: nil, ref: nil, state: nil, request_options: {}) ⇒ Courier::Models::NotificationContentMutationResponse

Update a single element within a notification template. Only supported for V2 (elemental) templates.

Parameters:

  • element_id (String)

    Path param: Element ID within the template.

  • id (String)

    Path param: Notification template ID (nt_ prefix).

  • type (String)

    Body param: Element type (text, meta, action, image, etc.).

  • channels (Array<String>)

    Body param

  • data (Hash{Symbol=>Object})

    Body param

  • if_ (String)

    Body param

  • loop_ (String)

    Body param

  • ref (String)

    Body param

  • state (Symbol, Courier::Models::NotificationTemplateState)

    Body param: Template state. Defaults to DRAFT.

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

Returns:

See Also:



246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/courier/resources/notifications.rb', line 246

def put_element(element_id, params)
  parsed, options = Courier::NotificationPutElementParams.dump_request(params)
  id =
    parsed.delete(:id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["notifications/%1$s/elements/%2$s", id, element_id],
    body: parsed,
    model: Courier::NotificationContentMutationResponse,
    options: options
  )
end

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

Set locale-specific content overrides for a notification template. Each element override must reference an existing element by ID. Only supported for V2 (elemental) templates.

Parameters:

Returns:

See Also:



280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/courier/resources/notifications.rb', line 280

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

#replace(id, notification:, state: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse

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

Replace a notification template. All fields are required.

Parameters:

Returns:

See Also:



313
314
315
316
317
318
319
320
321
322
# File 'lib/courier/resources/notifications.rb', line 313

def replace(id, params)
  parsed, options = Courier::NotificationReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["notifications/%1$s", id],
    body: parsed,
    model: Courier::NotificationTemplateResponse,
    options: options
  )
end

#retrieve(id, version: nil, request_options: {}) ⇒ Courier::Models::NotificationTemplateResponse

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

Retrieve a notification template by ID. Returns the published version by default. Pass version=draft to retrieve an unpublished template.

Parameters:

  • id (String)

    Template ID (nt_ prefix).

  • version (String)

    Version to retrieve. One of "draft", "published", or a version string like "v001

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

Returns:

See Also:



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/courier/resources/notifications.rb', line 54

def retrieve(id, params = {})
  parsed, options = Courier::NotificationRetrieveParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["notifications/%1$s", id],
    query: query,
    model: Courier::NotificationTemplateResponse,
    options: options
  )
end

#retrieve_content(id, version: nil, request_options: {}) ⇒ Courier::Models::NotificationContentGetResponse, Courier::Models::NotificationGetContent

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

Retrieve the content of a notification template. The response shape depends on whether the template uses V1 (blocks/channels) or V2 (elemental) content. Use the version query parameter to select draft, published, or a specific historical version.

Parameters:

  • id (String)

    Notification template ID (nt_ prefix).

  • version (String)

    Accepts draft, published, or a version string (e.g., v001). Defaults to `p

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

Returns:

See Also:



343
344
345
346
347
348
349
350
351
352
353
# File 'lib/courier/resources/notifications.rb', line 343

def retrieve_content(id, params = {})
  parsed, options = Courier::NotificationRetrieveContentParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["notifications/%1$s/content", id],
    query: query,
    model: Courier::Models::NotificationRetrieveContentResponse,
    options: options
  )
end