Skip to content

Validation fails when receiving a message from Direct Line - missing conversationUpdate.channelData #239

@msarchioto

Description

@msarchioto

try:
activity = ActivityTypeAdapter.validate_python(body)
except ValidationError as e:
self.logger.error(e.errors())
raise

Hi everyone,
This is my situation: I have an Azure Function leveraging Direct Line API 3.0 that I use to call a chatbot which has Teams SDK for Python, running on an Azure App Service.

On the Function side, I authenticate and return the conversation id:

        url = "https://directline.botframework.com/v3/directline/conversations"
        headers = {
            "Authorization": f"Bearer {direct_line_secret}",
            "Content-Type": "application/json",
        }
[...]
        conversation_data = response.json()
        conversation_id = conversation_data.get("conversationId")
        return conversation_id

I get the initial activities then I send an activity to a Direct Line conversation:

# Get activities from a Direct Line conversation
    try:
        url = f"https://directline.botframework.com/v3/directline/conversations/{conversation_id}/activities"
        if watermark:
            url += f"?watermark={watermark}"

        headers = {
            "Authorization": f"Bearer {direct_line_secret}",
        }

        response = requests.get(url, headers=headers, timeout=30)
[...]
# send acvitivity
    try:
        url = f"https://directline.botframework.com/v3/directline/conversations/{conversation_id}/activities"
        headers = {
            "Authorization": f"Bearer {direct_line_secret}",
            "Content-Type": "application/json",
        }
[...]
        response = requests.post(
            url, json=activity_payload, headers=headers, timeout=30
        )

I get the activities again.

I send two payloads to test the bots (on separate POSTs):

      {
        "channelId": "directline",
        "conversation": {
          "id": "conv123"
        },
        "from": {
          "id": "user123",
          "name": "Test User"
        },
        "text": "Give me all the Orders",
        "type": "message"
      },
      {
        "channelId": "directline",
        "conversation": {
          "id": "conv123"
        },
        "from": {
          "id": "user123",
          "name": "Test User"
        },
        "text": "Give me all the Orders that are pending",
        "type": "message"
      }

When I send the first one I get this error on the App Service side which is using Teams SDK:

{
  "type": "missing",
  "loc": [
    "conversationUpdate",
    "channelData"
  ],
  "msg": "Field required",
  "input": {
    "type": "conversationUpdate",
    "id": "Bh0ETfRaC25",
    "timestamp": "2025-12-22T11:29:37.3485747Z",
    "serviceUrl": "https://directline.botframework.com/",
    "channelId": "directline",
    "from": {
      "id": "dl_aba7a98ada0ee99e7d54af5df8e00440",
      "name": "Bot Tester"
    },
[...]
    ]
  },
  "url": "https://errors.pydantic.dev/2.12/v/missing"
}

[31m[1m[ERROR] @teams/app.BotBuilderPlugin[0m[22m conversationUpdate.channelData
[31m[1m[ERROR] @teams/app.BotBuilderPlugin[0m[22m   Field required [type=missing, input_value={'type': 'conversationUpd... 'name': 'Bot Tester'}]}, input_type=dict]

It says that conversationUpdate.channelData is missing, and I get a 502 error on the function side.

The second message, funny enough, is sent and received with no errors.

From what I can see, when you start a conversation via Direct Line, the service automatically sends conversationUpdate activities to your bot before you even send your first message. You can't stop this.
Documentation

POST https://directline.botframework.com/v3/directline/tokens/generate
[...]
Direct Line can perform additional security validation of the user ID and name, inhibiting tampering of these values by malicious clients. Including these values also improves Direct Line's ability to send the conversation update activity, allowing it to generate the conversation update immediately upon the user joining the conversation. When this information isn't provided, the user must send content before Direct Line can send the conversation update

When generating a token, Direct Line generates a conversationUpdate object that I can't prevent and has no channelData. This trips the Team's framework validation because it's mandatory on the other side.
This is a mismatch in behaviour we have to patch ourselves.
For Bot's framework channelData is optional: https://learn.microsoft.com/en-us/javascript/api/botframework-schema/activity?view=botbuilder-ts-latest

channelData?: any # Optional

tl;dr: Direct Line sends a conversationUpdate with no channelData, Teams SDK wants this, I can't change the behaviour.

This wasn't happening when we used the Bot Builder framework this wasn't happening.

Do you have any ideas on how I could solve this?

Thanks in advance for the help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions