Ejemplo n.º 1
0
    async def account_setup(account_setup: Dict, user: Text):
        """
        create new account

        :param account_setup: dict of account details
        :param user: user id
        :return: dict user details, user email id, confirmation mail subject, mail body
        """
        account = None
        bot = None
        user_details = None
        body = None
        subject = None
        mail_to = None
        try:
            account = AccountProcessor.add_account(
                account_setup.get("account"), user)
            bot = AccountProcessor.add_bot(account_setup.get("bot"),
                                           account["_id"], user)
            user_details = AccountProcessor.add_user(
                email=account_setup.get("email"),
                first_name=account_setup.get("first_name"),
                last_name=account_setup.get("last_name"),
                password=account_setup.get("password").get_secret_value(),
                account=account["_id"].__str__(),
                bot=bot["_id"].__str__(),
                user=user,
                role="admin",
            )
            await MongoProcessor().save_from_path(
                "template/use-cases/Hi-Hello",
                bot["_id"].__str__(),
                user="******")
            if AccountProcessor.EMAIL_ENABLED:
                token = Utility.generate_token(account_setup.get("email"))
                link = Utility.email_conf["app"]["url"] + '/verify/' + token
                body = Utility.email_conf['email']['templates'][
                    'confirmation_body'] + link
                subject = Utility.email_conf['email']['templates'][
                    'confirmation_subject']
                mail_to = account_setup.get("email")

        except Exception as e:
            if account and "_id" in account:
                Account.objects().get(id=account["_id"]).delete()
            if bot and "_id" in bot:
                Bot.objects().get(id=bot["_id"]).delete()
            raise e

        return user_details, mail_to, subject, body
Ejemplo n.º 2
0
 def update_bot(name: Text, bot: Text):
     if Utility.check_empty_string(name):
         raise AppException('Name cannot be empty')
     try:
         bot_info = Bot.objects(id=bot, status=True).get()
         bot_info.name = name
         bot_info.save()
     except DoesNotExist:
         raise AppException('Bot not found')
Ejemplo n.º 3
0
 def list_bots(account_id: int):
     for bot in Bot.objects(account=account_id, status=True):
         bot = bot.to_mongo().to_dict()
         bot.pop('account')
         bot.pop('user')
         bot.pop('timestamp')
         bot.pop('status')
         bot['_id'] = bot['_id'].__str__()
         yield bot
Ejemplo n.º 4
0
    def get_bot(id: str):
        """
        fetches bot details

        :param id: bot id
        :return: bot details
        """
        try:
            return Bot.objects().get(id=id).to_mongo().to_dict()
        except:
            raise DoesNotExist("Bot does not exists!")
Ejemplo n.º 5
0
 def delete_bot(bot: Text, user: Text):
     try:
         bot_info = Bot.objects(id=bot, status=True).get()
         bot_info.status = False
         bot_info.save()
         Utility.hard_delete_document([
             Actions, Configs, Endpoints, Entities, EntitySynonyms, Forms,
             HttpActionConfig, HttpActionLog, Intents, LookupTables,
             ModelDeployment, ModelTraining, RegexFeatures, Responses,
             Rules, SessionConfigs, Slots, Stories, TrainingDataGenerator,
             TrainingExamples, ValidationLogs
         ],
                                      bot,
                                      user=user)
     except DoesNotExist:
         raise AppException('Bot not found')
Ejemplo n.º 6
0
    def add_bot(name: str, account: int, user: str):
        """
        add a bot to account

        :param name: bot name
        :param account: account id
        :param user: user id
        :return: bot id
        """
        if Utility.check_empty_string(name):
            raise AppException("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()
Ejemplo n.º 7
0
    def add_bot(name: str,
                account: int,
                user: str,
                is_new_account: bool = False):
        """
        add a bot to account

        :param name: bot name
        :param account: account id
        :param user: user id
        :param is_new_account: True if it is a new account
        :return: bot id
        """
        if Utility.check_empty_string(name):
            raise AppException("Bot Name cannot be empty or blank spaces")

        if Utility.check_empty_string(user):
            raise AppException("user cannot be empty or blank spaces")

        Utility.is_exist(
            Bot,
            exp_message="Bot already exists!",
            name__iexact=name,
            account=account,
            status=True,
        )
        bot = Bot(name=name, account=account,
                  user=user).save().to_mongo().to_dict()
        bot_id = bot['_id'].__str__()
        if not is_new_account:
            AccountProcessor.add_bot_for_user(bot_id, user)
        BotSettings(bot=bot_id, user=user).save()
        processor = MongoProcessor()
        config = processor.load_config(bot_id)
        processor.add_or_overwrite_config(config, bot_id, user)
        processor.add_default_fallback_data(bot_id, user, True, True)
        return bot
Ejemplo n.º 8
0
 def wrapped(current_user: User, **kwargs):
     account = Account.objects().get(id=current_user.account)
     limit = account.license['bots'] if "bots" in account.license else 2
     count = Bot.objects(account=current_user.account).count()
     if count >= limit:
         raise AppException("Bot limit exhausted!")