Class: Sentdm::Resources::Messages

Inherits:
Object
  • Object
show all
Defined in:
lib/sentdm/resources/messages.rb

Overview

Send and track SMS and WhatsApp messages

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:



91
92
93
# File 'lib/sentdm/resources/messages.rb', line 91

def initialize(client:)
  @client = client
end

Instance Method Details

#retrieve_activities(id, request_options: {}) ⇒ Sentdm::Models::MessageRetrieveActivitiesResponse

Retrieves the activity log for a specific message. Activities track the message lifecycle including acceptance, processing, sending, delivery, and any errors.

Parameters:

  • id (String)

    Message ID from route parameter

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

Returns:

See Also:



19
20
21
22
23
24
25
26
# File 'lib/sentdm/resources/messages.rb', line 19

def retrieve_activities(id, params = {})
  @client.request(
    method: :get,
    path: ["v3/messages/%1$s/activities", id],
    model: Sentdm::Models::MessageRetrieveActivitiesResponse,
    options: params[:request_options]
  )
end

#retrieve_status(id, request_options: {}) ⇒ Sentdm::Models::MessageRetrieveStatusResponse

Retrieves the current status and details of a message by ID. Includes delivery status, timestamps, and error information if applicable.

Parameters:

Returns:

See Also:



40
41
42
43
44
45
46
47
# File 'lib/sentdm/resources/messages.rb', line 40

def retrieve_status(id, params = {})
  @client.request(
    method: :get,
    path: ["v3/messages/%1$s", id],
    model: Sentdm::Models::MessageRetrieveStatusResponse,
    options: params[:request_options]
  )
end

#send_(channel: nil, template: nil, test_mode: nil, to: nil, idempotency_key: nil, request_options: {}) ⇒ Sentdm::Models::MessageSendResponse

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

Sends a message to one or more recipients using a template. Supports multi-channel broadcast — when multiple channels are specified (e.g. [“sms”, “whatsapp”]), a separate message is created for each (recipient, channel) pair. Returns immediately with per-recipient message IDs for async tracking via webhooks or the GET /messages/id endpoint.

Parameters:

  • channel (Array<String>, nil)

    Body param: Channels to broadcast on, e.g. [“whatsapp”, “sms”].

  • template (Sentdm::Models::MessageSendParams::Template)

    Body param: Template reference (by id or name, with optional parameters)

  • test_mode (Boolean)

    Body param: Test mode flag - when true, the operation is simulated without side

  • to (Array<String>)

    Body param: List of recipient phone numbers in E.164 format (multi-recipient fan

  • idempotency_key (String)

    Header param: Unique key to ensure idempotent request processing. Must be 1-255

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

Returns:

See Also:



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sentdm/resources/messages.rb', line 75

def send_(params = {})
  parsed, options = Sentdm::MessageSendParams.dump_request(params)
  header_params = {idempotency_key: "idempotency-key"}
  @client.request(
    method: :post,
    path: "v3/messages",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Sentdm::Models::MessageSendResponse,
    options: options
  )
end