> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wcr.is/llms.txt
> Use this file to discover all available pages before exploring further.

# n8n workflow automation

> Use n8n to connect WeCareRemote events — new conversations, meetings, recordings — to email, Slack, NocoDB, and hundreds of other services.

[n8n](https://n8n.io) is the workflow automation layer between WeCareRemote and the rest of your operational stack. It listens for events on the platform and routes them to wherever they need to go — a NocoDB case table, a Slack channel, an NGO caseworker's inbox, a transcription service, an archive bucket. Anything that needs to happen "when something happens on WeCareRemote" is a good fit for n8n.

n8n runs as a self-hosted service alongside WeCareRemote, which means workflows execute inside your own infrastructure and no sensitive data is shipped to a third-party automation cloud.

## What n8n is used for

Common workflow patterns in WeCareRemote deployments:

* **Conversation routing** — when a refugee asks the AI assistant about a topic that needs human follow-up, post a card to the responsible NGO's Slack channel or create a NocoDB case row.
* **Meeting follow-up** — after a Jitsi recording lands in storage, trigger a transcription, summarise the result with an LLM, and email the summary to the caseworker.
* **Case lifecycle** — when a NocoDB case changes status, send the refugee an automated update through the platform and notify the assigned caseworker.
* **Blog publication** — when an `org_admin` publishes a new article in WordPress, cross-post a notification to Slack and add it to a NocoDB content calendar.
* **Scheduled syncs** — periodically pull statistics out of NocoDB into a dashboard or reporting spreadsheet.
* **Identity sync** — propagate new WeCareRemote user accounts into NocoDB so caseworker tables stay aligned with the JWT permissions on the platform.

## How n8n connects to WeCareRemote

n8n integrates with WeCareRemote in three main directions:

| Direction          | Mechanism                                                                    | Typical use                                        |
| ------------------ | ---------------------------------------------------------------------------- | -------------------------------------------------- |
| WeCareRemote → n8n | Outgoing webhooks from the platform or recordings backend                    | React to a new conversation, meeting, or recording |
| n8n → WeCareRemote | HTTP Request node calling the [AI agent API](/api/agent) with a Bearer token | Send messages, fetch threads, kick off agent runs  |
| n8n ↔ NocoDB       | n8n's built-in NocoDB node                                                   | Read and write structured case data                |

n8n itself authenticates to WeCareRemote the same way any API client does: it stores a JWT obtained from the [auth API](/api/auth) as a credential, then attaches it as an `Authorization: Bearer <token>` header on every request.

## Setting up the first workflow

This walkthrough creates a minimal workflow that listens for a WeCareRemote webhook and writes a row to NocoDB.

### Before you begin

You need:

* A running n8n instance reachable from the WeCareRemote backend
* A WeCareRemote JWT token for an `org_admin` user (see [JWT auth](/authentication/jwt-auth))
* A NocoDB table with at least the columns `thread_id`, `user_email`, `message`, `created_at`

### Steps

<Steps>
  <Step title="Create the webhook trigger">
    In n8n, add a **Webhook** node. Set the HTTP method to `POST` and copy the webhook URL — you will give this to your WeCareRemote administrator so the platform can post events to it.
  </Step>

  <Step title="Store the WeCareRemote credential">
    Open **Credentials → New** in n8n and create an **HTTP Header Auth** credential. Set the header name to `Authorization` and the value to `Bearer <your-jwt>`. Save it with a clear name like `WeCareRemote API`.
  </Step>

  <Step title="Add an HTTP Request node (optional)">
    If your workflow needs to call back into WeCareRemote — for example, to read the conversation history for the thread that triggered the webhook — add an **HTTP Request** node, point it at the [AI agent API](/api/agent), and attach the `WeCareRemote API` credential you created.
  </Step>

  <Step title="Add the NocoDB node">
    Add a **NocoDB** node and configure its credentials with your NocoDB API token and base URL (see [NocoDB integration](/integrations/nocodb)). Choose the **Create** operation and map the incoming webhook fields to the columns in your NocoDB table.
  </Step>

  <Step title="Activate the workflow">
    Save and activate the workflow. New webhook events from WeCareRemote will now create rows in NocoDB.
  </Step>
</Steps>

## Example: post new conversations to Slack

```json theme={null}
{
  "nodes": [
    { "name": "Webhook", "type": "n8n-nodes-base.webhook", "parameters": { "path": "wcr-new-conversation", "httpMethod": "POST" } },
    { "name": "Filter org_admin", "type": "n8n-nodes-base.if", "parameters": { "conditions": { "string": [ { "value1": "={{$json[\"role\"]}}", "operation": "equal", "value2": "blog" } ] } } },
    { "name": "Slack", "type": "n8n-nodes-base.slack", "parameters": { "operation": "post", "channel": "#refugee-support", "text": "=New conversation from {{$json[\"user_email\"]}}:\n>{{$json[\"message\"]}}" } }
  ]
}
```

Replace the webhook path and Slack channel for your deployment, then import the JSON into n8n via **Workflows → Import from File**.

## Calling the AI assistant from n8n

Use n8n's **HTTP Request** node to call the [AI agent endpoint](/api/agent) directly. The minimal configuration looks like:

| Field             | Value                                                                             |
| ----------------- | --------------------------------------------------------------------------------- |
| Method            | `POST`                                                                            |
| URL               | `http://your-instance:8080/`                                                      |
| Authentication    | `HTTP Header Auth` → `WeCareRemote API` credential                                |
| Body content type | `JSON`                                                                            |
| Body              | `{ "message": "{{$json[\"prompt\"]}}", "thread_id": "{{$json[\"thread_id\"]}}" }` |

The response includes the assistant's reply and the thread ID — pipe both into the next node in your workflow.

## Security and credentials

* **Store the JWT as a credential**, not in plain text inside a node. n8n encrypts credentials at rest.
* **Use a dedicated service account** with the minimum role needed (often `org_admin` is required to read recordings; for read-only conversation tasks, a `blog` account may be enough).
* **Rotate the token** if it leaks. Tokens expire on their own schedule, but you can invalidate a compromised account through your WeCareRemote administrator.
* **Protect inbound webhook URLs.** Treat the webhook path as a secret — anyone who knows it can trigger your workflow.

## Troubleshooting

<AccordionGroup>
  <Accordion title="The webhook is not firing">
    Check that the workflow is **activated**, not just saved. n8n only listens on a webhook URL when the workflow is active. Also confirm the WeCareRemote backend can reach your n8n instance — if n8n is on a private network, the platform needs network access to it.
  </Accordion>

  <Accordion title="API calls return 401 Unauthorized">
    Your JWT has expired or the credential is misconfigured. Generate a fresh token from the [auth API](/api/auth) and update the credential.
  </Accordion>

  <Accordion title="NocoDB rows are created but fields are empty">
    Open the NocoDB node and check the field mappings. Use the **Execute Node** button to inspect the actual incoming payload — webhook field names sometimes differ from what you expect.
  </Accordion>

  <Accordion title="Workflow runs but downstream service rejects the data">
    Add a **Set** node before the downstream service to coerce types (numbers, dates, booleans). NocoDB and Slack are picky about field types.
  </Accordion>
</AccordionGroup>

## Where to go next

<CardGroup cols={2}>
  <Card title="NocoDB integration" icon="table" href="/integrations/nocodb">
    Learn how to model case and content data in NocoDB and read it from n8n or the AI assistant.
  </Card>

  <Card title="AI agent API" icon="robot" href="/api/agent">
    Full reference for calling the AI assistant from n8n or any other client.
  </Card>
</CardGroup>
