def get_channel_config(connector_type: Text, bot: Text, mask_characters=True): """ fetch particular channel config for bot :param connector_type: channel name :param bot: bot id :param mask_characters: whether to mask the security keys default is True :return: Dict """ config = Channels.objects(bot=bot, connector_type=connector_type).exclude( "user").get().to_mongo().to_dict() logger.debug(config) config.pop("timestamp") channel_params = Utility.environment['channels'][ config['connector_type']] for require_field in channel_params['required_fields']: config['config'][require_field] = Utility.decrypt_message( config['config'][require_field]) if mask_characters: config['config'][require_field] = config['config'][ require_field][:-5] + '*****' return config
def validate(self, clean=True): from kairon.shared.data.utils import DataUtility Utility.validate_channel_config(self.connector_type, self.config, ValidationError) if self.connector_type == "telegram": webhook_url = DataUtility.get_channel_endpoint({ 'bot': self.bot, 'user': self.user, 'connector_type': self.connector_type }) Utility.register_telegram_webhook(Utility.decrypt_message(self.config['access_token']), webhook_url)
def list_channel_config(bot: Text, mask_characters: bool = True): """ list channel configuration against the bot :param bot: bot id :param mask_characters: whether to mask the security keys default is True :return: List """ for channel in Channels.objects(bot=bot).exclude( "user", "timestamp", "id"): data = channel.to_mongo().to_dict() data.pop("timestamp") channel_params = Utility.environment['channels'][ data['connector_type']] for require_field in channel_params['required_fields']: data['config'][require_field] = Utility.decrypt_message( data['config'][require_field]) if mask_characters: data['config'][require_field] = data['config'][ require_field][:-5] + '*****' yield data