Module: Telegram::Bot::UpdatesController::ReplyHelpers

Included in:
Telegram::Bot::UpdatesController
Defined in:
lib/telegram/bot/updates_controller/reply_helpers.rb

Instance Method Summary collapse

Instance Method Details

#answer_callback_query(text, params = {}) ⇒ Object

Same as respond_with, but for callback queries.



36
37
38
39
40
41
42
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 36

def answer_callback_query(text, params = {})
  params = params.merge(
    callback_query_id: payload['id'],
    text: text,
  )
  bot.answer_callback_query(params)
end

#answer_inline_query(results, params = {}) ⇒ Object

Same as respond_with, but for inline queries.



27
28
29
30
31
32
33
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 27

def answer_inline_query(results, params = {})
  params = params.merge(
    inline_query_id: payload['id'],
    results: results,
  )
  bot.answer_inline_query(params)
end

#answer_pre_checkout_query(ok, params = {}) ⇒ Object

Same as respond_with, but for pre checkout queries.



45
46
47
48
49
50
51
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 45

def answer_pre_checkout_query(ok, params = {})
  params = params.merge(
    pre_checkout_query_id: payload['id'],
    ok: ok,
  )
  bot.answer_pre_checkout_query(params)
end

#answer_shipping_query(ok, params = {}) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 53

def answer_shipping_query(ok, params = {})
  params = params.merge(
    shipping_query_id: payload['id'],
    ok: ok,
  )
  bot.answer_shipping_query(params)
end

#edit_message(type, params = {}) ⇒ Object

Edit message from callback query.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 62

def edit_message(type, params = {})
  params =
    if message_id = payload['inline_message_id'] # rubocop:disable Lint/AssignmentInCondition
      params.merge(inline_message_id: message_id)
    elsif message = payload['message'] # rubocop:disable Lint/AssignmentInCondition
      params.merge(chat_id: message['chat']['id'], message_id: message['message_id'])
    else
      raise 'Can not edit message without `inline_message_id` or `message`'
    end
  bot.public_send("edit_message_#{type}", params)
end

#reply_with(type, params) ⇒ Object

Same as respond_with but also sets ‘reply_to_message_id`.



19
20
21
22
23
24
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 19

def reply_with(type, params)
  payload = self.payload
  message_id = payload && payload['message_id']
  params = params.merge(reply_to_message_id: message_id) if message_id
  respond_with(type, params)
end

#respond_with(type, params) ⇒ Object

Helper to call bot’s ‘send_#type` method with already set `chat_id`:

respond_with :message, text: 'Hello!'
respond_with :message, text: '__Hello!__', parse_mode: :Markdown
respond_with :photo, photo: File.open(photo_to_send), caption: "It's incredible!"


12
13
14
15
16
# File 'lib/telegram/bot/updates_controller/reply_helpers.rb', line 12

def respond_with(type, params)
  chat = self.chat
  chat_id = chat && chat['id'] or raise 'Can not respond_with when chat is not present'
  bot.public_send("send_#{type}", params.merge(chat_id: chat_id))
end