AutomationFlowsData & Sheets › Post Prayer

Post Prayer

Post-Prayer. Uses postgres, httpRequest. Webhook trigger; 44 nodes.

Webhook trigger★★★★★ complexity44 nodesPostgresHTTP Request
Data & Sheets Trigger: Webhook Nodes: 44 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
{
  "nodes": [
    {
      "parameters": {
        "content": "",
        "height": 432,
        "width": 1856,
        "color": 2
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -5216,
        9408
      ],
      "id": "6c18285e-e4d7-403c-9781-c666bbf2142d",
      "name": "Sticky Note28"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO daily_deeds (user_id, date, {{ $json.column_name }})\nVALUES ({{ $json.telegram_id }}, '{{ $json.date }}', true)\nON CONFLICT (user_id, date) \nDO UPDATE SET {{ $json.column_name }} = true, updated_at = NOW();",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -4736,
        9536
      ],
      "id": "665b73e0-b26d-4723-bc83-7963f61964af",
      "name": "Update Daily Deeds",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": {{ $('Parse Azkar Callback1').item.json.chat_id }},\n  \"message_id\": {{ $('Parse Azkar Callback1').item.json.message_id }},\n  \"text\": {{ JSON.stringify($('Parse Azkar Callback1').item.json.confirmation_message) }}\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4512,
        9536
      ],
      "id": "d1cf0630-179b-47a5-925c-2f497bcfaebb",
      "name": "Edit Azkar Message"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/answerCallbackQuery",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"callback_query_id\": \"{{ $('Parse Azkar Callback1').item.json.callback_query_id }}\",\n  \"text\": \"\u062a\u0645 \u2705\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4288,
        9536
      ],
      "id": "761370e4-26c1-46a0-8d0f-caa538eaeae4",
      "name": "Answer Callback Query"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -4064,
        9536
      ],
      "id": "145ff278-3ab9-4f36-bb8f-045a4a4fbbd2",
      "name": "Respond Success"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "azkar-callback",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -5168,
        9536
      ],
      "id": "2161df1d-4b35-47c4-839c-9ebc80bdfdb0",
      "name": "Azkar Callback Webhook1"
    },
    {
      "parameters": {
        "jsCode": "const body = $input.first().json.body.body;  // Note: body.body\n\nconst callbackData = body.callback_data;\nconst parts = callbackData.split('|');\n\n// Format: azkar|sabah|2025-01-15|telegram_id\nconst azkarType = parts[1]; // 'sabah' or 'masa'\nconst date = parts[2];\nconst telegramId = parseInt(parts[3]);\n\n// Determine which column to update\nconst columnName = azkarType === 'sabah' ? 'azkar_sabah_done' : 'azkar_masa_done';\n\n// Confirmation message based on type\nconst confirmationMessage = azkarType === 'sabah' \n  ? '\ud83c\udf05 \u0623\u0630\u0643\u0627\u0631 \u0627\u0644\u0635\u0628\u0627\u062d \u2705\\n\\n\u062a\u0645 \u0627\u0644\u062a\u0633\u062c\u064a\u0644 - \u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32'\n  : '\ud83c\udf06 \u0623\u0630\u0643\u0627\u0631 \u0627\u0644\u0645\u0633\u0627\u0621 \u2705\\n\\n\u062a\u0645 \u0627\u0644\u062a\u0633\u062c\u064a\u0644 - \u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32';\n\nreturn {\n  json: {\n    telegram_id: telegramId,\n    chat_id: body.chat_id,\n    message_id: body.message_id,\n    callback_query_id: body.callback_query_id,\n    azkar_type: azkarType,\n    date: date,\n    column_name: columnName,\n    confirmation_message: confirmationMessage\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -4944,
        9536
      ],
      "id": "c7a6be7e-fa3e-4730-a867-bb356927b489",
      "name": "Parse Azkar Callback1"
    },
    {
      "parameters": {
        "content": "# Azkar Callback Handler",
        "height": 80,
        "width": 500,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -5184,
        9424
      ],
      "id": "78161653-c89a-495d-bc50-e4b10dd47763",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "post-prayer-flow",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -5168,
        8752
      ],
      "id": "9f5398bb-a94a-48e6-af92-05e5eaf24a30",
      "name": "Post-Prayer Webhook"
    },
    {
      "parameters": {
        "jsCode": "const user = $input.first().json;\nconst inputData = $('Post-Prayer Webhook').first().json.body;\n\nconst prayer = inputData.prayer_name;\nconst telegramId = inputData.telegram_id;\nconst messageId = inputData.message_id;\nconst today = new Date().toISOString().split('T')[0];\n\n// Determine what follow-up questions to ask\nconst askMasjid = user.masjid_prayer_enabled && user.gender === 'male';\nconst askSunnah = user.sunnah_enabled && prayer !== 'Asr'; // Asr has no ratiba sunnah\n\n// Prayer Arabic names\nconst prayerArabic = {\n  'Fajr': '\u0627\u0644\u0641\u062c\u0631',\n  'Dhuhr': '\u0627\u0644\u0638\u0647\u0631',\n  'Asr': '\u0627\u0644\u0639\u0635\u0631',\n  'Maghrib': '\u0627\u0644\u0645\u063a\u0631\u0628',\n  'Isha': '\u0627\u0644\u0639\u0634\u0627\u0621'\n};\n\nreturn {\n  json: {\n    telegram_id: telegramId,\n    message_id: messageId,\n    prayer: prayer,\n    prayer_arabic: prayerArabic[prayer] || prayer,\n    date: today,\n    gender: user.gender,\n    ask_masjid: askMasjid,\n    ask_sunnah: askSunnah,\n    sunnah_enabled: user.sunnah_enabled,\n    timezone: user.timezone\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -4720,
        8752
      ],
      "id": "79cf9926-3f55-4f66-a17e-00dc3d6dc904",
      "name": "Decide Follow-up"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "ask-masjid",
              "leftValue": "={{ $json.ask_masjid }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -4512,
        8752
      ],
      "id": "759ff0f5-83c8-448e-80e8-69ac92d9945c",
      "name": "Ask Masjid?"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": {{ $json.telegram_id }},\n  \"message_id\": {{ $json.message_id }},\n  \"text\": \"\u2705 \u062a\u0645 \u062a\u0633\u062c\u064a\u0644 \u0635\u0644\u0627\u0629 {{ $json.prayer_arabic }} \u0641\u064a \u0648\u0642\u062a\u0647\u0627\\n\u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32\\n\\n\u0635\u0644\u064a\u062a\u0647\u0627 \u0641\u064a\u0646\u061f\",\n  \"reply_markup\": {\n    \"inline_keyboard\": [\n      [\n        {\n          \"text\": \"\ud83d\udd4c \u0641\u064a \u0627\u0644\u0645\u0633\u062c\u062f\",\n          \"callback_data\": \"masjid|{{ $json.prayer }}|yes|{{ $json.date }}|{{ $json.telegram_id }}|{{ $json.message_id }}\"\n        },\n        {\n          \"text\": \"\ud83c\udfe0 \u0641\u064a \u0627\u0644\u0628\u064a\u062a\",\n          \"callback_data\": \"masjid|{{ $json.prayer }}|no|{{ $json.date }}|{{ $json.telegram_id }}|{{ $json.message_id }}\"\n        }\n      ]\n    ]\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4288,
        8560
      ],
      "id": "4a68450d-111e-448a-b505-e36b41287573",
      "name": "Edit to Masjid Question"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "ask-sunnah",
              "leftValue": "={{ $json.ask_sunnah }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -4288,
        8768
      ],
      "id": "54d12cd5-0f0d-4e7d-b426-f1a1e63260e1",
      "name": "Ask Sunnah?"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, action: 'masjid_question' }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -3632,
        8496
      ],
      "id": "22d7c7cc-463f-4243-a3e0-3a9346b6d475",
      "name": "Respond Masjid"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, action: 'sunnah_question' }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -3632,
        8640
      ],
      "id": "c6e64c5f-37d7-405c-8dd6-dd8f862ebdc9",
      "name": "Respond Sunnah"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true, action: 'no_followup' }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -3632,
        8784
      ],
      "id": "e63d7481-6896-42a7-9aff-68f42f2faf2c",
      "name": "Respond No Follow-up"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT \n  telegram_id,\n  gender,\n  sunnah_enabled,\n  masjid_prayer_enabled,\n  timezone\nFROM users \nWHERE telegram_id = $1",
        "options": {
          "queryReplacement": "={{ $json.body.telegram_id }}"
        }
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -4944,
        8752
      ],
      "id": "18bfbe10-5603-4b27-a1bb-45e39d567ea2",
      "name": "Get User Settings1",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": {{ $json.telegram_id }},\n  \"message_id\": {{ $json.message_id }},\n  \"text\": \"\u2705 \u062a\u0645 \u062a\u0633\u062c\u064a\u0644 \u0635\u0644\u0627\u0629 {{ $json.prayer_arabic }} \u0641\u064a \u0648\u0642\u062a\u0647\u0627\\n\u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32\\n\\n\u0635\u0644\u064a\u062a \u0627\u0644\u0633\u0646\u0629\u061f\",\n  \"reply_markup\": {\n    \"inline_keyboard\": [\n      [\n        {\n          \"text\": \"\u2705 \u0623\u064a\u0648\u0647\",\n          \"callback_data\": \"sunnah|{{ $json.prayer }}|yes|{{ $json.date }}|{{ $json.telegram_id }}|{{ $json.message_id }}\"\n        },\n        {\n          \"text\": \"\u274c \u0644\u0627\",\n          \"callback_data\": \"sunnah|{{ $json.prayer }}|no|{{ $json.date }}|{{ $json.telegram_id }}|{{ $json.message_id }}\"\n        }\n      ]\n    ]\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4096,
        8640
      ],
      "id": "ef616555-79d1-463f-a161-2182d53ec723",
      "name": "Edit to Sunnah Question1"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "masjid-callback",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -5168,
        8960
      ],
      "id": "4b5a9d9b-71a1-4bb4-a63c-f27573ade733",
      "name": "Masjid Callback Webhook"
    },
    {
      "parameters": {
        "jsCode": "const body = $input.first().json.body.body;\n\nconst callbackData = body.callback_data;\nconst parts = callbackData.split('|');\n\n// Format: masjid|Prayer|yes/no|date|telegram_id|message_id\nconst prayer = parts[1];\nconst answer = parts[2]; // 'yes' or 'no'\nconst date = parts[3];\nconst telegramId = parseInt(parts[4]);\nconst messageId = parseInt(parts[5]);\n\n// Map prayer to masjid column\nconst masjidColumnMap = {\n  'Fajr': 'fajr_masjid',\n  'Dhuhr': 'dhuhr_masjid',\n  'Asr': 'asr_masjid',\n  'Maghrib': 'maghrib_masjid',\n  'Isha': 'isha_masjid'\n};\n\nconst columnName = masjidColumnMap[prayer];\nconst prayedInMasjid = answer === 'yes';\n\n// Prayer Arabic names\nconst prayerArabic = {\n  'Fajr': '\u0627\u0644\u0641\u062c\u0631',\n  'Dhuhr': '\u0627\u0644\u0638\u0647\u0631',\n  'Asr': '\u0627\u0644\u0639\u0635\u0631',\n  'Maghrib': '\u0627\u0644\u0645\u063a\u0631\u0628',\n  'Isha': '\u0627\u0644\u0639\u0634\u0627\u0621'\n};\n\nconst masjidText = prayedInMasjid ? '\ud83d\udd4c \u062c\u0645\u0627\u0639\u0629' : '\ud83c\udfe0 \u0645\u0646\u0641\u0631\u062f';\n\nreturn {\n  json: {\n    telegram_id: telegramId,\n    chat_id: body.chat_id,\n    message_id: messageId,\n    callback_query_id: body.callback_query_id,\n    prayer: prayer,\n    prayer_arabic: prayerArabic[prayer],\n    date: date,\n    column_name: columnName,\n    prayed_in_masjid: prayedInMasjid,\n    masjid_text: masjidText,\n    answer: answer\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -4960,
        8960
      ],
      "id": "79ee242a-b2ec-40f3-87e1-138cb7f1fb3a",
      "name": "Parse Masjid Callback"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO daily_deeds (user_id, date, {{ $json.column_name }})\nVALUES ({{ $json.telegram_id }}, '{{ $json.date }}', {{ $json.prayed_in_masjid }})\nON CONFLICT (user_id, date) \nDO UPDATE SET {{ $json.column_name }} = {{ $json.prayed_in_masjid }}, updated_at = NOW();",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -4736,
        8960
      ],
      "id": "4a19d3a8-e078-4260-987a-636c4d8faf7e",
      "name": "Update Masjid in DB",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT sunnah_enabled FROM users WHERE telegram_id = {{ $('Parse Masjid Callback').item.json.telegram_id }}",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -4512,
        8960
      ],
      "id": "e068572c-ff15-4bfc-b58e-67b481e7ecef",
      "name": "Check Sunnah Enabled",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "sunnah-enabled",
              "leftValue": "={{ $json.sunnah_enabled }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            },
            {
              "id": "not-asr",
              "leftValue": "={{ $('Parse Masjid Callback').item.json.prayer }}",
              "rightValue": "Asr",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -4288,
        8960
      ],
      "id": "713074f0-d937-43d8-905b-3ee943d55805",
      "name": "Ask Sunnah Next?"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": {{ $('Parse Masjid Callback').item.json.chat_id }},\n  \"message_id\": {{ $('Parse Masjid Callback').item.json.message_id }},\n  \"text\": \"\u2705 \u062a\u0645 \u062a\u0633\u062c\u064a\u0644 \u0635\u0644\u0627\u0629 {{ $('Parse Masjid Callback').item.json.prayer_arabic }} \u0641\u064a \u0648\u0642\u062a\u0647\u0627\\n{{ $('Parse Masjid Callback').item.json.masjid_text }} - \u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32\\n\\n\u0635\u0644\u064a\u062a \u0627\u0644\u0633\u0646\u0629\u061f\",\n  \"reply_markup\": {\n    \"inline_keyboard\": [\n      [\n        {\n          \"text\": \"\u2705 \u0623\u064a\u0648\u0647\",\n          \"callback_data\": \"sunnah|{{ $('Parse Masjid Callback').item.json.prayer }}|yes|{{ $('Parse Masjid Callback').item.json.date }}|{{ $('Parse Masjid Callback').item.json.telegram_id }}|{{ $('Parse Masjid Callback').item.json.message_id }}|{{ $('Parse Masjid Callback').item.json.masjid_text }}\"\n        },\n        {\n          \"text\": \"\u274c \u0644\u0627\",\n          \"callback_data\": \"sunnah|{{ $('Parse Masjid Callback').item.json.prayer }}|no|{{ $('Parse Masjid Callback').item.json.date }}|{{ $('Parse Masjid Callback').item.json.telegram_id }}|{{ $('Parse Masjid Callback').item.json.message_id }}|{{ $('Parse Masjid Callback').item.json.masjid_text }}\"\n        }\n      ]\n    ]\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4080,
        8880
      ],
      "id": "48e8f1b1-11cd-4543-9a8f-c002fcdad9bf",
      "name": "Edit to Sunnah Question"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": {{ $('Parse Masjid Callback').item.json.chat_id }},\n  \"message_id\": {{ $('Parse Masjid Callback').item.json.message_id }},\n  \"text\": \"\u2705 \u062a\u0645 \u062a\u0633\u062c\u064a\u0644 \u0635\u0644\u0627\u0629 {{ $('Parse Masjid Callback').item.json.prayer_arabic }} \u0641\u064a \u0648\u0642\u062a\u0647\u0627\\n{{ $('Parse Masjid Callback').item.json.masjid_text }} - \u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4080,
        9040
      ],
      "id": "e025d188-0078-4c94-85c1-b7505d22c664",
      "name": "Edit to Final Confirmation"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/answerCallbackQuery",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"callback_query_id\": \"{{ $('Parse Masjid Callback').item.json.callback_query_id }}\",\n  \"text\": \"\u062a\u0645 \u2705\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -3856,
        8960
      ],
      "id": "049fc21e-dcdc-41fd-abdb-d5ef57d8ce0a",
      "name": "Answer Callback Query1"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -3632,
        8960
      ],
      "id": "7c95b92b-a438-4fb1-a036-f8c8120742e5",
      "name": "Respond Success1"
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "sunnah-callback",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -5168,
        9184
      ],
      "id": "f2da34f1-4ed8-4f71-8469-1bb84f74776f",
      "name": "Sunnah Callback Webhook"
    },
    {
      "parameters": {
        "jsCode": "const body = $input.first().json.body.body;\n\nconst callbackData = body.callback_data;\nconst parts = callbackData.split('|');\n\n// Format: sunnah|Prayer|yes/no|date|telegram_id|message_id|masjid_text (optional)\nconst prayer = parts[1];\nconst answer = parts[2]; // 'yes' or 'no'\nconst date = parts[3];\nconst telegramId = parseInt(parts[4]);\nconst messageId = parseInt(parts[5]);\nconst masjidText = parts[6] || ''; // May be empty if no masjid question was asked\n\n// Map prayer to sunnah column(s)\nconst sunnahColumnMap = {\n  'Fajr': 'fajr_sunnah_2',\n  'Dhuhr': 'dhuhr_sunnah_4_before',\n  'Maghrib': 'maghrib_sunnah_2',\n  'Isha': 'isha_sunnah_2'\n};\n\nconst columnName = sunnahColumnMap[prayer];\nconst prayedSunnah = answer === 'yes';\n\n// Prayer Arabic names\nconst prayerArabic = {\n  'Fajr': '\u0627\u0644\u0641\u062c\u0631',\n  'Dhuhr': '\u0627\u0644\u0638\u0647\u0631',\n  'Asr': '\u0627\u0644\u0639\u0635\u0631',\n  'Maghrib': '\u0627\u0644\u0645\u063a\u0631\u0628',\n  'Isha': '\u0627\u0644\u0639\u0634\u0627\u0621'\n};\n\n// Build final confirmation message\nlet finalMessage = `\u2705 \u062a\u0645 \u062a\u0633\u062c\u064a\u0644 \u0635\u0644\u0627\u0629 ${prayerArabic[prayer]} \u0641\u064a \u0648\u0642\u062a\u0647\u0627\\n`;\n\nif (masjidText) {\n  finalMessage += `${masjidText}`;\n  if (prayedSunnah) {\n    finalMessage += ` + \u0633\u0646\u0629 ${prayerArabic[prayer]}`;\n  }\n  finalMessage += `\\n\u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32`;\n} else {\n  if (prayedSunnah) {\n    finalMessage += `+ \u0633\u0646\u0629 ${prayerArabic[prayer]}\\n\u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32`;\n  } else {\n    finalMessage += `\u062a\u0642\u0628\u0644 \u0627\u0644\u0644\u0647 \ud83e\udd32`;\n  }\n}\n\nreturn {\n  json: {\n    telegram_id: telegramId,\n    chat_id: body.chat_id,\n    message_id: messageId,\n    callback_query_id: body.callback_query_id,\n    prayer: prayer,\n    prayer_arabic: prayerArabic[prayer],\n    date: date,\n    column_name: columnName,\n    prayed_sunnah: prayedSunnah,\n    final_message: finalMessage\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -4960,
        9184
      ],
      "id": "04f7a5a1-666a-419d-bb78-18ac39e55e1b",
      "name": "Parse Sunnah Callback"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "has-column",
              "leftValue": "={{ $json.column_name }}",
              "rightValue": "",
              "operator": {
                "type": "string",
                "operation": "notEmpty"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -4736,
        9184
      ],
      "id": "d91059b3-341a-41ee-8a6b-0225d8d319fd",
      "name": "Has Sunnah Column?"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO daily_deeds (user_id, date, {{ $json.column_name }})\nVALUES ({{ $json.telegram_id }}, '{{ $json.date }}', {{ $json.prayed_sunnah }})\nON CONFLICT (user_id, date) \nDO UPDATE SET {{ $json.column_name }} = {{ $json.prayed_sunnah }}, updated_at = NOW();",
        "options": {}
      },
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.6,
      "position": [
        -4512,
        9120
      ],
      "id": "356f6e65-39cb-46dd-8923-44a3af97993e",
      "name": "Update Sunnah in DB",
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/editMessageText",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"chat_id\": {{ $('Parse Sunnah Callback').item.json.chat_id }},\n  \"message_id\": {{ $('Parse Sunnah Callback').item.json.message_id }},\n  \"text\": {{ JSON.stringify($('Parse Sunnah Callback').item.json.final_message) }}\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4288,
        9200
      ],
      "id": "26c5cdc6-467b-4448-9037-63005a6b1208",
      "name": "Edit to Final Message"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.telegram.org/bot{{ $env.TELEGRAM_BOT_TOKEN }}/answerCallbackQuery",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"callback_query_id\": \"{{ $('Parse Sunnah Callback').item.json.callback_query_id }}\",\n  \"text\": \"\u062a\u0645 \u2705\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -4080,
        9200
      ],
      "id": "b9f7d378-3068-4615-bcb7-40b873edaba3",
      "name": "Answer Callback Query2"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify({ success: true }) }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        -3856,
        9200
      ],
      "id": "e668fddd-5aa0-4e74-a1d4-1fbe789bd277",
      "name": "Respond Success2"
    },
    {
      "parameters": {
        "content": "",
        "height": 944,
        "width": 1856,
        "color": 2
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -5216,
        8432
      ],
      "id": "84ff7e7e-f993-4d26-9bf9-68653fb6d4ca",
      "name": "Sticky Note29"
    },
    {
      "parameters": {
        "content": "# Post Prayer Webhook / Callbacks",
        "height": 96,
        "width": 600,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -5168,
        8512
      ],
      "id": "30b7aae0-017f-489f-8501-5fcbbd6ac0d2",
      "name": "Sticky Note23"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4336,
        8528
      ],
      "id": "ce58614a-7604-4022-b0fa-7d7337efbc81",
      "name": "Sticky Note8"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4144,
        8608
      ],
      "id": "40a43000-d397-4f54-bc1b-d19c3063b741",
      "name": "Sticky Note9"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -3904,
        8928
      ],
      "id": "e509ffbd-d759-4a3a-86b8-1e3ff0383128",
      "name": "Sticky Note10"
    },
    {
      "parameters": {
        "content": "",
        "height": 320,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4128,
        8864
      ],
      "id": "bc6e1c8e-be8c-4885-a70f-099a217674f1",
      "name": "Sticky Note11"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4336,
        9168
      ],
      "id": "54697b1e-3eb7-48b1-8ccf-2fb6c1b715e8",
      "name": "Sticky Note12"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4128,
        9168
      ],
      "id": "0dbe9878-402a-487c-ab19-ba2ed1d2e1b8",
      "name": "Sticky Note13"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4560,
        9504
      ],
      "id": "e710c31d-3f61-4ac3-82eb-be7c5b199b1c",
      "name": "Sticky Note14"
    },
    {
      "parameters": {
        "content": "",
        "height": 208,
        "width": 192,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -4336,
        9504
      ],
      "id": "4de14c56-5ced-4e19-b2a5-5ac20bbf5231",
      "name": "Sticky Note15"
    }
  ],
  "connections": {
    "Update Daily Deeds": {
      "main": [
        [
          {
            "node": "Edit Azkar Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Azkar Message": {
      "main": [
        [
          {
            "node": "Answer Callback Query",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Answer Callback Query": {
      "main": [
        [
          {
            "node": "Respond Success",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Azkar Callback Webhook1": {
      "main": [
        [
          {
            "node": "Parse Azkar Callback1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Azkar Callback1": {
      "main": [
        [
          {
            "node": "Update Daily Deeds",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Post-Prayer Webhook": {
      "main": [
        [
          {
            "node": "Get User Settings1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decide Follow-up": {
      "main": [
        [
          {
            "node": "Ask Masjid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask Masjid?": {
      "main": [
        [
          {
            "node": "Edit to Masjid Question",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Ask Sunnah?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit to Masjid Question": {
      "main": [
        [
          {
            "node": "Respond Masjid",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask Sunnah?": {
      "main": [
        [
          {
            "node": "Edit to Sunnah Question1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond No Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get User Settings1": {
      "main": [
        [
          {
            "node": "Decide Follow-up",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit to Sunnah Question1": {
      "main": [
        [
          {
            "node": "Respond Sunnah",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Masjid Callback Webhook": {
      "main": [
        [
          {
            "node": "Parse Masjid Callback",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Masjid Callback": {
      "main": [
        [
          {
            "node": "Update Masjid in DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Masjid in DB": {
      "main": [
        [
          {
            "node": "Check Sunnah Enabled",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Sunnah Enabled": {
      "main": [
        [
          {
            "node": "Ask Sunnah Next?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ask Sunnah Next?": {
      "main": [
        [
          {
            "node": "Edit to Sunnah Question",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit to Final Confirmation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit to Sunnah Question": {
      "main": [
        [
          {
            "node": "Answer Callback Query1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit to Final Confirmation": {
      "main": [
        [
          {
            "node": "Answer Callback Query1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Answer Callback Query1": {
      "main": [
        [
          {
            "node": "Respond Success1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sunnah Callback Webhook": {
      "main": [
        [
          {
            "node": "Parse Sunnah Callback",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Sunnah Callback": {
      "main": [
        [
          {
            "node": "Has Sunnah Column?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Sunnah Column?": {
      "main": [
        [
          {
            "node": "Update Sunnah in DB",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit to Final Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Sunnah in DB": {
      "main": [
        [
          {
            "node": "Edit to Final Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit to Final Message": {
      "main": [
        [
          {
            "node": "Answer Callback Query2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Answer Callback Query2": {
      "main": [
        [
          {
            "node": "Respond Success2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "meta": {
    "templateCredsSetupCompleted": true
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

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

About this workflow

Post-Prayer. Uses postgres, httpRequest. Webhook trigger; 44 nodes.

Source: https://github.com/mustafatawfiq/hazem/blob/fba6bbcca492c550daa50b34b4f62fabcd1f1026/workflows/post-prayer.json — original creator credit. Request a take-down →

More Data & Sheets workflows → · Browse all categories →

Related workflows

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

Data & Sheets

CMM. Uses httpRequest, postgres, redis. Webhook trigger; 90 nodes.

HTTP Request, Postgres, Redis
Data & Sheets

Scraping. Uses httpRequest, postgres, @apify/n8n-nodes-apify, respondToWebhook. Webhook trigger; 61 nodes.

HTTP Request, Postgres, @Apify/N8N Nodes Apify
Data & Sheets

Workflow B — AI Listing Engine. Uses httpRequest, postgres, errorTrigger. Webhook trigger; 47 nodes.

HTTP Request, Postgres, Error Trigger
Data & Sheets

LogSentinel Workflow. Uses postgres, emailSend, httpRequest. Webhook trigger; 44 nodes.

Postgres, Email Send, HTTP Request
Data & Sheets

ITB SDR — MVP. Uses postgres, httpRequest. Webhook trigger; 39 nodes.

Postgres, HTTP Request