Module: TelegramBot::RequestMethods

Included in:
TelegramBot
Defined in:
lib/telegram_bot/request_methods.rb

Constant Summary collapse

CHAT_ACTIONS =
[
  :typing,
  :upload_photo,
  :record_video,
  :update_video,
  :record_audio,
  :upload_audio,
  :upload_document,
  :find_location
]
METHODS =
[
  :get_me,
  :send_message,
  :forward_message,
  :send_photo,
  :send_document,
  :send_sticker,
  :send_video,
  :send_location,
  :send_chat_action,
  :get_user_profile_photos,
  :get_updates,
  :set_webhook
]

Instance Method Summary collapse

Instance Method Details

#forward_message(msg, to, from = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/telegram_bot/request_methods.rb', line 35

def forward_message(msg, to, from = nil)
  from_chat = from.nil? ? msg.chat : Chat.from(from)

  params = {
    chat_id: Chat.from(chat).id,
    from_chat_id: from_chat.id,
    message_id: Message.from(msg).id
  }

  Message.from(request(:forward_message, params))
end

#get_meObject



15
16
17
# File 'lib/telegram_bot/request_methods.rb', line 15

def get_me
  User.from(request(:get_me, {}))
end

#get_updates(offset: nil, limit: nil, timeout: nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/telegram_bot/request_methods.rb', line 3

def get_updates(offset: nil, limit: nil, timeout: nil)
  params = {
    offset:  offset,
    limit:   limit,
    timouet: timeout
  }.reject {|_,v| v.nil?}

  request(:get_updates, params).map do |update|
    Update.from(update)
  end
end

#send_chat_action(chat, action) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/telegram_bot/request_methods.rb', line 59

def send_chat_action(chat, action)
  unless CHAT_ACTIONS.include?(action.intern)
    warn "invalid chat action #{action}, available actions are" +
         " #{CHAT_ACTIONS.join(', ')}."
    action = CHAT_ACTIONS.first
  end

  params = {
    chat_id: Chat.from(chat).id,
    action: action.to_s
  }

  request(:send_chat_action, params)
  nil
end

#send_message(chat, text, disable_web_page_preview: nil, reply_to: nil, reply_markup: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/telegram_bot/request_methods.rb', line 19

def send_message(chat, text,
                 disable_web_page_preview: nil,
                 reply_to: nil,
                 reply_markup: nil)
  reply_to = Message.from(reply_to)
  params = {
    chat_id: Chat.from(chat).id,
    text: text,
    disable_web_page_preview: disable_web_page_preview,
    reply_to_message_id: reply_to && reply_to.id,
    reply_markup: reply_markup ? reply_markup.to_json : nil
  }.reject {|_,v| v.nil?}

  Message.from(request(:send_message, params))
end