Class: Spree::Api::Webhook::TelegramBotsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/api/webhook/telegram_bots_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/spree/api/webhook/telegram_bots_controller.rb', line 8

def create
  chat_id = params.dig(:message, :chat, :id)
  text = params.dig(:message, :text)

  if text == '/start' && chat_id.present?
    send_message_to_user_in_queue(chat_id)
    head :ok
  else
    head :unprocessable_entity
  end
end

#send_message_to_user_in_queue(chat_id) ⇒ Object



20
21
22
23
24
25
# File 'app/controllers/spree/api/webhook/telegram_bots_controller.rb', line 20

def send_message_to_user_in_queue(chat_id)
  SpreeCmCommissioner::TelegramStartMessageSenderJob.perform_later(
    chat_id: chat_id,
    telegram_bot_id: @telegram_bot.id
  )
end