class TelegramWorkflow::Params

Public Class Methods

new(params) click to toggle source
# File lib/telegram_workflow/params.rb, line 4
def initialize(params)
  @params = params
end

Public Instance Methods

[](key) click to toggle source
# File lib/telegram_workflow/params.rb, line 8
def [](key)
  @params[key]
end
callback_data() click to toggle source
# File lib/telegram_workflow/params.rb, line 53
def callback_data
  @params.dig("callback_query", "data")
end
chat_id() click to toggle source
# File lib/telegram_workflow/params.rb, line 34
def chat_id
  @params.dig("message", "chat", "id") ||
    @params.dig("callback_query", "message", "chat", "id") ||
    @params.dig("edited_message", "chat", "id") ||
    @params.dig("channel_post", "chat", "id") ||
    @params.dig("edited_channel_post", "chat", "id")
end
command?() click to toggle source
# File lib/telegram_workflow/params.rb, line 65
def command?
  !!message_text&.start_with?("/")
end
inline_data() click to toggle source
# File lib/telegram_workflow/params.rb, line 57
def inline_data
  @params.dig("inline_query", "query")
end
language_code() click to toggle source
# File lib/telegram_workflow/params.rb, line 22
def language_code
  user&.dig("language_code") || "en"
end
message() click to toggle source
# File lib/telegram_workflow/params.rb, line 42
def message
  @params["message"] ||
    @params["edited_message"] ||
    @params["channel_post"] ||
    @params["edited_channel_post"]
end
message_text() click to toggle source
# File lib/telegram_workflow/params.rb, line 49
def message_text
  message&.dig("text")
end
start?() click to toggle source
# File lib/telegram_workflow/params.rb, line 61
def start?
  !!message_text&.start_with?("/start")
end
to_h() click to toggle source
# File lib/telegram_workflow/params.rb, line 74
def to_h
  @params
end
user() click to toggle source
# File lib/telegram_workflow/params.rb, line 12
def user
  @user ||= message&.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")
end
user_id() click to toggle source
# File lib/telegram_workflow/params.rb, line 26
def user_id
  user&.dig("id")
end
username() click to toggle source
# File lib/telegram_workflow/params.rb, line 30
def username
  user&.dig("username")
end