Module: ChatgptAssistant::Bots::Telegram::Events
- Included in:
- TelegramBot
- Defined in:
- lib/chatgpt_assistant/bots/telegram/events.rb
Instance Method Summary collapse
- #audio_event ⇒ Object
- #confirm_account_event ⇒ Object
- #help_event ⇒ Object
- #hist_event ⇒ Object
- #list_event ⇒ Object
- #login_event ⇒ Object
- #new_chat_event ⇒ Object
- #register_event ⇒ Object
- #select_chat_event ⇒ Object
- #sign_out_event ⇒ Object
- #start_event ⇒ Object
- #telegram_chat_event ⇒ Object
Instance Method Details
#audio_event ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 98 def audio_event audio_allowed? user_audio = transcribe_file(telegram_audio_url) = Message.new(content: user_audio[:text], chat_id: user.current_chat_id, role: "user") raise MessageNotCreatedError unless .save ai_response = telegram_process_ai_voice(user_audio[:file]) (voice: ai_response[:voice], text: ai_response[:text]) delete_file ai_response[:voice] rescue UserNotLoggedInError, NoChatSelectedError, MessageNotCreatedError, AccountNotVerifiedError => e e., msg.chat.id end |
#confirm_account_event ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 36 def confirm_account_event raise UserNotLoggedInError if user.nil? user_info = msg.text.split("/* ").last name, token = user_info.split(":") "#{name} - #{token}", msg.chat.id if user_confirmed? [:account_confirmed], msg.chat.id else [:account_not_confirmed], msg.chat.id end rescue UserNotLoggedInError => e e., msg.chat.id end |
#help_event ⇒ Object
11 12 13 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 11 def help_event .each { |m| m, msg.chat.id } end |
#hist_event ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 15 def hist_event hist_allowed? user.chat_history.each do |m| m, msg.chat.id end rescue NoChatSelectedError, UserNotLoggedInError, NoMessagesFoundedError, AccountNotVerifiedError => e e., msg.chat.id end |
#list_event ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 25 def list_event list_allowed? [:chat_list], msg.chat.id chats_str = "" user.chats.each_with_index { |c, i| chats_str += "Chat #{i + 1} - #{c.title}\n" } chats_str, msg.chat.id rescue NoChatsFoundedError, UserNotLoggedInError, AccountNotVerifiedError => e e., msg.chat.id end |
#login_event ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 51 def login_event raise UserLoggedInError if user user_info = msg.text.split("/").last email, password = user_info.split(":") authenticate_user(email, password) rescue UserNotFoundError, WrongPasswordError, UserLoggedInError => e e., msg.chat.id end |
#new_chat_event ⇒ Object
80 81 82 83 84 85 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 80 def new_chat_event common_allowed? NewChatJob.perform_async(msg.text.split("/").last, user.id, msg.chat.id) rescue UserNotLoggedInError, AccountNotVerifiedError => e e., msg.chat.id end |
#register_event ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 61 def register_event user_info = msg.text.split("/").last email, password = register_allowed?(user_info) name = msg.from.first_name || "Anonymous" RegisterJob.perform_async(email, password, name, visitor.telegram_id) rescue NoRegisterInfoError, UserLoggedInError => e e., msg.chat.id end |
#select_chat_event ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 87 def select_chat_event common_allowed? title = msg.text.split("/").last chat = user.chat_by_title(title) select_allowed?(chat) [:chat_selected], msg.chat.id rescue UserNotLoggedInError, ChatNotFoundError, AccountNotVerifiedError => e e., msg.chat.id end |
#sign_out_event ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 71 def sign_out_event raise UserNotLoggedInError if user.nil? user.update(telegram_id: nil) [:user_logged_out], msg.chat.id rescue UserNotLoggedInError => e e., msg.chat.id end |
#start_event ⇒ Object
7 8 9 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 7 def start_event end |
#telegram_chat_event ⇒ Object
111 112 113 114 115 116 |
# File 'lib/chatgpt_assistant/bots/telegram/events.rb', line 111 def telegram_chat_event common_allowed? chat_if_exists rescue UserNotLoggedInError, AccountNotVerifiedError => e e., msg.chat.id end |