Class: Kogno::Messenger::PostComment
- Inherits:
-
Object
- Object
- Kogno::Messenger::PostComment
- Defined in:
- lib/core/lib/messenger/post_comment.rb
Instance Attribute Summary collapse
-
#event ⇒ Object
Returns the value of attribute event.
Instance Method Summary collapse
- #comment_id ⇒ Object
- #empty? ⇒ Boolean
- #get_context(user, notification) ⇒ Object
- #handle_event(debug = false) ⇒ Object
-
#initialize(data, page_id) ⇒ PostComment
constructor
A new instance of PostComment.
- #item_type ⇒ Object
- #page_id ⇒ Object
- #payload_action ⇒ Object
- #post_id ⇒ Object
- #sender_id ⇒ Object
- #sender_name ⇒ Object
- #text ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(data, page_id) ⇒ PostComment
Returns a new instance of PostComment.
9 10 11 12 |
# File 'lib/core/lib/messenger/post_comment.rb', line 9 def initialize(data, page_id) @data = data @page_id = page_id end |
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event.
5 6 7 |
# File 'lib/core/lib/messenger/post_comment.rb', line 5 def event @event end |
Instance Method Details
#comment_id ⇒ Object
46 47 48 |
# File 'lib/core/lib/messenger/post_comment.rb', line 46 def comment_id return(@data[:value][:comment_id] rescue nil) end |
#empty? ⇒ Boolean
58 59 60 |
# File 'lib/core/lib/messenger/post_comment.rb', line 58 def empty? self.text.to_s.empty? end |
#get_context(user, notification) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/core/lib/messenger/post_comment.rb', line 50 def get_context(user,notification) # Here you can use different contexts by self.post_id context_class = Context::router(Kogno::Application.config.routes.post_comment)[:class] context_route = nil context = context_class.new(user,self,notification,context_route) return(context) end |
#handle_event(debug = false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 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 |
# File 'lib/core/lib/messenger/post_comment.rb', line 62 def handle_event(debug=false) begin user = User.new(last_usage_at: Time.now, vars:{}) self.set_nlp(user.locale) notification = Notification.new(user,self) logger.write "--------------------MESSAGE: #{self.text}--------------------------", :green context = get_context(user,notification) return({post_comment: self, user: user, notification: notification, context: context}) if debug context.run_for_text_only notification.send_private_reply(self.comment_id) recipient_psid = notification.get_psid_from_response_log user = User.find_or_create_by_psid(recipient_psid, :messenger, self.page_id, self.sender_id, false) if Kogno::Application.config.store_log_in_database user.(self, :post_comment_received) user.log_response(notification) end logger.write "**********************#{user.context}***********************", :green rescue StandardError => e error_token = Digest::MD5.hexdigest("#{Time.now}#{rand(1000)}") # This helps to identify the error that arrives to Slack in order to search it in logs/http.log logger.write e., :red logger.write "Error Token: #{error_token}", :red logger.write "Backtrace:\n\t#{e.backtrace.join("\n\t")}", :red ErrorHandler.notify_by_slack(Kogno::Application.config.app_name,e, error_token) if Kogno::Application.config.error_notifier.slack[:enable] rescue false end end |
#item_type ⇒ Object
38 39 40 |
# File 'lib/core/lib/messenger/post_comment.rb', line 38 def item_type return(@data[:value][:item].to_sym rescue nil) end |
#page_id ⇒ Object
34 35 36 |
# File 'lib/core/lib/messenger/post_comment.rb', line 34 def page_id @page_id end |
#payload_action ⇒ Object
18 19 20 |
# File 'lib/core/lib/messenger/post_comment.rb', line 18 def payload_action nil end |
#post_id ⇒ Object
30 31 32 |
# File 'lib/core/lib/messenger/post_comment.rb', line 30 def post_id return(@data[:value][:post_id] rescue nil) end |
#sender_id ⇒ Object
22 23 24 |
# File 'lib/core/lib/messenger/post_comment.rb', line 22 def sender_id return(@data[:value][:from][:id] rescue nil) end |
#sender_name ⇒ Object
26 27 28 |
# File 'lib/core/lib/messenger/post_comment.rb', line 26 def sender_name return(@data[:value][:from][:name] rescue nil) end |
#text ⇒ Object
42 43 44 |
# File 'lib/core/lib/messenger/post_comment.rb', line 42 def text return(@data[:value][:message] rescue "") end |
#type ⇒ Object
14 15 16 |
# File 'lib/core/lib/messenger/post_comment.rb', line 14 def type :post_comment end |