feat: enhance n8n workflows with dynamic credential management and email configuration
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
WORKFLOW_TEMPLATE="${N8N_WORKFLOW_TEMPLATE:-/opt/mc-cars/workflows/01-qualification-payment-email.json}"
|
||||
WORKFLOW_RENDERED="/tmp/01-qualification-payment-email.rendered.json"
|
||||
CREDENTIALS_FILE="/tmp/mc-cars-credentials.json"
|
||||
|
||||
required_var() {
|
||||
var_name="$1"
|
||||
eval "var_value=\${$var_name:-}"
|
||||
if [ -z "$var_value" ]; then
|
||||
echo "[n8n-bootstrap] Missing required env var: $var_name" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
escape_sed() {
|
||||
printf '%s' "$1" | sed -e 's/[\/&]/\\&/g'
|
||||
}
|
||||
|
||||
required_var N8N_POSTGRES_CREDENTIAL_ID
|
||||
required_var N8N_POSTGRES_CREDENTIAL_NAME
|
||||
required_var N8N_SMTP_CREDENTIAL_ID
|
||||
required_var N8N_SMTP_CREDENTIAL_NAME
|
||||
required_var N8N_SMTP_HOST
|
||||
required_var N8N_SMTP_USER
|
||||
required_var N8N_SMTP_PASS
|
||||
required_var N8N_PAYPAL_KAUTION_LINK
|
||||
required_var N8N_PAYPAL_MIETE_LINK
|
||||
required_var DB_POSTGRESDB_PASSWORD
|
||||
required_var N8N_PAYMENT_WORKFLOW_ID
|
||||
|
||||
cat > "$CREDENTIALS_FILE" <<EOF
|
||||
[
|
||||
{
|
||||
"id": "${N8N_POSTGRES_CREDENTIAL_ID}",
|
||||
"name": "${N8N_POSTGRES_CREDENTIAL_NAME}",
|
||||
"type": "postgres",
|
||||
"data": {
|
||||
"host": "db",
|
||||
"password": "${DB_POSTGRESDB_PASSWORD}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "${N8N_SMTP_CREDENTIAL_ID}",
|
||||
"name": "${N8N_SMTP_CREDENTIAL_NAME}",
|
||||
"type": "smtp",
|
||||
"data": {
|
||||
"host": "${N8N_SMTP_HOST}",
|
||||
"user": "${N8N_SMTP_USER}",
|
||||
"password": "${N8N_SMTP_PASS}"
|
||||
}
|
||||
}
|
||||
]
|
||||
EOF
|
||||
|
||||
if [ ! -f "$WORKFLOW_TEMPLATE" ]; then
|
||||
echo "[n8n-bootstrap] Workflow template not found: $WORKFLOW_TEMPLATE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
POSTGRES_ID_ESCAPED="$(escape_sed "$N8N_POSTGRES_CREDENTIAL_ID")"
|
||||
SMTP_ID_ESCAPED="$(escape_sed "$N8N_SMTP_CREDENTIAL_ID")"
|
||||
KAUTION_LINK_ESCAPED="$(escape_sed "$N8N_PAYPAL_KAUTION_LINK")"
|
||||
MIETE_LINK_ESCAPED="$(escape_sed "$N8N_PAYPAL_MIETE_LINK")"
|
||||
|
||||
sed \
|
||||
-e "s/__POSTGRES_CREDENTIAL_ID__/${POSTGRES_ID_ESCAPED}/g" \
|
||||
-e "s/__SMTP_CREDENTIAL_ID__/${SMTP_ID_ESCAPED}/g" \
|
||||
-e "s|__PAYPAL_KAUTION_LINK__|${KAUTION_LINK_ESCAPED}|g" \
|
||||
-e "s|__PAYPAL_MIETE_LINK__|${MIETE_LINK_ESCAPED}|g" \
|
||||
"$WORKFLOW_TEMPLATE" > "$WORKFLOW_RENDERED"
|
||||
|
||||
echo "[n8n-bootstrap] Importing credentials"
|
||||
n8n import:credentials --input="$CREDENTIALS_FILE"
|
||||
|
||||
echo "[n8n-bootstrap] Importing workflow"
|
||||
n8n import:workflow --input="$WORKFLOW_RENDERED"
|
||||
|
||||
echo "[n8n-bootstrap] Activating workflow ${N8N_PAYMENT_WORKFLOW_ID}"
|
||||
n8n update:workflow --id="${N8N_PAYMENT_WORKFLOW_ID}" --active=true
|
||||
|
||||
echo "[n8n-bootstrap] Bootstrap complete"
|
||||
File diff suppressed because one or more lines are too long
+22
-22
@@ -30,36 +30,36 @@ This folder contains exportable n8n workflow definitions for the MC Cars qualifi
|
||||
|
||||
## Setup Instructions
|
||||
|
||||
### 1. Create Postgres credential in n8n
|
||||
- **Name:** `MC Cars Postgres`
|
||||
- **Host:** `db`
|
||||
- **Port:** `5432`
|
||||
- **Database:** `postgres`
|
||||
- **User:** `postgres`
|
||||
- **Password:** (value of `POSTGRES_PASSWORD` from `.env`)
|
||||
### 1. Configure `.env`
|
||||
The stack now bootstraps n8n credentials/workflow automatically on every `docker compose up`.
|
||||
|
||||
### 2. Create SMTP credential in n8n
|
||||
- **Name:** `MC Cars SMTP`
|
||||
- **Host:** `heracles.mxrouting.net`
|
||||
- **Port:** `587` (STARTTLS) or `465` (SSL/TLS)
|
||||
- **User:** `office@mc-cars.at`
|
||||
- **Password:** use the mailbox password provided out-of-band (do not commit secrets to git)
|
||||
- **From:** `office@mc-cars.at`
|
||||
Required env variables:
|
||||
- `POSTGRES_PASSWORD`
|
||||
- `N8N_POSTGRES_CREDENTIAL_ID`
|
||||
- `N8N_POSTGRES_CREDENTIAL_NAME`
|
||||
- `N8N_SMTP_CREDENTIAL_ID`
|
||||
- `N8N_SMTP_CREDENTIAL_NAME`
|
||||
- `N8N_SMTP_HOST`
|
||||
- `N8N_SMTP_USER`
|
||||
- `N8N_SMTP_PASS`
|
||||
- `N8N_PAYPAL_KAUTION_LINK`
|
||||
- `N8N_PAYPAL_MIETE_LINK`
|
||||
- `N8N_PAYMENT_WORKFLOW_ID`
|
||||
|
||||
### 3. Mailbox reference (for future incoming-email workflows)
|
||||
### 2. Mailbox reference (for future incoming-email workflows)
|
||||
- **IMAP host:** `heracles.mxrouting.net` (port `993`, SSL/TLS)
|
||||
- **POP3 host:** `heracles.mxrouting.net` (port `995`, SSL/TLS)
|
||||
- **Username:** `office@mc-cars.at`
|
||||
- **Password:** same mailbox password as SMTP
|
||||
|
||||
### 4. Import workflows
|
||||
1. Open n8n at http://localhost:55590
|
||||
2. Go to **Workflows** → **Import from file**
|
||||
3. Import `01-qualification-payment-email.json`
|
||||
4. Import `02-mietvertrag-pdf-email.json`
|
||||
5. Open each workflow → assign the credentials created above → **Activate**
|
||||
### 3. Import behavior
|
||||
On startup, n8n runs `/opt/mc-cars/bootstrap/bootstrap-n8n.sh` which:
|
||||
1. Creates/updates Postgres and SMTP credentials from `.env`
|
||||
2. Renders `01-qualification-payment-email.json` placeholders
|
||||
3. Imports the workflow so nodes are always linked to the expected credential IDs
|
||||
4. Activates the payment workflow automatically (`n8n update:workflow --active=true`)
|
||||
|
||||
### 5. Upload Mietvertrag template (optional)
|
||||
### 4. Upload Mietvertrag template (optional)
|
||||
1. Open Admin panel → **Einstellungen** tab
|
||||
2. Upload a DOCX file in the "Mietvertrag-Vorlage" section
|
||||
3. The template should contain these placeholders:
|
||||
|
||||
Reference in New Issue
Block a user