This guide explains how to handle both plain text inputs and structured JSON payloads (from Adaptive Cards) within a single interaction node in Microsoft Teams.
The Problem
When using MSTeams Adaptive Cards (such as dropdowns or radio buttons), the Submit action sends data as a JSON object (for example, {“choice”: “value”}) to the bot.
- String Entities: These expect plain text. When they receive stringified JSON from MSTeams, they fail to process it and trigger errors like: “I’m sorry, I am unable to recognize the string. Please enter again.”
- Composite Entities: While well-suited for JSON inputs, they can restrict users from entering simple, unstructured text within the same node.
Recommended Solutions
1. Multi-Channel Branching Design (Best Practice)
The most reliable approach is to branch your dialog flow based on the channel. This allows each input type to be handled appropriately.
Implementation:
- Add a Logic/Split Node before the entity node.
- Evaluate the context variable: context.channel.type.
- If MSTeams: Route to a Composite Entity configured to parse JSON fields.
- If Web/Other channels: Route to a String Entity to handle plain text input.
2. Composite Entity with Flexible (“Unstructured”) Patterns
If maintaining a single node is important, a Composite Entity can be configured to accept both structured and unstructured inputs.
How it works:
If no NLP patterns match, the Composite Entity can still accept raw JSON without processing it through NLP.
Implementation:
- Define sub-entities for expected fields (e.g., bookingReason).
- Add a broad or generic NLP pattern to capture free-form text.
- In downstream logic, differentiate input types using a script:
if (typeof context.entities.MyCompositeNode.subEntity === ‘object’) {
// Handle JSON input
} else {
// Handle plain text input
}
3. Pre-Processing with a Script Node
Another approach is to normalize the input before it reaches the Entity node.
Implementation:
- Insert a Script Node before the Entity node.
- Detect whether the incoming message is stringified JSON.
- If true, extract the relevant value (e.g., dropdown selection).
- Store the extracted value in a context variable or directly assign it to the entity.
This effectively converts complex JSON into a simple string for downstream processing.
Technical Context
In the Kore.ai platform, MSTeams Action.Submit payloads are processed by stringifying the body.value. Since body.text is typically empty for Adaptive Cards, the platform relies on the entityRefKey mechanism for handling input.