Exemplo n.º 1
0
    async def test_not_send_not_send_typing_indicator_when_bot_running_as_skill(
            self):
        async def aux(context):
            await asyncio.sleep(1)
            await context.send_activity(f"echo:{context.activity.text}")

        skill_adapter = SkillTestAdapter(aux)
        skill_adapter.use(ShowTypingMiddleware(0.001, 1))

        step1 = await skill_adapter.send("foo")
        await step1.assert_reply("echo:foo")
Exemplo n.º 2
0
    async def test_should_not_immediately_respond_with_message(self):
        async def aux(context):
            await asyncio.sleep(0.600)
            await context.send_activity(f"echo:{context.activity.text}")

        def assert_is_not_message(activity, description):  # pylint: disable=unused-argument
            assert activity.type != ActivityTypes.message

        adapter = TestAdapter(aux)
        adapter.use(ShowTypingMiddleware())

        step1 = await adapter.send("foo")
        await step1.assert_reply(assert_is_not_message)
Exemplo n.º 3
0
    async def test_should_automatically_send_a_typing_indicator(self):
        async def aux(context):
            await asyncio.sleep(0.600)
            await context.send_activity(f"echo:{context.activity.text}")

        def assert_is_typing(activity, description):  # pylint: disable=unused-argument
            assert activity.type == ActivityTypes.typing

        adapter = TestAdapter(aux)
        adapter.use(ShowTypingMiddleware())

        step1 = await adapter.send("foo")
        step2 = await step1.assert_reply(assert_is_typing)
        step3 = await step2.assert_reply("echo:foo")
        step4 = await step3.send("bar")
        step5 = await step4.assert_reply(assert_is_typing)
        await step5.assert_reply("echo:bar")
Exemplo n.º 4
0
    if context.activity.channel_id == "emulator":
        # Create a trace activity that contains the error object
        trace_activity = Activity(
            label="TurnError",
            name="on_turn_error Trace",
            timestamp=datetime.utcnow(),
            type=ActivityTypes.trace,
            value=f"{error}",
            value_type="https://www.botframework.com/schemas/error",
        )
        # Send a trace activity, which will be displayed in Bot Framework Emulator
        await context.send_activity(trace_activity)


ADAPTER.on_turn_error = on_error
ADAPTER.use(ShowTypingMiddleware())

# Create the Bot
BOT = MyBot()


# Listen for incoming requests on /api/messages
async def messages(req: Request) -> Response:
    # Main bot message handler.
    if "application/json" in req.headers["Content-Type"]:
        body = await req.json()
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = req.headers[