def add_user( email: str, password: str, first_name: str, last_name: str, account: int, bot: str, user: str, is_integration_user=False, role="trainer", ): Utility.is_exist( User, query={"email": email}, exp_message= "User already exists! try with different email address.", ) return (User( email=email, password=Utility.get_password_hash(password), first_name=first_name, last_name=last_name, account=account, bot=bot, user=user, is_integration_user=is_integration_user, role=role, ).save().to_mongo().to_dict())
def add_user( email: str, password: str, first_name: str, last_name: str, account: int, bot: str, user: str, is_integration_user=False, role="trainer", ): """ Adds a new user to the app based on the details provided by the user """ assert not Utility.check_empty_string(email) and not Utility.check_empty_string(last_name) and not Utility.check_empty_string(first_name) and not Utility.check_empty_string(password),"Email, FirstName, LastName and password cannot be empty or blank spaces " Utility.is_exist( User, exp_message="User already exists! try with different email address.", email__iexact=email.strip(), status=True ) return ( User( email=email.strip(), password=Utility.get_password_hash(password.strip()), first_name=first_name.strip(), last_name=last_name.strip(), account=account, bot=bot.strip(), user=user.strip(), is_integration_user=is_integration_user, role=role.strip(), ) .save() .to_mongo() .to_dict() )
def add_account(name: str, user: str): """ Adds a new account for the trainer app """ assert not Utility.check_empty_string(name), "Account Name cannot be empty or blank spaces" Utility.is_exist( Account, exp_message="Account name already exists!", name__iexact=name, status=True ) return Account(name=name.strip(), user=user).save().to_mongo().to_dict()
def add_bot(name: str, account: int, user: str): """ Adds a bot to the specified user account """ assert not Utility.check_empty_string(name), "Bot Name cannot be empty or blank spaces" Utility.is_exist( Bot, exp_message="Bot already exists!", name__iexact=name, account=account, status=True ) return Bot(name=name, account=account, user=user).save().to_mongo().to_dict()
def add_action(self, name: Text, bot: Text, user: Text): Utility.is_exist( Actions, query={ "name": name, "bot": bot }, exp_message="Entity already exists!", ) Actions(name=name, bot=bot, user=user).save()
def add_bot(name: str, account: int, user: str): Utility.is_exist( Bot, query={ "name": name, "account": account }, exp_message="Bot already exists!", ) return Bot(name=name, account=account, user=user).save().to_mongo().to_dict()
def add_intent(self, text: Text, bot: Text, user: Text): Utility.is_exist( Intents, query={ "name": text, "bot": bot }, exp_message="Intent already exists!", ) saved = Intents(name=text, bot=bot, user=user).save().to_mongo().to_dict() return saved["_id"].__str__()
def add_training_example(self, examples: List[Text], intent: Text, bot: Text, user: Text): if not Utility.is_exist( Intents, query={ "name": intent, "bot": bot }, raise_error=False): self.add_intent(intent, bot, user) for example in examples: if Utility.is_exist(TrainingExamples, query={ "text": example, "bot": bot }, raise_error=False): yield { "text": example, "message": "Training Example already exists!", "_id": None, } else: training_example = TrainingExamples(intent=intent, text=example, bot=bot, user=user) if not Utility.check_empty_string(example): entities = MarkdownReader._find_entities_in_training_example( example) if entities: ext_entity = [ent["entity"] for ent in entities] self.__save_domain_entities(ext_entity, bot=bot, user=user) self.__add_slots_from_entities(ext_entity, bot, user) training_example.text = re.sub( ent_regex, lambda m: m.groupdict()["entity_text"], example) training_example.entities = list( self.__extract_entities(entities)) try: saved = training_example.save().to_mongo().to_dict() yield { "text": example, "_id": saved["_id"].__str__(), "message": "Training Example added successfully!", } except Exception as e: yield {"text": example, "_id": None, "message": str(e)}
def add_entity(self, name: Text, bot: Text, user: Text): Utility.is_exist( Entities, query={ "name": name, "bot": bot }, exp_message="Entity already exists!", ) Entities(name=name, bot=bot, user=user).save() if not Utility.is_exist( Slots, query={ "name": name, "bot": bot }, raise_error=False): Slots(name=name, type="text", bot=bot, user=user).save()
def add_response(self, utterances: Dict, name: Text, bot: Text, user: Text): self.__check_response_existence(response=utterances, bot=bot, exp_message="Response already exists!") response = list( self.__extract_response_value(values=[utterances], key=name, bot=bot, user=user))[0] value = response.save().to_mongo().to_dict() if not Utility.is_exist( Actions, query={ "name": name, "bot": bot }, raise_error=False): Actions(name=name, bot=bot, user=user).save() return value["_id"].__str__()
def get_integration_user(bot: str, account: int): if not Utility.is_exist(User, query={ "bot": bot, "is_integration_user": True }, raise_error=False): email = bot + "@integration.com" password = Utility.generate_password() return AccountProcessor.add_user(email=email, password=password, first_name=bot, last_name=bot, account=account, bot=bot, user="******", is_integration_user=True) else: return User.objects(bot=bot).get( is_integration_user=True).to_mongo().to_dict()
def get_integration_user(bot: str, account: int): """ Getting the integration user. If it does'nt exist, a new integration user is created """ if not Utility.is_exist( User, raise_error=False, bot=bot, is_integration_user=True, status=True ): email = bot + "@integration.com" password = Utility.generate_password() return AccountProcessor.add_user( email=email, password=password, first_name=bot, last_name=bot, account=account, bot=bot, user="******", is_integration_user=True, ) else: return ( User.objects(bot=bot).get(is_integration_user=True).to_mongo().to_dict() )
def add_account(name: str, user: str): Utility.is_exist(Account, query={"name": name}, exp_message="Account name already exists!") return Account(name=name, user=user).save().to_mongo().to_dict()