Class: Apologist::Channels::Client
- Inherits:
-
Object
- Object
- Apologist::Channels::Client
- Defined in:
- lib/Apologist/channels/client.rb
Instance Method Summary collapse
-
#get_discord_channel_status(request_options: {}, **params) ⇒ Apologist::Channels::Types::GetDiscordChannelStatusResponse
Returns the status of the Discord channel.
-
#get_instagram_privacy_policy(request_options: {}, **params) ⇒ String
Returns a static HTML privacy policy page for the Instagram integration.
- #initialize(client:) ⇒ void constructor
-
#receive_discord_interaction(request_options: {}, **params) ⇒ untyped
Receives Discord interaction callbacks for the channel.
-
#receive_facebook_message(request_options: {}, **params) ⇒ untyped
Receives Facebook/Messenger (and Instagram-style) message events for the channel.
-
#receive_telegram_update(request_options: {}, **params) ⇒ untyped
Receives Telegram bot update events for the channel.
-
#receive_twilio_message(request_options: {}, **params) ⇒ untyped
Receives inbound Twilio messages for the channel as form-encoded data.
-
#verify_facebook_webhook(request_options: {}, **params) ⇒ String
Handles the Meta webhook verification handshake, echoing
hub.challengewhenhub.verify_tokenmatches the channel's configured token.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/Apologist/channels/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#get_discord_channel_status(request_options: {}, **params) ⇒ Apologist::Channels::Types::GetDiscordChannelStatusResponse
Returns the status of the Discord channel. Used as a lightweight health/verification endpoint.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/Apologist/channels/client.rb', line 28 def get_discord_channel_status(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/discord", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Channels::Types::GetDiscordChannelStatusResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get_instagram_privacy_policy(request_options: {}, **params) ⇒ String
Returns a static HTML privacy policy page for the Instagram integration.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/Apologist/channels/client.rb', line 213 def get_instagram_privacy_policy(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/instagram/privacy", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#receive_discord_interaction(request_options: {}, **params) ⇒ untyped
Receives Discord interaction callbacks for the channel. Requests are verified via Ed25519 signature headers; unsigned or invalid requests are rejected. Payload shape is defined by Discord.
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 101 102 |
# File 'lib/Apologist/channels/client.rb', line 75 def receive_discord_interaction(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) path_param_names = %i[id] body_params = params.except(*path_param_names) headers = {} headers["x-signature-ed25519"] = params[:signature_ed25519] if params[:signature_ed25519] headers["x-signature-timestamp"] = params[:signature_timestamp] if params[:signature_timestamp] request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/discord", headers: headers, body: body_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#receive_facebook_message(request_options: {}, **params) ⇒ untyped
Receives Facebook/Messenger (and Instagram-style) message events for the channel. Payload shape is defined by Meta.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/Apologist/channels/client.rb', line 174 def (request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) path_param_names = %i[id] body_params = params.except(*path_param_names) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/facebook", body: body_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#receive_telegram_update(request_options: {}, **params) ⇒ untyped
Receives Telegram bot update events for the channel. Non-message updates are acknowledged and ignored. Payload shape is defined by Telegram.
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/Apologist/channels/client.rb', line 254 def receive_telegram_update(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) path_param_names = %i[id] body_params = params.except(*path_param_names) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/telegram", body: body_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#receive_twilio_message(request_options: {}, **params) ⇒ untyped
Receives inbound Twilio messages for the channel as form-encoded data. Payload fields are defined by Twilio.
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/Apologist/channels/client.rb', line 293 def (request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request_data = Apologist::Channels::Types::ReceiveTwilioMessageRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Apologist::Internal::UrlEncoded::Request.new( base_url: [:base_url], method: "POST", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/twilio", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#verify_facebook_webhook(request_options: {}, **params) ⇒ String
Handles the Meta webhook verification handshake, echoing hub.challenge when hub.verify_token matches the
channel's configured token.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/Apologist/channels/client.rb', line 127 def verify_facebook_webhook(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["hub.mode"] = params[:hub_mode] if params.key?(:hub_mode) query_params["hub.verify_token"] = params[:hub_verify_token] if params.key?(:hub_verify_token) query_params["hub.challenge"] = params[:hub_challenge] if params.key?(:hub_challenge) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/facebook", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |