Project Overview: AI-Powered Medical Assistant Workflow
Hello n8n Community,
I’m developing an AI-powered medical assistant named Médi using n8n. The assistant interacts with users via Telegram, collects structured information, and stores it in Supabase. The workflow is designed to handle three types of structured data:
patient
praticien
rendez_vous
Each of these corresponds to a specific form filled out by the user during the interaction.
Workflow Architecture
The workflow follows this structure:
- Telegram Interaction: User engages with Médi via Telegram.
- AI Agent Processing: Médi processes the conversation and, upon gathering sufficient information, generates a structured JSON object corresponding to one of the three types mentioned above.
- IF Node: Checks if the output from the AI Agent is a complete JSON object.
- If true: Proceeds to the Switch node.
- If false: Returns to the conversation for further data collection.
- Switch Node: Determines the type of form (
patient
,praticien
, orrendez_vous
) based on theformulaire
field in the JSON. - Supabase Insertion: Inserts the structured data into the appropriate table in Supabase.
Objective of the IF Node
The IF node is intended to:
- Pass through the data if the AI Agent’s output is a complete JSON object.
- Block the data if the output is incomplete or not a JSON object (e.g., a string or null), prompting further interaction with the user.
Issue Encountered
Despite configuring the IF node to check for an object, it doesn’t behave as expected:
- When the AI Agent outputs a complete JSON object, the IF node still routes the data through the false branch.
- Attempts to check for the existence of specific fields (e.g.,
formulaire
) result in type errors, such as:
csharp
CopyEdit
Wrong type: true is a string but was expecting an object.
- Using expressions like
{{$json}}
in the IF node’s condition doesn’t resolve the issue.
Example of AI Agent’s Output
Here’s a sample JSON object generated by the AI Agent:
json
CopyEdit
{
"formulaire": "praticien",
"telegram_id": "123456789",
"nom": "Mitoni",
"prenom": "Bobo",
"specialite": "Dentiste",
"email": "[email protected]",
"telephone": "98038737793",
"adresse": "7, Paris, France",
"disponibilites": "Lundi 9h",
"piece_id_url": "https://...",
"diplome_url": "https://...",
"num_ordre_medical": "M7895"
}
Despite this structured output, the IF node doesn’t recognize it as an object.
Troubleshooting Steps Taken
- Configured the IF node to check if the data type is an object.
- Attempted to verify the existence of specific fields within the JSON.
- Used expressions like
{{$json}}
to reference the entire JSON object. - Reviewed n8n documentation and community discussions related to the IF node’s behavior.
Desired Outcome
I seek guidance on:
- Correctly configuring the IF node to detect whether the input is a complete JSON object.
- Ensuring that the IF node routes complete JSON objects through the true branch and incomplete or non-object data through the false branch.
- Alternative approaches or best practices within n8n to achieve this conditional logic.
Request for Assistance
Any insights, suggestions, or examples from the community would be immensely helpful. If needed, I can provide the current workflow’s JSON export for a more in-depth review.
Thank you in advance for your support!