Handling patient medical file uploads (PDF/images) mid-conversation in a multi-step Telegram/WhatsApp triage workflow

Hi everyone,

I’m building a no-code automation for a health tourism intake and triage system, and I’d love some guidance from the community on the file-handling part of the flow.

CONTEXT / WHAT’S ALREADY WORKING:

  • Telegram Trigger receives patient text messages.
  • An AI node (Claude) analyzes the message, detects language, translates it, and returns a structured JSON triage result (suggested specialty, confidence level, missing info).
  • Airtable stores Doctors / Patients / Cases and is used to route the case to the right specialist.
  • The rest of the flow forwards the doctor’s response back to the patient, and later generates a tracking code and sends the full case to an external system via a webhook.

WHAT I NOW NEED HELP WITH:
I want to extend the intake step so patients can upload their medical records and test results (PDF and images) directly in the same Telegram/WhatsApp conversation, not through a separate form, so the whole triage conversation stays in one continuous chat thread.

Specifically I’m looking for advice on:

  1. Best practice for capturing both document and photo message types from Telegram Trigger in a single branch (rather than building separate paths for message.document vs message.photo).

  2. Recommended approach for downloading the file (Telegram file_id) inside n8n and passing it to an OCR or vision-capable AI step for text extraction — should this go through a dedicated OCR node, or is feeding the image/PDF directly to a vision-capable LLM node more reliable for medical documents?

  3. How others handle mixing multiple input types (free text + file attachments) within the same conversation turn before sending everything to the AI analysis node as one combined payload.

  4. Any guidance on temporarily storing the uploaded files (e.g., binary data handling, or pushing to cloud storage) before they’re attached to the patient’s case record in Airtable.

  5. Since this involves sensitive personal health data, any recommended patterns for handling encryption/retention of uploaded files within an n8n workflow would be very helpful.

I’m running this on n8n.cloud. Happy to share more details about the workflow structure if useful. Any pointers, example workflows, or node recommendations would be greatly appreciated.

Thanks in advance!

Hey @Hossein_Nikounam, while you wait for a response, here are some things that might help:

Suggested resources

Automatically matched to your question.

Docs:

Forum:

@withabdul, @mohamed3nan, @fahmiiireza - you’ve helped with similar issues before, can you take a look?

Automatically suggested by n8n’s community bot. It’s a pilot - please share feedback here.

  1. Telegram sends these as separate fields (message.document vs message.photo), so use an expression right after the trigger to normalize them into one value before branching further: {{ $json.message.document?.file_id || $json.message.photo?.[$json.message.photo.length - 1]?.file_id }} (photos come as an array of sizes, grab the last/largest). Feed that single file_id into one Telegram “Get File” node regardless of type.
  2. OCR vs vision LLM: For medical docs, I’d lean toward feeding directly to a vision-capable LLM rather than a dedicated OCR node, OCR alone gives you raw text but loses layout/structure (lab value tables, form fields), and a vision model can reason about that structure directly. Dedicated OCR is worth adding only if you hit cost or reliability issues at volume, or need guaranteed-deterministic text extraction for a downstream rule-based step.
  1. Mixing text + files in one turn: Don’t try to force everything into a single AI call per Telegram message. Keep a per-case buffer (a Data Table row or Airtable “Case” record keyed by chat_id) that accumulates text and file references as they arrive, and only fire the AI analysis node once triggered explicitly (e.g., patient sends “done” / a timeout / a fixed number of expected inputs).
    1. Temp storage: n8n’s binary data only lives for the duration of a single execution, it doesn’t persist across separate trigger events in a conversation. Download via Get File, then immediately push to actual cloud storage (S3/GCS/Azure Blob) and store just the URL/reference in your Airtable case record, don’t try to hold binary data in n8n itself between turns.
1 Like
  1. Encryption/retention for PHI: This is the one I’d flag as bigger than a workflow-design question, you’re handling health data over Telegram/WhatsApp, which raises real HIPAA/GDPR-adjacent compliance questions (data processing agreements, retention limits, whether Telegram/WhatsApp’s own terms even permit PHI transmission) that are legal/compliance decisions, not n8n config. Technically: enable server-side encryption on your storage bucket, set explicit lifecycle/retention policies there, and check n8n’s log settings so binary data/PII isn’t retained in execution logs longer than needed. I’d genuinely get a compliance advisor involved before this goes to real patients, not just secure the pipes.
1 Like

Hi @Hossein_Nikounam Welcome!

Three practical things that bite specifically with medical documents over Telegram.

Bot downloads are capped at 20MB by getFile. Scanned records and multi page PDFs go over that more often than you’d think, and there’s nothing you can do about it from the n8n side. Worth deciding up front whether you tell patients the limit or give them a fallback upload link for anything bigger.

If a patient sends a lab report as a photo, Telegram recompresses it and small print in tables gets mangled. Even the largest entry in message.photo is compressed. For anything with numbers on it you want them sending it as a file instead, which arrives as message.document untouched. That one probably matters more for your vision model accuracy than which model you pick.

And if someone sends several images at once, Telegram delivers them as separate updates sharing a media_group_id, so you get one execution per image rather than one for the batch. Another reason for the buffer sergeys mentioned, and keying on media_group_id lets you stitch them back together.

This is a solvable pattern — here’s how I’d approach the file-handling piece.

**Receiving binary files from Telegram mid-conversation**

When a patient sends a document or photo to your Telegram bot, the trigger fires with a `document` or `photo` object containing a `file_id`. You need a two-step extraction:

1. **Get file path:** HTTP Request node → `GET https://api.telegram.org/bot{TOKEN}/getFile?file_id={file_id}` → returns `result.file_path`

2. **Download the file:** HTTP Request node → `GET https://api.telegram.org/file/bot{TOKEN}/{file_path}` → set response format to **File** (binary)

After step 2 you have a binary item in n8n that you can pipe directly into Google Drive or convert for Airtable.

**Storing the file**

- **Google Drive:** Use the Drive node → Upload, pass the binary. You get back a file ID you can store in your session memory or Airtable record.

- **Airtable attachment:** Airtable expects an array of `{url: “…”}` objects in attachment fields. Upload to Drive first (or any public-accessible storage), then pass the URL to Airtable. You can’t push raw binary directly into Airtable attachments.

**Keeping conversation state across messages**

Since each Telegram message triggers a fresh workflow run, you need external state. The common pattern:

- Use Airtable or a simple key-value (Redis, even a Google Sheet) keyed by `chat_id`

- On each trigger, look up the existing record for that `chat_id`, merge the new file reference in, update the record

- Your LLM/triage step reads the full record (including all file references) before deciding next action

**HIPAA note:** If this is for real patient data, n8n.cloud stores workflow data on their infrastructure. Worth checking whether that aligns with your compliance requirements — self-hosted n8n gives you full data locality control.

Happy to go deeper on any of these steps.

The mechanics above are right, so this is only the part that changes because the files are medical records.

The Telegram download URL carries your bot token in the path: api.telegram.org/file/bot/<file_path>. Anyone holding that URL holds the token, and the token is full control of the bot. So storing that URL, or handing it to Airtable as an attachment source, sends your bot token to a third party and into whatever logs and backups it keeps. Download the file inside n8n, upload the bytes to your own storage, and let the Telegram URL expire with the execution.

The same reasoning one step on. An attachment URL that opens without a login is a copy of the document rather than a pointer to it. For patient records the pattern that survives review is private object storage with a signed URL generated at view time and a short expiry, so access becomes an event you can log and revoke.

One Cloud detail that is easy to miss: your executions are a second copy of everything. Binary references, extracted text and the AI node input all sit in execution data, so the executions list becomes a store of patient documents. In workflow Settings, save nothing for successful production executions and keep error executions only as long as you actually need them.

On the compliance point sergeys raised, agreed it is the bigger item. Worth checking early whether Telegram and WhatsApp Business terms permit this data category in your jurisdiction, because that answer can change the intake channel, and changing it now is cheaper than after the first real patient.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.