Class: Kogno::WhatsApp::StatusMessage
- Inherits:
-
Message
- Object
- Message
- Kogno::WhatsApp::StatusMessage
show all
- Defined in:
- lib/core/lib/whatsapp/status_message.rb
Instance Attribute Summary
Attributes inherited from Message
#event
Instance Method Summary
collapse
Methods inherited from Message
#attachments, #deep_link_data, #deep_link_param, #empty?, #empty_thread_from_ad?, #get_context, #location, #log_message_info, #nlp, #numbers_in_text, #overwrite_postback, #page_id, #params, #payload, #payload_action, #postback_params, #postback_payload, #raw_message, #raw_payload, #referral, #set_nlp, #stickers, #text, #webhook_data
Constructor Details
#initialize(data, type = nil) ⇒ StatusMessage
Returns a new instance of StatusMessage.
7
8
9
10
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 7
def initialize(data, type=nil)
@data = data
@type = type
end
|
Instance Method Details
#handle_event(debug = false) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 37
def handle_event(debug=false)
begin
user = User.find_or_create_by_psid(self.sender_id, :whatsapp)
if self.status == "read"
user.mark_last_message_as_read
end
rescue StandardError => e
error_token = Digest::MD5.hexdigest("#{Time.now}#{rand(1000)}") logger.write e.message, :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
|
28
29
30
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 28
def metadata
@data[:metadata]
end
|
16
17
18
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 16
def platform
:whatsapp
end
|
#sender_id ⇒ Object
32
33
34
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 32
def sender_id
return self.status_raw[:recipient_id]
end
|
#status ⇒ Object
24
25
26
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 24
def status
self.status_raw[:status]
end
|
#status_raw ⇒ Object
20
21
22
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 20
def status_raw
@data[:statuses][0]
end
|
#type ⇒ Object
12
13
14
|
# File 'lib/core/lib/whatsapp/status_message.rb', line 12
def type
@type
end
|