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:



201
202
203
# File 'lib/rcs/send/client.rb', line 201

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientPinnacle::AsyncRequestClient (readonly)



197
198
199
# File 'lib/rcs/send/client.rb', line 197

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:



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/rcs/send/client.rb', line 355

def mms(to:, from:, media_urls:, text: nil, status_callback: 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 || {}),
        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
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:



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/rcs/send/client.rb', line 255

def rcs(from:, to:, text: nil, media_url: nil, cards: nil, quick_replies: nil, fallback: nil, status_callback: 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,
        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
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:



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/rcs/send/client.rb', line 306

def sms(to:, from:, text:, status_callback: 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 || {}),
        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
end