Module: ChatgptAssistant::Bots::Telegram::Actions
- Included in:
- TelegramBot
- Defined in:
- lib/chatgpt_assistant/bots/telegram/actions.rb
Instance Method Summary collapse
- #chat_created_message(chat) ⇒ Object
- #telegram_create_chat ⇒ Object
- #telegram_send_start_message ⇒ Object
- #telegram_user_create(visitor_id, email, password) ⇒ Object
Instance Method Details
#chat_created_message(chat) ⇒ Object
46 47 48 49 50 |
# File 'lib/chatgpt_assistant/bots/telegram/actions.rb', line 46 def (chat) bot.api.(chat_id: msg.chat.id, text: "Intructions sended to actor:\n#{chat.prompt}") unless chat.actor.nil? bot.api.(chat_id: msg.chat.id, text: "Response from assistant:\n#{chat.[1].content}") unless chat.actor.nil? bot.api.(chat_id: msg.chat.id, text: [:chat_created]) if bot.respond_to?(:api) end |
#telegram_create_chat ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/chatgpt_assistant/bots/telegram/actions.rb', line 24 def telegram_create_chat text = msg.text title = text.split("/").last mode = nil if title.include?(":") mode = title.split(":").last title = title.split(":").first end actor_modes = AwesomeChatgptActors::CastControl.actors return "invalid mode", msg.chat.id unless (mode.to_i >= 1 && mode.to_i <= actor_modes.size + 1) || mode.nil? return "invalid chat title", msg.chat.id if title.nil? || title.empty? return "You already have a chat with this title", msg.chat.id if user.chat_by_title(title) actor_name = actor_modes[mode.to_i - 1] if mode actor = AwesomeChatgptActors::Actor.new(prompt_type: actor_name) if actor_name chat = Chat.new(user_id: user.id, status: 0, title: title, actor: actor_name, prompt: actor.prompt) if actor chat = Chat.new(user_id: user.id, status: 0, title: title) unless actor return "Something went wrong", msg.chat.id unless chat chat.save ? (chat) : (chat_id: msg.chat.id, text: [:chat_creation_failed]) end |
#telegram_send_start_message ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/chatgpt_assistant/bots/telegram/actions.rb', line 16 def [:start], msg.chat.id = .join("\n").to_s , msg.chat.id [:start_helper], msg.chat.id [:start_sec_helper], msg.chat.id end |
#telegram_user_create(visitor_id, email, password) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/chatgpt_assistant/bots/telegram/actions.rb', line 7 def telegram_user_create(visitor_id, email, password) visitor = Visitor.find_by(id: visitor_id) return false unless visitor visitor.tel_user.update(telegram_id: nil) if visitor.tel_user.present? user = User.new(telegram_id: visitor.telegram_id, email: email, password: password) user.save ? user.email : user.errors. end |