From 6228476acc608c9d755897d9b866bf2d774c1bed Mon Sep 17 00:00:00 2001 From: Joaquin Perez Date: Mon, 7 Aug 2023 15:31:56 -0300 Subject: [PATCH 1/2] Get nlp data from FB --- lib/stealth/services/facebook/events/message_event.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/stealth/services/facebook/events/message_event.rb b/lib/stealth/services/facebook/events/message_event.rb index c3fce80..6813b65 100644 --- a/lib/stealth/services/facebook/events/message_event.rb +++ b/lib/stealth/services/facebook/events/message_event.rb @@ -18,6 +18,7 @@ def process fetch_message fetch_location fetch_attachments + fetch_nlp end private @@ -68,6 +69,12 @@ def fetch_attachments end end + def fetch_nlp + if params.dig('message', 'nlp').present? + service_message.nlp_result = params.dig('message', 'nlp').as_json + end + end + end end From c5d05d115595961cce5ba5c5511fd01258198f92 Mon Sep 17 00:00:00 2001 From: Joaquin Perez Date: Thu, 4 Jan 2024 18:43:08 -0300 Subject: [PATCH 2/2] Added ENV vars for testing --- lib/stealth/services/facebook/client.rb | 40 ++++++++++++++++++------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/stealth/services/facebook/client.rb b/lib/stealth/services/facebook/client.rb index 990ef67..11a2218 100644 --- a/lib/stealth/services/facebook/client.rb +++ b/lib/stealth/services/facebook/client.rb @@ -12,10 +12,13 @@ module Services module Facebook class Client < Stealth::Services::BaseClient + FB_URL = ENV['FACEBOOK_API_URL'] || "graph.facebook.com" + FB_HTTP_PROTOCOL = ENV['FACEBOOK_HTTP_PROTOCOL'] || "https" + FB_ENDPOINT = if ENV['FACEBOOK_API_VERSION'].present? - "https://graph.facebook.com/v#{ENV['FACEBOOK_API_VERSION']}/me" + "#{FB_HTTP_PROTOCOL}://#{FB_URL}/v#{ENV['FACEBOOK_API_VERSION']}/me" else - "https://graph.facebook.com/v3.2/me" + "#{FB_HTTP_PROTOCOL}://#{FB_URL}/v3.2/me" end attr_reader :api_endpoint, :reply @@ -67,11 +70,19 @@ def self.fetch_profile(recipient_id:, fields: nil) access_token: Stealth.config.facebook.page_access_token } - uri = URI::HTTPS.build( - host: "graph.facebook.com", - path: "/#{recipient_id}", - query: query_hash.to_query - ) + if FB_HTTP_PROTOCOL == 'https' + uri = URI::HTTPS.build( + host: FB_URL, + path: "/#{recipient_id}", + query: query_hash.to_query + ) + elsif FB_HTTP_PROTOCOL == 'http' + uri = URI::HTTP.build( + host: FB_URL, + path: "/#{recipient_id}", + query: query_hash.to_query + ) + end res = http_client.get(uri.to_s) Stealth::Logger.l(topic: @@ -107,10 +118,17 @@ def self.track(recipient_id:, metric:, value:, options: {}) page_id: Stealth.config.facebook.page_id } - uri = URI::HTTPS.build( - host: "graph.facebook.com", - path: "/#{Stealth.config.facebook.app_id}/activities" - ) + if FB_HTTP_PROTOCOL == 'https' + uri = URI::HTTPS.build( + host: FB_URL, + path: "/#{Stealth.config.facebook.app_id}/activities" + ) + elsif FB_HTTP_PROTOCOL == 'http' + uri = URI::HTTP.build( + host: FB_URL, + path: "/#{Stealth.config.facebook.app_id}/activities" + ) + end res = http_client.post(uri.to_s, body: MultiJson.dump(params)) Stealth::Logger.l(