Class: Kogno::Telegram::InlineQuery
- Inherits:
-
Message
- Object
- Message
- Kogno::Telegram::InlineQuery
show all
- Defined in:
- lib/core/lib/telegram/inline_query.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Message
#attachments, #deep_link_data, #deep_link_param, #empty_thread_from_ad?, #location, #log_message_info, #nlp, #numbers_in_text, #overwrite_postback, #params, #payload, #postback_params, #postback_payload, #raw_message, #raw_payload, #referral, #set_nlp, #stickers, #webhook_data
Constructor Details
Returns a new instance of InlineQuery.
9
10
11
|
# File 'lib/core/lib/telegram/inline_query.rb', line 9
def initialize(data)
@data = data
end
|
Instance Attribute Details
#event ⇒ Object
Returns the value of attribute event.
5
6
7
|
# File 'lib/core/lib/telegram/inline_query.rb', line 5
def event
@event
end
|
Instance Method Details
#chat_type ⇒ Object
25
26
27
|
# File 'lib/core/lib/telegram/inline_query.rb', line 25
def chat_type
@data[:chat_type]
end
|
#empty? ⇒ Boolean
49
50
51
|
# File 'lib/core/lib/telegram/inline_query.rb', line 49
def empty?
self.text.to_s.empty?
end
|
#get_context(user, notification) ⇒ Object
58
59
60
61
62
63
|
# File 'lib/core/lib/telegram/inline_query.rb', line 58
def get_context(user,notification)
context_class = Context::router(Kogno::Application.config.routes.inline_query)[:class]
context = context_class.new(user,self,notification,nil, nil, user)
return(context)
end
|
#handle_event(debug = false) ⇒ Object
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
101
102
103
104
105
106
107
108
|
# File 'lib/core/lib/telegram/inline_query.rb', line 65
def handle_event(debug=false)
begin
user = User.find_or_create_by_psid(self.sender_id, :telegram)
user.first_name = self.sender_first_name
user.last_name = self.sender_last_name
user.save
self.set_nlp(user.locale)
I18n.locale = user.locale unless user.locale.nil?
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.answer_inline_query(self.id, self.sender_id)
recipient_psid = notification.get_psid_from_response_log
user = User.find_or_create_by_psid(self.sender_id, :telegram)
if Kogno::Application.config.store_log_in_database
user.log_message(self, :inline_query_received)
user.log_response(notification)
end
logger.write "**********************#{user.context}***********************", :green
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
|
#id ⇒ Object
29
30
31
|
# File 'lib/core/lib/telegram/inline_query.rb', line 29
def id
return @data[:id]
end
|
#page_id ⇒ Object
21
22
23
|
# File 'lib/core/lib/telegram/inline_query.rb', line 21
def page_id
nil
end
|
#payload_action ⇒ Object
45
46
47
|
# File 'lib/core/lib/telegram/inline_query.rb', line 45
def payload_action
nil
end
|
17
18
19
|
# File 'lib/core/lib/telegram/inline_query.rb', line 17
def platform
:telegram
end
|
#sender_first_name ⇒ Object
37
38
39
|
# File 'lib/core/lib/telegram/inline_query.rb', line 37
def sender_first_name
return @data[:from][:first_name] rescue ""
end
|
#sender_id ⇒ Object
33
34
35
|
# File 'lib/core/lib/telegram/inline_query.rb', line 33
def sender_id
return @data[:from][:id]
end
|
#sender_last_name ⇒ Object
41
42
43
|
# File 'lib/core/lib/telegram/inline_query.rb', line 41
def sender_last_name
return @data[:from][:last_name] rescue ""
end
|
#text ⇒ Object
54
55
56
|
# File 'lib/core/lib/telegram/inline_query.rb', line 54
def text
return (@data[:query].to_s rescue "")
end
|
#type ⇒ Object
13
14
15
|
# File 'lib/core/lib/telegram/inline_query.rb', line 13
def type
:inline_query
end
|