コード例 #1
0
ファイル: bot_lib.py プロジェクト: brainwane/zulip
 def get_config_info(self, bot_name: str, optional: bool=False) -> Dict[str, str]:
     try:
         return get_bot_config(self.user_profile)
     except ConfigError:
         if optional:
             return dict()
         raise
コード例 #2
0
 def get_config_info(self, bot_name: str, optional: bool=False) -> Dict[str, str]:
     try:
         return get_bot_config(self.user_profile)
     except ConfigError:
         if optional:
             return dict()
         raise
コード例 #3
0
ファイル: users.py プロジェクト: priyank-p/zulip
def get_service_dicts_for_bot(user_profile_id: int) -> List[Dict[str, Any]]:
    user_profile = get_user_profile_by_id(user_profile_id)
    services = get_bot_services(user_profile_id)
    service_dicts: List[Dict[str, Any]] = []
    if user_profile.bot_type == UserProfile.OUTGOING_WEBHOOK_BOT:
        service_dicts = [
            {
                "base_url": service.base_url,
                "interface": service.interface,
                "token": service.token,
            }
            for service in services
        ]
    elif user_profile.bot_type == UserProfile.EMBEDDED_BOT:
        try:
            service_dicts = [
                {
                    "config_data": get_bot_config(user_profile),
                    "service_name": services[0].name,
                }
            ]
        # A ConfigError just means that there are no config entries for user_profile.
        except ConfigError:
            pass
    return service_dicts
コード例 #4
0
ファイル: test_bots.py プロジェクト: zonasw/zulip
    def test_create_embedded_bot(self, **extras: Any) -> None:
        self.login(self.example_email('hamlet'))

        # Test to create embedded bot with correct service_name
        bot_config_info = {'key': 'value'}
        bot_info = {
            'full_name': 'Embedded test bot',
            'short_name': 'embeddedservicebot',
            'bot_type': UserProfile.EMBEDDED_BOT,
            'service_name': 'followup',
            'config_data': ujson.dumps(bot_config_info),
        }
        bot_info.update(extras)
        with self.settings(EMBEDDED_BOTS_ENABLED=False):
            result = self.client_post("/json/bots", bot_info)
            self.assert_json_error(result, 'Embedded bots are not enabled.')

        result = self.client_post("/json/bots", bot_info)
        self.assert_json_success(result)

        bot_email = "*****@*****.**"
        bot_realm = get_realm('zulip')
        bot = get_user(bot_email, bot_realm)
        services = get_bot_services(bot.id)
        service = services[0]
        bot_config = get_bot_config(bot)
        self.assertEqual(bot_config, bot_config_info)
        self.assertEqual(len(services), 1)
        self.assertEqual(service.name, "followup")
        self.assertEqual(service.user_profile, bot)

        # Test to create embedded bot with incorrect service_name
        bot_info = {
            'full_name': 'Embedded test bot',
            'short_name': 'embeddedservicebot',
            'bot_type': UserProfile.EMBEDDED_BOT,
            'service_name': 'not_existing_service',
        }
        bot_info.update(extras)
        result = self.client_post("/json/bots", bot_info)
        self.assert_json_error(result, 'Invalid embedded bot name.')

        # Test to create embedded bot with an invalid config value
        malformatted_bot_config_info = {'foo': ['bar', 'baz']}
        bot_info = {
            'full_name': 'Embedded test bot',
            'short_name': 'embeddedservicebot2',
            'bot_type': UserProfile.EMBEDDED_BOT,
            'service_name': 'followup',
            'config_data': ujson.dumps(malformatted_bot_config_info)
        }
        bot_info.update(extras)
        result = self.client_post("/json/bots", bot_info)
        self.assert_json_error(
            result, 'config_data contains a value that is not a string')
コード例 #5
0
ファイル: test_bots.py プロジェクト: joydeep1701/zulip
    def test_create_embedded_bot(self, **extras: Any) -> None:
        self.login(self.example_email('hamlet'))

        # Test to create embedded bot with correct service_name
        bot_config_info = {'key': 'value'}
        bot_info = {
            'full_name': 'Embedded test bot',
            'short_name': 'embeddedservicebot',
            'bot_type': UserProfile.EMBEDDED_BOT,
            'service_name': 'followup',
            'config_data': ujson.dumps(bot_config_info),
        }
        bot_info.update(extras)
        with self.settings(EMBEDDED_BOTS_ENABLED=False):
            result = self.client_post("/json/bots", bot_info)
            self.assert_json_error(result, 'Embedded bots are not enabled.')

        result = self.client_post("/json/bots", bot_info)
        self.assert_json_success(result)

        bot_email = "*****@*****.**"
        bot_realm = get_realm('zulip')
        bot = get_user(bot_email, bot_realm)
        services = get_bot_services(bot.id)
        service = services[0]
        bot_config = get_bot_config(bot)
        self.assertEqual(bot_config, bot_config_info)
        self.assertEqual(len(services), 1)
        self.assertEqual(service.name, "followup")
        self.assertEqual(service.user_profile, bot)

        # Test to create embedded bot with incorrect service_name
        bot_info = {
            'full_name': 'Embedded test bot',
            'short_name': 'embeddedservicebot',
            'bot_type': UserProfile.EMBEDDED_BOT,
            'service_name': 'not_existing_service',
        }
        bot_info.update(extras)
        result = self.client_post("/json/bots", bot_info)
        self.assert_json_error(result, 'Invalid embedded bot name.')

        # Test to create embedded bot with an invalid config value
        malformatted_bot_config_info = {'foo': ['bar', 'baz']}
        bot_info = {
            'full_name': 'Embedded test bot',
            'short_name': 'embeddedservicebot2',
            'bot_type': UserProfile.EMBEDDED_BOT,
            'service_name': 'followup',
            'config_data': ujson.dumps(malformatted_bot_config_info)
        }
        bot_info.update(extras)
        result = self.client_post("/json/bots", bot_info)
        self.assert_json_error(result, 'config_data contains a value that is not a string')
コード例 #6
0
ファイル: users.py プロジェクト: priyank-p/zulip
def do_update_bot_config_data(bot_profile: UserProfile, config_data: Dict[str, str]) -> None:
    for key, value in config_data.items():
        set_bot_config(bot_profile, key, value)
    updated_config_data = get_bot_config(bot_profile)
    send_event(
        bot_profile.realm,
        dict(
            type="realm_bot",
            op="update",
            bot=dict(
                user_id=bot_profile.id,
                services=[dict(config_data=updated_config_data)],
            ),
        ),
        bot_owner_user_ids(bot_profile),
    )
コード例 #7
0
 def test_create_embedded_bot(self, **extras: Any) -> None:
     bot_config_info = {'key': 'value'}
     self.create_test_bot(short_name='embeddedservicebot',
                          user_profile=self.example_user("hamlet"),
                          bot_type=UserProfile.EMBEDDED_BOT,
                          service_name='followup',
                          config_data=ujson.dumps(bot_config_info),
                          **extras)
     bot_email = "*****@*****.**"
     bot_realm = get_realm('zulip')
     bot = get_user(bot_email, bot_realm)
     services = get_bot_services(bot.id)
     service = services[0]
     bot_config = get_bot_config(bot)
     self.assertEqual(bot_config, bot_config_info)
     self.assertEqual(len(services), 1)
     self.assertEqual(service.name, "followup")
     self.assertEqual(service.user_profile, bot)
コード例 #8
0
 def get_config_info(self) -> Dict[Text, Text]:
     return get_bot_config(self.user_profile)
コード例 #9
0
ファイル: bot_lib.py プロジェクト: sonu96/zulip
 def get_config_info(self):
     # type: () -> Dict[Text, Text]
     return get_bot_config(self.user_profile)