microsoft/botbuilder-python

TypeError: Object of type ExpectedReplies is not JSON serializable

Closed this issue · 3 comments

Github issues should be used for bugs and feature requests. Use Stack Overflow for general "how-to" questions.

Version

4.16.1

Describe the bug

When used as a skill in Copilot Studio, it raises an exception:

Traceback (most recent call last):
  File "lib/python3.11/site-packages/botbuilder/core/integration/aiohttp_channel_service_exception_middleware.py", line 21, in aiohttp_error_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "app.py", line 50, in messages
    return await ADAPTER.process(req, BOT)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.11/site-packages/botbuilder/integration/aiohttp/cloud_adapter.py", line 104, in process
    return json_response(
           ^^^^^^^^^^^^^^
  File "lib/python3.11/site-packages/aiohttp/web_response.py", line 811, in json_response
    text = dumps(data)
           ^^^^^^^^^^^
  File "lib/python3.11/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.11/json/encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "lib/python3.11/json/encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ExpectedReplies is not JSON serializable

To Reproduce

Steps to reproduce the behavior:

  1. Run a local instance using python app.py
  2. Use an HTTP client like RapidAPI or Postman to send the following request:
{
  "channelData": {
    "clientActivityID": "17239724318949u1bvvo56l",
    "webchat:sequence-id": 1723972432213,
    "state": "sent",
    "webchat:send-status": "sent"
  },
  "text": "Hello!",
  "textFormat": "plain",
  "type": "message",
  "channelId": "emulator",
  "from": {
    "id": "b517d36e-35c9-4f84-8bdf-f3aae6ed44f4",
    "name": "User",
    "role": "user"
  },
  "locale": "en-US",
  "localTimestamp": "2024-08-18T12:13:52+03:00",
  "localTimezone": "Europe/Rome",
  "attachments": [],
  "entities": [
    {
      "requiresBotState": true,
      "supportsListening": true,
      "supportsTts": true,
      "type": "ClientCapabilities"
    }
  ],
  "conversation": {
    "id": "2a835710-5d42-11ef-a0f8-4df1eaa60431|livechat"
  },
  "id": "2fc06f60-5d42-11ef-a0f8-4df1eaa60431",
  "recipient": {
    "id": "2a7c5230-5d42-11ef-a32f-cfef2b50c669",
    "name": "Bot",
    "role": "bot"
  },
  "timestamp": "2024-08-18T09:13:52.213Z",
  "serviceUrl": "https://....ngrok-free.app",
  "deliveryMode": "expectReplies"
}
  1. The logs will report the above stack trace.

Expected behavior

The app should work

Additional context

I am using bot as a skill in Copilot Studio.

The error happens with AdapterWithErrorHandler(CloudAdapter), it doesn't happen with BotFrameworkAdapter

Did you find any solution for this ?

Yes, use "BotFrameworkAdapter" instead of (a subclass of) "CloudAdapter".

Hope it helps