Class: TelegramWorkflow::Params
- Inherits:
-
Object
- Object
- TelegramWorkflow::Params
- Defined in:
- lib/telegram_workflow/params.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #callback_data ⇒ Object
- #chat ⇒ Object
- #chat_id ⇒ Object
- #command? ⇒ Boolean
- #deep_link_payload ⇒ Object
-
#initialize(params) ⇒ Params
constructor
A new instance of Params.
- #inline_data ⇒ Object
- #language_code ⇒ Object
- #message ⇒ Object
- #message_text ⇒ Object
- #start? ⇒ Boolean
- #to_h ⇒ Object
- #user ⇒ Object
- #user_id ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(params) ⇒ Params
Returns a new instance of Params.
4 5 6 |
# File 'lib/telegram_workflow/params.rb', line 4 def initialize(params) @params = params end |
Instance Method Details
#[](key) ⇒ Object
8 9 10 |
# File 'lib/telegram_workflow/params.rb', line 8 def [](key) @params[key] end |
#callback_data ⇒ Object
60 61 62 |
# File 'lib/telegram_workflow/params.rb', line 60 def callback_data @params.dig("callback_query", "data") end |
#chat ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/telegram_workflow/params.rb', line 41 def chat @params.dig("message", "chat") || @params.dig("callback_query", "message", "chat") || @params.dig("edited_message", "chat") || @params.dig("channel_post", "chat") || @params.dig("edited_channel_post", "chat") end |
#chat_id ⇒ Object
37 38 39 |
# File 'lib/telegram_workflow/params.rb', line 37 def chat_id chat&.dig("id") end |
#command? ⇒ Boolean
72 73 74 |
# File 'lib/telegram_workflow/params.rb', line 72 def command? !!&.start_with?("/") end |
#deep_link_payload ⇒ Object
76 77 78 79 |
# File 'lib/telegram_workflow/params.rb', line 76 def deep_link_payload match = /\A\/(startgroup|start) (?<payload>.+)\z/.match() match["payload"] if match end |
#inline_data ⇒ Object
64 65 66 |
# File 'lib/telegram_workflow/params.rb', line 64 def inline_data @params.dig("inline_query", "query") end |
#language_code ⇒ Object
25 26 27 |
# File 'lib/telegram_workflow/params.rb', line 25 def language_code user&.dig("language_code") || "en" end |
#message ⇒ Object
49 50 51 52 53 54 |
# File 'lib/telegram_workflow/params.rb', line 49 def @params["message"] || @params["edited_message"] || @params["channel_post"] || @params["edited_channel_post"] end |
#message_text ⇒ Object
56 57 58 |
# File 'lib/telegram_workflow/params.rb', line 56 def &.dig("text") end |
#start? ⇒ Boolean
68 69 70 |
# File 'lib/telegram_workflow/params.rb', line 68 def start? !!&.start_with?("/start") end |
#to_h ⇒ Object
81 82 83 |
# File 'lib/telegram_workflow/params.rb', line 81 def to_h @params end |
#user ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/telegram_workflow/params.rb', line 12 def user @user ||= &.dig("from") || @params.dig("callback_query", "from") || @params.dig("pre_checkout_query", "from") || @params.dig("shipping_query", "from") || @params.dig("inline_query", "from") || @params.dig("chosen_inline_result", "from") || @params.dig("poll_answer", "user") || @params.dig("chat_join_request", "from") || @params.dig("chat_member", "from") || @params.dig("my_chat_member", "from") end |
#user_id ⇒ Object
29 30 31 |
# File 'lib/telegram_workflow/params.rb', line 29 def user_id user&.dig("id") end |
#username ⇒ Object
33 34 35 |
# File 'lib/telegram_workflow/params.rb', line 33 def username user&.dig("username") end |