diff --git a/zerver/lib/users.py b/zerver/lib/users.py index c261bbabee..24c11d288b 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -47,19 +47,21 @@ def check_short_name(short_name_raw: str) -> str: raise JsonableError(_("Bad name or username")) return short_name -def check_valid_bot_config(service_name: str, config_data: Dict[str, str]) -> None: - try: - from zerver.lib.bot_lib import get_bot_handler - bot_handler = get_bot_handler(service_name) - if hasattr(bot_handler, 'validate_config'): - bot_handler.validate_config(config_data) - except ConfigValidationError: - # The exception provides a specific error message, but that - # message is not tagged translatable, because it is - # triggered in the external zulip_bots package. - # TODO: Think of some clever way to provide a more specific - # error message. - raise JsonableError(_("Invalid configuration data!")) +def check_valid_bot_config(bot_type: int, service_name: str, + config_data: Dict[str, str]) -> None: + if bot_type == UserProfile.EMBEDDED_BOT: + try: + from zerver.lib.bot_lib import get_bot_handler + bot_handler = get_bot_handler(service_name) + if hasattr(bot_handler, 'validate_config'): + bot_handler.validate_config(config_data) + except ConfigValidationError: + # The exception provides a specific error message, but that + # message is not tagged translatable, because it is + # triggered in the external zulip_bots package. + # TODO: Think of some clever way to provide a more specific + # error message. + raise JsonableError(_("Invalid configuration data!")) # Adds an outgoing webhook or embedded bot service. def add_service(name: str, user_profile: UserProfile, base_url: Optional[str]=None, diff --git a/zerver/views/users.py b/zerver/views/users.py index e0c0ab7738..1a0f38c6e7 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -321,7 +321,7 @@ def add_bot_backend( user_profile, default_events_register_stream_name) if bot_type == UserProfile.EMBEDDED_BOT: - check_valid_bot_config(service_name, config_data) + check_valid_bot_config(bot_type, service_name, config_data) bot_profile = do_create_user(email=email, password='', realm=user_profile.realm, full_name=full_name,