async def run():
    stream_id_1 = "lRwCZlDbxWLd2BDP-1D_8n___o0f4ZkEdA"
    stream_id_2 = "12lruitZ3cecVY1_SKgKB3___omJ6uHodA"

    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        message_service = bdk.messages()

        await message_service.send_message(stream_id_1, "<messageML>Hello, World!</messageML>")

        with open("/path/to/attachment1", "rb") as file1, \
                open("/path/to/attachment2", "rb") as file2:
            await message_service.blast_message(
                [stream_id_1, stream_id_2],
                "<messageML>Hello, World!</messageML>",
                attachment=[file1, file2]
            )

        logging.info("Obo example:")
        obo_auth_session = bdk.obo(username="******")
        async with bdk.obo_services(obo_auth_session) as obo_services:
            # Message ID can be retrieved by following guide here:
            # https://docs.developers.symphony.com/building-bots-on-symphony/datafeed/overview-of-streams
            await obo_services.messages().suppress_message("URL-Safe MessageID")
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        signal_service = bdk.signals()

        logging.info('Creating new signal.')
        signal = await signal_service.create_signal(
            BaseSignal(name="Testing signal",
                       query="HASHTAG:hashtag",
                       visible_on_profile=False,
                       company_wide=False))
        logging.info(signal)

        logging.info(await signal_service.get_signal(signal.id))

        logging.info('Add a subscriber to the signal.')
        await signal_service.subscribe_users_to_signal(signal.id, True,
                                                       [13056700580913])

        logging.info('Unsubscribe added user to the signal.')
        await signal_service.unsubscribe_users_to_signal(
            signal.id, [13056700580913])

        logging.info("Listing all signals")
        async for s in await signal_service.list_all_signals():
            logging.debug(s)

        logging.info("List all subscribers")
        async for s in await signal_service.list_all_subscribers(signal.id):
            logging.debug(s)

        logging.info(await signal_service.delete_signal(signal.id))
async def run():
    # One can retrieve the stream id (aka conversation id) following the guide here:
    # https://docs.developers.symphony.com/building-bots-on-symphony/datafeed/overview-of-streams
    stream_id = "ubaSiuUsc_j-_lVQ8vhAz3___opSJdJZdA"

    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        streams = bdk.streams()

        await streams.create_im_or_mim(
            [13056700579872, 13056700579891, 13056700579850])
        await streams.create_room(
            V3RoomAttributes(name="New fancy room", description="test room"))

        logging.debug(await streams.get_stream(stream_id))
        await streams.add_member_to_room(13056700579859, stream_id)
        await streams.remove_member_from_room(13056700579859, stream_id)

        async for m in await streams.list_all_streams_members(stream_id):
            logging.debug(m)

        stream_filter = StreamFilter(stream_types=[
            StreamType(type="IM"),
            StreamType(type="MIM"),
            StreamType(type="ROOM")
        ],
                                     include_inactive_streams=False)
        async for s in await streams.list_all_streams(stream_filter):
            logging.debug(s)
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        datafeed_loop = bdk.datafeed()
        datafeed_loop.subscribe(RealTimeEventListenerImpl())
        await datafeed_loop.start()
Пример #5
0
async def run(hz_client):
    async with SymphonyBdk(
            BdkConfigLoader.load_from_symphony_dir(
                "config_reader.yaml")) as bdk:
        datafeed = bdk.datafeed()
        datafeed.subscribe(EventListener(bdk.messages(), hz_client))
        logging.debug("Starting datafeed")
        await datafeed.start()
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        connection_service = bdk.connections()
        user_connection = await connection_service.list_connections(
            status=ConnectionStatus.ALL)
        logging.info(user_connection)
Пример #7
0
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config_injector.yaml")
    async with SymphonyBdk(config) as bdk:
        stream_id = await create_test_room(bdk.streams())

        await send_messages(bdk.messages(), stream_id)
        await check_all_messages_have_been_replied_to(bdk.messages(),
                                                      config.bot.username,
                                                      stream_id)
Пример #8
0
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")
    async with SymphonyBdk(config) as bdk:
        auth_session = bdk.bot_session()
        logging.info(await auth_session.key_manager_token)
        logging.info(await auth_session.session_token)
        logging.info("Obo example:")
        obo_auth_session = bdk.obo(username="******")
        logging.info(await obo_auth_session.session_token)
Пример #9
0
async def test_invalid_app_config(invalid_app_id_config, mock_obo_session):
    async with SymphonyBdk(invalid_app_id_config) as symphony_bdk:
        with pytest.raises(BdkConfigError):
            symphony_bdk.app_authenticator()
        with pytest.raises(BdkConfigError):
            symphony_bdk.obo(username="******")
        with pytest.raises(BdkConfigError):
            symphony_bdk.obo(user_id=1234)
        with pytest.raises(BdkConfigError):
            symphony_bdk.obo_services(mock_obo_session)
Пример #10
0
async def test_obo_with_username(config):
    with patch.object(OboAuthenticatorRsa,
                      "authenticate_by_username") as mock_authenticate:
        mock_authenticate.return_value = Mock(OboAuthSession)
        username = "******"

        async with SymphonyBdk(config) as symphony_bdk:
            obo_session = symphony_bdk.obo(username=username)

            assert obo_session is not None
            mock_authenticate.assert_called_once_with(username)
Пример #11
0
async def run():
    async with SymphonyBdk(
            BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk:
        activities = bdk.activities()
        messages = bdk.messages()

        @activities.slash("/hello")
        async def on_hello(context: CommandContext):
            await messages.send_message(
                context.stream_id, "<messageML>Hello, World!</messageML>")

        await bdk.datafeed().start()
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")
    async with SymphonyBdk(config) as bdk:
        ext_app_authenticator = bdk.app_authenticator()

        app_auth = await ext_app_authenticator.authenticate_extension_app(
            "appToken")
        ta = app_auth.app_token
        ts = app_auth.symphony_token
        logging.debug("App token: %s, Symphony token: %s", ta, ts)

        logging.debug("Is token pair valid: %s", await
                      ext_app_authenticator.is_token_pair_valid(ta, ts))
Пример #13
0
async def test_obo_with_user_id_and_username(config):
    with patch.object(OboAuthenticatorRsa, "authenticate_by_username") as authenticate_by_username, \
            patch.object(OboAuthenticatorRsa, "authenticate_by_user_id") as authenticate_by_user_id:
        authenticate_by_user_id.return_value = Mock(OboAuthSession)
        user_id = 12345

        async with SymphonyBdk(config) as symphony_bdk:
            obo_session = symphony_bdk.obo(user_id=user_id,
                                           username="******")

            assert obo_session is not None
            authenticate_by_user_id.assert_called_once_with(user_id)
            authenticate_by_username.assert_not_called()
Пример #14
0
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        datafeed_loop = bdk.datafeed()
        datafeed_loop.subscribe(RealTimeEventListenerImpl())

        t = asyncio.create_task(datafeed_loop.start())  # start DF loop

        await asyncio.sleep(10)
        await datafeed_loop.stop()  # stop after 10s

        await t  # wait for DF loop to finish
Пример #15
0
async def test_bot_session(config):
    with patch("symphony.bdk.core.auth.bot_authenticator.create_signed_jwt",
               return_value="privateKey"):
        bot_authenticator = AsyncMock(BotAuthenticatorRsa)
        bot_authenticator.retrieve_session_token.return_value = "session_token"
        bot_authenticator.retrieve_key_manager_token.return_value = "km_token"
        bot_session = AuthSession(bot_authenticator)
        async with SymphonyBdk(config) as symphony_bdk:
            symphony_bdk._bot_session = bot_session
            auth_session = symphony_bdk.bot_session()
            assert auth_session is not None
            assert await auth_session.session_token == "session_token"
            assert await auth_session.key_manager_token == "km_token"
async def run():
    config = BdkConfigLoader.load_from_symphony_dir("config.yaml")

    async with SymphonyBdk(config) as bdk:
        user_service = bdk.users()

        logging.info(await user_service.list_users_by_ids([12987981103610]))

        query = UserSearchQuery(query='bot', filters=UserSearchFilter(company='Symphony'))
        async for uid in await user_service.search_all_users(query, local=False):
            logging.debug(uid)

        async for i in await user_service.list_all_user_details_by_filter(user_filter=UserFilter(status="ENABLED",
                                                                                                 role="INDIVIDUAL"),
                                                                          max_number=100):
            logging.debug(i.user_attributes.display_name)
Пример #17
0
async def run():
    async with SymphonyBdk(BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk:
        activities = bdk.activities()
        messages = bdk.messages()

        @activities.slash("/go")
        async def on_hello(context: CommandContext):
            pick_emoji = ["cat", "dromedary_camel", "dolphin", "dog", "hamster", "goat", "panda_face", "koala", "frog", "penguin"]

            previous_message: V4Message = await messages.send_message(context.stream_id, "Let the show begin!")

            for i in range(0, len(pick_emoji)):
                time.sleep(1)
                mml = "<emoji shortcode=\"{}\" /><br/><br/>Update <b>#{}</b>".format(pick_emoji[i], (i + 1))
                previous_message = await messages.update_message(previous_message.stream.stream_id, previous_message.message_id, mml)

        await bdk.datafeed().start()
Пример #18
0
async def test_non_obo_services_fail_with_obo_only(obo_only_config):
    async with SymphonyBdk(obo_only_config) as symphony_bdk:
        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.bot_session()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.messages()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.streams()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.datafeed()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.users()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.connections()
Пример #19
0
async def test_bot_invalid_config_session(invalid_username_config):
    async with SymphonyBdk(invalid_username_config) as symphony_bdk:
        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.bot_session()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.messages()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.streams()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.datafeed()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.users()

        with pytest.raises(BotNotConfiguredError):
            symphony_bdk.connections()
Пример #20
0
async def test_obo_services(config, mock_obo_session):
    async with SymphonyBdk(config) as symphony_bdk:
        async with symphony_bdk.obo_services(mock_obo_session) as obo_services:
            assert obo_services is not None
async def run():
    async with SymphonyBdk(
            BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk:
        bdk.activities().register(JoinRoomActivity(bdk.messages()))
        await bdk.datafeed().start()
async def run():
    async with SymphonyBdk(
            BdkConfigLoader.load_from_symphony_dir("config.yaml")) as bdk:
        bdk.activities().register(SlashGifCommandActivity(bdk.messages()))
        bdk.activities().register(ReplyFormReplyActivity(bdk.messages()))
        await bdk.datafeed().start()
Пример #23
0
async def test_obo_fails(config):
    with pytest.raises(AuthInitializationError):
        async with SymphonyBdk(config) as symphony_bdk:
            symphony_bdk.obo()
Пример #24
0
async def test_ext_app_authenticator_fails(config):
    config.app = BdkAuthenticationConfig()
    async with SymphonyBdk(config) as symphony_bdk:
        with pytest.raises(AuthInitializationError):
            symphony_bdk.app_authenticator()
Пример #25
0
async def test_ext_app_authenticator(obo_only_config):
    async with SymphonyBdk(obo_only_config) as symphony_bdk:
        authenticator = symphony_bdk.app_authenticator()
        assert authenticator is not None
        assert symphony_bdk.app_authenticator(
        ) == authenticator  # test same instance is always returned