AutomationFlowsAI & RAG › W the Usual

W the Usual

W_THE_USUAL. Uses postgres, httpRequest. Webhook trigger; 6 nodes.

Webhook trigger★★★★☆ complexity6 nodesPostgresHTTP Request
AI & RAG Trigger: Webhook Nodes: 6 Complexity: ★★★★☆ Added:

This workflow follows the HTTP Request → Postgres recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "name": "W_THE_USUAL",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "webhook/predict-order",
        "options": {}
      },
      "name": "User Opens Menu",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT oi.label, count(*) as freq \nFROM orders o \nJOIN order_items oi ON o.order_id = oi.order_id \nWHERE o.\"customer_userId\" = $1 \nAND o.tenant_id = $2 \nAND EXTRACT(HOUR FROM o.created_at) BETWEEN EXTRACT(HOUR FROM NOW()) - 4 AND EXTRACT(HOUR FROM NOW()) + 4 \nGROUP BY oi.label \nORDER BY freq DESC \nLIMIT 1;",
        "additionalFields": {
          "queryParams": "={{ [$json.body.user_id, $json.body.tenant_id] }}"
        }
      },
      "name": "Predict Favorite",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        300,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $items('Predict Favorite').length > 0 && $json.freq > 2 }}",
              "value2": true
            }
          ]
        }
      },
      "name": "Has Usual?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const fav = $('Predict Favorite').item.json;\nreturn { json: { \n  text: `Comme d'habitude ? \ud83c\udf54\\n(${fav.label})`,\n  buttons: [\n    { type: 'reply', reply: { id: 'ORDER_USUAL', title: 'Oui, envoyer !' } },\n    { type: 'reply', reply: { id: 'SHOW_MENU', title: 'Non, voir menu' } }\n  ]\n} };"
      },
      "name": "Format Magic Button",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        700,
        200
      ]
    },
    {
      "parameters": {
        "jsCode": "return { json: { \n  text: `Bienvenue chez Ralph\u00e9 ! \ud83c\udf54`,\n  buttons: [\n    { type: 'reply', reply: { id: 'SHOW_MENU', title: 'Voir la carte' } }\n  ]\n} };"
      },
      "name": "Format Standard",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        700,
        400
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ 'https://graph.facebook.com/' + ($json.system_config?.graph_api_version || $env.GRAPH_API_VERSION || 'v21.0') + '/' + ($json.system_config?.whatsapp_phone_number_id || $env.WA_PHONE_NUMBER_ID) + '/messages' }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer {{ $json.system_config?.whatsapp_access_token || $env.WA_API_TOKEN }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "bodyParameters": {
          "parameters": [
            {
              "name": "messaging_product",
              "value": "whatsapp"
            },
            {
              "name": "to",
              "value": "={{ $('User Opens Menu').item.json.body.user_id }}"
            },
            {
              "name": "type",
              "value": "interactive"
            },
            {
              "name": "interactive",
              "value": "={ \"type\": \"button\", \"body\": { \"text\": \"{{ $json.text }}\" }, \"action\": { \"buttons\": {{ JSON.stringify($json.buttons) }} } }"
            }
          ]
        }
      },
      "name": "Send WhatsApp Reply",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "User Opens Menu": {
      "main": [
        [
          {
            "node": "Predict Favorite",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Predict Favorite": {
      "main": [
        [
          {
            "node": "Has Usual?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Usual?": {
      "main": [
        [
          {
            "node": "Format Magic Button",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Format Standard",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Magic Button": {
      "main": [
        [
          {
            "node": "Send WhatsApp Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Standard": {
      "main": [
        [
          {
            "node": "Send WhatsApp Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

W_THE_USUAL. Uses postgres, httpRequest. Webhook trigger; 6 nodes.

Source: https://github.com/zerAda/RestaurantAgentAutomation/blob/01f7d5a305709db391c21d46709728da8382c1dd/workflows/W_THE_USUAL.json — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Jigsaw API key for image processing, I use this as a gatekeeper/second pair of eyes. LINK to their website https://jigsawstack.com/ SECOND A postgress DATABASE (I use Supabase) LlamaCloud for the pars

HTTP Request, Postgres, Stop And Error +2
AI & RAG

W1 - IN WhatsApp Adapter (Secure + Fast ACK). Uses postgres, redis, httpRequest. Webhook trigger; 50 nodes.

Postgres, Redis, HTTP Request
AI & RAG

W1 - IN WhatsApp Adapter (Secure + Fast ACK). Uses postgres, redis, httpRequest. Webhook trigger; 48 nodes.

Postgres, Redis, HTTP Request
AI & RAG

W2 - IN Instagram Adapter (Secure). Uses postgres, httpRequest. Webhook trigger; 28 nodes.

Postgres, HTTP Request
AI & RAG

W3 - IN Messenger Adapter (Secure). Uses postgres, httpRequest. Webhook trigger; 28 nodes.

Postgres, HTTP Request