Class: Courier::Resources::Messages

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

Overview

Look up the messages Courier has accepted, inspect their delivery history and rendered output, and cancel, resend, or archive them.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Messages

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

Parameters:



183
184
185
# File 'lib/courier/resources/messages.rb', line 183

def initialize(client:)
  @client = client
end

Instance Method Details

#cancel(message_id, request_options: {}) ⇒ Courier::Models::MessageDetails

Cancels a message that is still in the delivery pipeline and returns the message record with its resulting canceled or failed status.

Parameters:

  • message_id (String)

    A unique identifier representing the message ID

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

Returns:

See Also:



97
98
99
100
101
102
103
104
# File 'lib/courier/resources/messages.rb', line 97

def cancel(message_id, params = {})
  @client.request(
    method: :post,
    path: ["messages/%1$s/cancel", message_id],
    model: Courier::MessageDetails,
    options: params[:request_options]
  )
end

#content(message_id, request_options: {}) ⇒ Courier::Models::MessageContentResponse

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

Returns the rendered content Courier delivered for a message, broken out per channel, to confirm what the recipient received.

Parameters:

  • message_id (String)

    A unique identifier associated with the message you wish to retrieve (results fr

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

Returns:

See Also:



121
122
123
124
125
126
127
128
# File 'lib/courier/resources/messages.rb', line 121

def content(message_id, params = {})
  @client.request(
    method: :get,
    path: ["messages/%1$s/output", message_id],
    model: Courier::Models::MessageContentResponse,
    options: params[:request_options]
  )
end

#history(message_id, type: nil, request_options: {}) ⇒ Courier::Models::MessageHistoryResponse

Returns the ordered event history for a sent message, one entry per status transition with its timestamp.

Parameters:

  • message_id (String)

    A unique identifier representing the message ID

  • type (String, nil)

    A supported Message History type that will filter the events returned.

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

Returns:

See Also:



144
145
146
147
148
149
150
151
152
153
154
# File 'lib/courier/resources/messages.rb', line 144

def history(message_id, params = {})
  parsed, options = Courier::MessageHistoryParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: ["messages/%1$s/history", message_id],
    query: query,
    model: Courier::Models::MessageHistoryResponse,
    options: options
  )
end

#list(archived: nil, cursor: nil, enqueued_after: nil, event: nil, list: nil, message_id: nil, notification: nil, provider: nil, recipient: nil, status: nil, tag: nil, tags: nil, tenant_id: nil, trace_id: nil, request_options: {}) ⇒ Courier::Models::MessageListResponse

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

Returns previously sent messages, most recent first, each carrying its status, recipient, channel, and provider. Paged by cursor.

Parameters:

  • archived (Boolean, nil)

    A boolean value that indicates whether archived messages should be included in t

  • cursor (String, nil)

    A unique identifier that allows for fetching the next set of messages.

  • enqueued_after (String, nil)

    The enqueued datetime of a message to filter out messages received before.

  • event (String, nil)

    A unique identifier representing the event that was used to send the event.

  • list (String, nil)

    A unique identifier representing the list the message was sent to.

  • message_id (String, nil)

    A unique identifier representing the message_id returned from either /send or /s

  • notification (String, nil)

    A unique identifier representing the notification that was used to send the even

  • provider (Array<String, nil>)

    The key assocated to the provider you want to filter on. E.g., sendgrid, inbox,

  • recipient (String, nil)

    A unique identifier representing the recipient associated with the requested pro

  • status (Array<String, nil>)

    An indicator of the current status of the message. Allows multiple values to be

  • tag (Array<String, nil>)

    A tag placed in the metadata.tags during a notification send. Allows multiple va

  • tags (String, nil)

    A comma delimited list of 'tags'. Messages will be returned if they match any of

  • tenant_id (String, nil)

    Messages sent with the context of a Tenant

  • trace_id (String, nil)

    The unique identifier used to trace the requests

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

Returns:

See Also:



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

def list(params = {})
  parsed, options = Courier::MessageListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "messages",
    query: query.transform_keys(message_id: "messageId", trace_id: "traceId"),
    model: Courier::Models::MessageListResponse,
    options: options
  )
end

#resend(message_id, request_options: {}) ⇒ Courier::Models::MessageResendResponse

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

Resends a previously sent message to the same recipient and content, returning a new messageId. The original send request is not modified.

Parameters:

  • message_id (String)

    A unique identifier representing the message ID of the original message to resen

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

Returns:

See Also:



171
172
173
174
175
176
177
178
# File 'lib/courier/resources/messages.rb', line 171

def resend(message_id, params = {})
  @client.request(
    method: :post,
    path: ["messages/%1$s/resend", message_id],
    model: Courier::Models::MessageResendResponse,
    options: params[:request_options]
  )
end

#retrieve(message_id, request_options: {}) ⇒ Courier::Models::MessageRetrieveResponse

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

Returns a sent message's status, recipient, event, and per-provider delivery detail, with timestamps for enqueued, sent, delivered, opened, and clicked.

Parameters:

  • message_id (String)

    A unique identifier associated with the message you wish to retrieve (results fr

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

Returns:

See Also:



23
24
25
26
27
28
29
30
# File 'lib/courier/resources/messages.rb', line 23

def retrieve(message_id, params = {})
  @client.request(
    method: :get,
    path: ["messages/%1$s", message_id],
    model: Courier::Models::MessageRetrieveResponse,
    options: params[:request_options]
  )
end