Module: ChatgptAssistant::Bots::Telegram::VoiceActions

Included in:
TelegramBot
Defined in:
lib/chatgpt_assistant/bots/telegram/voice_actions.rb

Instance Method Summary collapse

Instance Method Details

#telegram_audioObject



15
16
17
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 15

def telegram_audio
  msg.audio || msg.voice
end

#telegram_audio_infoObject



7
8
9
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 7

def telegram_audio_info
  bot.api.get_file(file_id: telegram_audio.file_id)
end

#telegram_audio_urlObject



11
12
13
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 11

def telegram_audio_url
  "https://api.telegram.org/file/bot#{telegram_token}/#{telegram_audio_info["result"]["file_path"]}"
end

#telegram_process_ai_voice(user_audio) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 19

def telegram_process_ai_voice(user_audio)
  ai_text = chatter.chat(user_audio["text"], user.current_chat_id, error_messages[:something_went_wrong])
  ai_voice = synthesis.synthesize_text(ai_text)
  {
    voice: ai_voice,
    text: ai_text
  }
end

#telegram_send_voice_message(voice: nil, text: nil) ⇒ Object



28
29
30
31
32
# File 'lib/chatgpt_assistant/bots/telegram/voice_actions.rb', line 28

def telegram_send_voice_message(voice: nil, text: nil)
  messages = parse_message text, 4096
  bot.api.send_voice(chat_id: msg.chat.id, voice: Faraday::UploadIO.new(voice, "audio/mp3"))
  messages.each { |message| send_message message, msg.chat.id }
end