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:



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

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientPinnacle::RequestClient (readonly)



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

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:



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/rcs/send/client.rb', line 150

def mms(to:, from:, text:, media_urls:, 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
    }.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, 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:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/rcs/send/client.rb', line 66

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



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/rcs/send/client.rb', line 110

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