Class: Pinnacle::SendClient

Inherits:
Object
  • Object
show all
Defined in:
lib/rcs/send/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ Pinnacle::SendClient

Parameters:



19
20
21
# File 'lib/rcs/send/client.rb', line 19

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientPinnacle::RequestClient (readonly)



15
16
17
# File 'lib/rcs/send/client.rb', line 15

def request_client
  @request_client
end

Instance Method Details

#mms(to:, from:, media_urls:, text: nil, status_callback: nil, request_options: nil) ⇒ Pinnacle::Send::SendMmsResponse

Send an MMS message with media attachments.

Examples:

api = Pinnacle::Client.new(
  base_url: "https://api.example.com",
  environment: Pinnacle::Environment::DEFAULT,
  api_key: "YOUR_API_KEY"
)
api.send.mms(
  to: "to",
  from: "from",
  media_urls: ["https://example.com/image1.jpg", "https://example.com/video.mp4"]
)

Parameters:

  • to (String)

    The recipient’s phone number in E.164 format (e.g., +12345678901).

  • from (String)

    The sender’s phone number in E.164 format. Must be owned by the user.

  • text (String) (defaults to: nil)

    The MMS message content (max 1600 characters).

  • media_urls (Array<String>)

    The URLs of media to include. ‘jpeg`, `jpg`, `gif`, and `png` file types are fully supported and have a size limit of 5 MB. 500 KB limit for other types. Up to 10 media URLs can be included.

  • status_callback (String) (defaults to: nil)

    Optional URL to receive a POST request when the message status changes. Read more about status callbacks [here](/api-reference/receive-msg-statuses).

  • request_options (Pinnacle::RequestOptions) (defaults to: nil)

Returns:



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/rcs/send/client.rb', line 169

def mms(to:, from:, media_urls:, text: nil, status_callback: nil, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["PINNACLE-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      to: to,
      from: from,
      text: text,
      mediaUrls: media_urls,
      statusCallback: status_callback
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/send/mms"
  end
  Pinnacle::Send::SendMmsResponse.from_json(json_object: response.body)
end

#rcs(from:, to:, text: nil, media_url: nil, cards: nil, quick_replies: nil, fallback: nil, status_callback: nil, request_options: nil) ⇒ Pinnacle::Send::SendRcsResponse

Send an interactive RCS message with text, media, or cards. Each message can

only contain either text, media, or card(s).
Quick replies can also be added to the message.

Examples:

api = Pinnacle::Client.new(
  base_url: "https://api.example.com",
  environment: Pinnacle::Environment::DEFAULT,
  api_key: "YOUR_API_KEY"
)
api.send.rcs(from: "from", to: "to")

Parameters:

  • from (String)

    The id of the RCS agent sending the message. Use ‘test’ if you want to send from the Pinnacle test agent. The test agent can only send to whitelisted test numbers. See dashboard.trypinnacle.app/settings/test-numbers to whitelist a number.

  • to (String)

    The recipient’s RCS-enabled phone number in E.164 format (e.g., +12345678901).

  • text (String) (defaults to: nil)

    Text content of the message. Make sure you have either ‘text’, ‘mediaUrl’, or ‘cards’. An error will be thrown if multiple (i.e. both ‘text’ and ‘mediaUrl’) is provided.

  • media_url (String) (defaults to: nil)

    Media URL to be included in the message. Make sure you have either ‘text’, ‘mediaUrl’, or ‘cards’. An error will be thrown if multiple (i.e. both ‘text’ and ‘mediaUrl’) is provided.

  • cards (Array<Hash>) (defaults to: nil)

    List of rich cards. Maximum of 10 cards. Make sure you have either ‘text’, ‘mediaUrl’, or ‘cards’. An error will be thrown if multiple (i.e. both ‘text’ and ‘mediaUrl’) is provided.Request of type Array<Pinnacle::Card>, as a Hash

    * :title (String)
    * :subtitle (String)
    * :media_url (String)
    * :buttons (Array<Pinnacle::Action>)
    
  • quick_replies (Array<Hash>) (defaults to: nil)

    Optional list of quick reply actions (max 10).Request of type Array<Pinnacle::Action>, as a Hash

    • :title (String)

    • :type (Pinnacle::ActionType)

    • :payload (String)

    • :metadata (String)

    • :event_start_time (String)

    • :event_end_time (String)

    • :event_title (String)

    • :event_description (String)

    • :lat_long (Hash)

      • :lat (Float)

      • :lng (Float)

  • fallback (Hash) (defaults to: nil)

    Request of type Pinnacle::Send::RcsFallback, as a Hash

    • :from (String)

    • :text (String)

    • :media_urls (Array<String>)

  • status_callback (String) (defaults to: nil)

    Optional URL to receive a POST request when the message status changes. Read more about status callbacks [here](/api-reference/receive-msg-statuses).

  • request_options (Pinnacle::RequestOptions) (defaults to: nil)

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rcs/send/client.rb', line 73

def rcs(from:, to:, text: nil, media_url: nil, cards: nil, quick_replies: nil, fallback: nil, status_callback: nil,
        request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["PINNACLE-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      from: from,
      to: to,
      text: text,
      mediaUrl: media_url,
      cards: cards,
      quickReplies: quick_replies,
      fallback: fallback,
      statusCallback: status_callback
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/send/rcs"
  end
  Pinnacle::Send::SendRcsResponse.from_json(json_object: response.body)
end

#sms(to:, from:, text:, status_callback: nil, request_options: nil) ⇒ Pinnacle::Send::SendSmsResponse

Send an SMS message to a recipient.

Examples:

api = Pinnacle::Client.new(
  base_url: "https://api.example.com",
  environment: Pinnacle::Environment::DEFAULT,
  api_key: "YOUR_API_KEY"
)
api.send.sms(
  to: "to",
  from: "from",
  text: "text"
)

Parameters:

  • to (String)

    The recipient’s phone number in E.164 format (e.g., +12345678901).

  • from (String)

    The sender’s phone number in E.164 format. Must be owned by the user.

  • text (String)

    The SMS message content (max 1600 characters).

  • status_callback (String) (defaults to: nil)

    Optional URL to receive a POST request when the message status changes. Read more about status callbacks [here](/api-reference/receive-msg-statuses).

  • request_options (Pinnacle::RequestOptions) (defaults to: nil)

Returns:



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/rcs/send/client.rb', line 122

def sms(to:, from:, text:, status_callback: nil, request_options: nil)
  response = @request_client.conn.post do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    req.headers["PINNACLE-API-Key"] = request_options.api_key unless request_options&.api_key.nil?
    req.headers = {
  **(req.headers || {}),
  **@request_client.get_headers,
  **(request_options&.additional_headers || {})
    }.compact
    unless request_options.nil? || request_options&.additional_query_parameters.nil?
      req.params = { **(request_options&.additional_query_parameters || {}) }.compact
    end
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      to: to,
      from: from,
      text: text,
      statusCallback: status_callback
    }.compact
    req.url "#{@request_client.get_url(request_options: request_options)}/send/sms"
  end
  Pinnacle::Send::SendSmsResponse.from_json(json_object: response.body)
end