Class: Pinnacle::AsyncSendClient

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::AsyncSendClient

Parameters:



181
182
183
# File 'lib/rcs/send/client.rb', line 181

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientPinnacle::AsyncRequestClient (readonly)



177
178
179
# File 'lib/rcs/send/client.rb', line 177

def request_client
  @request_client
end

Instance Method Details

#mms(to:, from:, text:, media_urls:, 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",
  text: "text",
  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)

    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.

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

Returns:



317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/rcs/send/client.rb', line 317

def mms(to:, from:, text:, media_urls:, request_options: nil)
  Async do
    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
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/send/mms"
    end
    Pinnacle::Send::SendMmsResponse.from_json(json_object: response.body)
  end
end

#rcs(from:, to:, text: nil, media_url: nil, cards: nil, quick_replies: 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)

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

Returns:



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/rcs/send/client.rb', line 229

def rcs(from:, to:, text: nil, media_url: nil, cards: nil, quick_replies: nil, request_options: nil)
  Async do
    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
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/send/rcs"
    end
    Pinnacle::Send::SendRcsResponse.from_json(json_object: response.body)
  end
end

#sms(to:, from:, text:, 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).

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

Returns:



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/rcs/send/client.rb', line 275

def sms(to:, from:, text:, request_options: nil)
  Async do
    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 }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/send/sms"
    end
    Pinnacle::Send::SendSmsResponse.from_json(json_object: response.body)
  end
end