Class: Pinnacle::Messages::Rcs::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



10
11
12
# File 'lib/pinnacle/messages/rcs/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#send_(request_options: {}, **params) ⇒ Pinnacle::Messages::Rcs::Types::SendRichMessageResponse

Send a RCS message immediately or schedule it for future delivery.

Requires an active RCS agent and recipient devices that support RCS Business Messaging.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pinnacle/messages/rcs/client.rb', line 27

def send_(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "messages/send/rcs",
    body: Pinnacle::Types::RichMessage.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Messages::Rcs::Types::SendRichMessageResponse.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#send_typing(request_options: {}, **params) ⇒ Pinnacle::Types::SendTypingIndicatorResponse

Send a typing indicator from an RCS agent to a recipient.

This endpoint allows RCS agents to display a typing indicator to recipients. The indicator is a message bubble with animated typing dots like this: <img src=“” alt=“Typing Indicator” style=“display: inline; height: 1.5em; vertical-align: middle; margin: 0 4px;” />

**Use Case:** Typing indicators are especially useful for providing feedback to users while the agent is thinking or generating a response that may take some time, creating a more engaging conversational experience.

Expiration: Typing indicators automatically expire after around 20 seconds or when the agent sends a message, whichever comes first.

Frequency: You can send typing indicators as many times as needed, though only one will be displayed at a time. Sending multiple typing indicators will extend the duration of the current indicator.

> Note: Typing indicators are best-effort hints, not delivery-guaranteed state. The platform is allowed to coalesce or drop them, and the client UI decides when to show/hide.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/pinnacle/messages/rcs/client.rb', line 78

def send_typing(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "messages/send/typing",
    body: Pinnacle::Messages::Rcs::Types::SendTypingIndicatorSchema.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::SendTypingIndicatorResponse.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#validate(request_options: {}, **params) ⇒ Pinnacle::Types::RcsValidationResult

Validate RCS message content without sending it.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/pinnacle/messages/rcs/client.rb', line 112

def validate(request_options: {}, **params)
  params = Pinnacle::Internal::Types::Utils.normalize_keys(params)
  request = Pinnacle::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "messages/validate/rcs",
    body: Pinnacle::Types::RcsValidateContent.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Pinnacle::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Pinnacle::Types::RcsValidationResult.load(response.body)
  else
    error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end