Class: ChatgptAssistant::RegisterService

Inherits:
Object
  • Object
show all
Defined in:
lib/chatgpt_assistant/bots/services/register_service.rb

Overview

This class is responsible to background the register service

Instance Method Summary collapse

Constructor Details

#initialize(email, password, name, chat_id) ⇒ RegisterService

Returns a new instance of RegisterService.



6
7
8
9
10
11
12
13
# File 'lib/chatgpt_assistant/bots/services/register_service.rb', line 6

def initialize(email, password, name, chat_id)
  @name = name
  @email = email
  @password = password
  @chat_id = chat_id
  @config = Config.new
  @config.db_connection
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
# File 'lib/chatgpt_assistant/bots/services/register_service.rb', line 15

def call
  return if user_already_exists?

  @user = User.new(email: @email, password: @password, telegram_id: @chat_id, name: @name)
  @user.save ? success_message : error_message
rescue UserAlreadyExistsError, WrongEmailError, WrongPasswordError => e
  telegram_async.send_message(e.message, @chat_id)
end