Class: FacebookMessenger
Overview
Facebook Logger
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ FacebookMessenger
constructor
A new instance of FacebookMessenger.
- #log_incoming(message) ⇒ Object
- #log_outgoing(message, sender_id) ⇒ Object
- #log_user_profile(message) ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ FacebookMessenger
Returns a new instance of FacebookMessenger.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/botanalytics/facebook.rb', line 9 def initialize(params = {}) super(params) @fb_token = params.fetch(:fb_token, nil) @path = 'messages/facebook-messenger/' @profile_path = 'facebook-messenger/users/' @async = params.fetch(:async, false) informs("Logging enabled for #{self.class.name}...") if @async require 'concurrent' @executor_service = Concurrent::ThreadPoolExecutor.new( min_threads: 1, max_threads: Concurrent.processor_count, max_queue: 100, fallback_policy: :caller_runs ) informs("Mode: Async...") end end |
Instance Method Details
#log_incoming(message) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/botanalytics/facebook.rb', line 28 def log_incoming() validation = validate(, "Incoming message") if validation[:ok] payload = { 'recipient': nil, 'timestamp': (Time.new.to_f*1000).to_i, 'message': } informs("Logging incoming message...") informs() if @async @executor_service.post do submits(payload, @path) end else submits(payload, @path) end else fails(validation[:err], validation[:reason], ) end end |
#log_outgoing(message, sender_id) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/botanalytics/facebook.rb', line 51 def log_outgoing(, sender_id) validation = validate_outgoing(, sender_id) if validation[:ok] payload = { 'recipient': sender_id, 'timestamp': (Time.new.to_f*1000).to_i, 'message': , 'fb_token': @fb_token } informs("Logging outgoing message...") informs() if @async @executor_service.post do submits(payload, @path) end else submits(payload, @path) end else fails(validation[:err], validation[:reason], ) end end |
#log_user_profile(message) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/botanalytics/facebook.rb', line 75 def log_user_profile() validation = validate(, "User profile") if validation[:ok] informs("Logging user profile message...") informs() if @async @executor_service.post do submits(, @profile_path) end else submits(, @profile_path) end else fails(validation[:err], validation[:reason], ) end end |