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.
-
#get_line_channel_status(request_options: {}, **params) ⇒ Apologist::Channels::Types::GetLineChannelStatusResponse
Returns the status of the LINE channel.
- #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_line_webhook(request_options: {}, **params) ⇒ untyped
Receives LINE Messaging API webhook 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.
-
#receive_whats_app_message(request_options: {}, **params) ⇒ untyped
Receives WhatsApp Cloud API message events for the channel.
-
#verify_facebook_webhook(request_options: {}, **params) ⇒ String
Handles the Meta webhook verification handshake, echoing
hub.challengewhenhub.verify_tokenmatches the channel's configured token. -
#verify_whats_app_webhook(request_options: {}, **params) ⇒ String
Handles the Meta WhatsApp Cloud API 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.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/Apologist/channels/client.rb', line 301 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 |
#get_line_channel_status(request_options: {}, **params) ⇒ Apologist::Channels::Types::GetLineChannelStatusResponse
Returns the status of the LINE channel. Used as a lightweight health/verification endpoint.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/Apologist/channels/client.rb', line 119 def get_line_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)}/line", 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::GetLineChannelStatusResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end 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.
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/Apologist/channels/client.rb', line 262 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_line_webhook(request_options: {}, **params) ⇒ untyped
Receives LINE Messaging API webhook events for the channel. Requests are verified via the x-line-signature
HMAC-SHA256 (Base64) header using the channel secret unless an api_key is present. Payload shape is defined by
LINE. The route acknowledges quickly and processes text message and follow events asynchronously.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/Apologist/channels/client.rb', line 164 def receive_line_webhook(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-line-signature"] = params[:line_signature] if params[:line_signature] request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/line", 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_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.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/Apologist/channels/client.rb', line 342 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.
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/Apologist/channels/client.rb', line 381 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 |
#receive_whats_app_message(request_options: {}, **params) ⇒ untyped
Receives WhatsApp Cloud API message events for the channel. Payload shape is defined by Meta. Signature
verification via x-hub-signature-256 is used when the channel has an App Secret configured; otherwise the
webhook relies on URL secrecy and/or an api_key query parameter.
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/Apologist/channels/client.rb', line 478 def (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-hub-signature-256"] = params[:hub_signature256] if params[:hub_signature256] request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "channels/#{URI.encode_uri_component(params[:id].to_s)}/whatsapp", 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 |
#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.
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/Apologist/channels/client.rb', line 215 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 |
#verify_whats_app_webhook(request_options: {}, **params) ⇒ String
Handles the Meta WhatsApp Cloud API webhook verification handshake, echoing hub.challenge when
hub.verify_token matches the channel's configured token.
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/Apologist/channels/client.rb', line 429 def verify_whats_app_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)}/whatsapp", 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 |