Handle messenger api postback button payload

Describe the problem/error/question

Hello, I am new at n8n and I am currently trying to implement a simple flow with messenger API. I have an issue where I don’t know how to trigger a specific action on n8n after clicking a button in messenger.

To illustrate the expected flow its:

User sends chat “!farm” → n8n trigger HTTP POST → POST to messenger api to display buttons (log harvest, view records) → user clicks button → do something on n8n (yet to implement)

I am only on test so the current output is:

Click execute workflow → send “!farm” on messenger → n8n triggers HTTP POST → buttons displayed on messenger → user clicks button → webhook does not recieve anything.

upon check meta docs it seems that it should trigger a postback (idk if that is the same as POST) to trigger the webhook, but its not happening.

I think I am missing something, and even if I try to click execute workflow before clicking buttons on messenger, it still doesn’t show on the webhook that is receiving something.

What is the error message (if any)?

There is no error, I am just unable to execute the desired functionality

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
{
  "nodes": [
    {
      "parameters": {
        "multipleMethods": true,
        "path": "3973f149-2a2d-4bfb-bbc3-26819008b1a4",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [
        0,
        -112
      ],
      "id": "d8736663-aeb9-439a-93a9-e5432ff5ce84",
      "name": "Webhook",
      "webhookId": "3973f149-2a2d-4bfb-bbc3-26819008b1a4",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "acae4b6d-9f5d-4621-8c83-dd607b8538fb",
              "leftValue": "={{ $json.query.hub_mode }}",
              "rightValue": "subscribe",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "4496e0a8-c914-4a96-8260-be8284cc26cf",
              "leftValue": "={{ $json.query.hub_verify_token }}",
              "rightValue": "chatbot",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        224,
        -208
      ],
      "id": "39251975-dcb9-4823-a7b2-51b23aeaa578",
      "name": "If"
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ $('Webhook').item.json.query.hub_challenge }}",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        448,
        -208
      ],
      "id": "644e1de9-c3fb-4af0-9eb8-78a649fa3bbd",
      "name": "Respond to Webhook"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "a8fa432b-682d-41a3-b5ef-d3214d47f18a",
              "leftValue": "={{ $json.body.entry[0].messaging[0].message.text }}",
              "rightValue": "!farm",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        224,
        -16
      ],
      "id": "a3cbd099-babc-4853-8028-cd2d7c404bd5",
      "name": "If1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://graph.facebook.com/v25.0/me/messages",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "access_token",
              "value": "EAANQkF1opXUBRBRMs5CzTX2mXZAkoPuFOkbZBRZAaPw8urL7ENF0l2825lv6Tru2zoyZBaXp1z4OElSOB8ZAqLeWT74vBj2OCbSg6X6YxjXnF289LLZAZBZCCQzoEvB0wUegS2OJ206LfBKUnYkoWCjcmTar07iZAwOzL35KCXqG7uqh9ex2WQAD3dPEK2XcuCSxs8jYwxV92"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"recipient\": {\n    \"id\":  {{ $('Webhook').item.json.body.entry[0].messaging[0].sender.id }}\n  },\n  \"message\": {\n    \"attachment\": {\n      \"type\": \"template\",\n      \"payload\": {\n        \"template_type\": \"button\",\n        \"text\": \"What do you want to do next?\",\n        \"buttons\": [\n          {\n            \"type\": \"postback\",\n            \"payload\": \"log_harvest\",\n            \"title\": \"Log Harvest\"\n          },\n          {\n            \"type\": \"postback\",\n            \"payload\": \"view_records\",\n            \"title\": \"View Records\"\n          }\n        ]\n      }\n    }\n  }\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        448,
        -16
      ],
      "id": "2f16faa7-31aa-4bbb-b79a-6783cd8bd95f",
      "name": "Send Action Options"
    },
    {
      "parameters": {
        "respondWith": "allIncomingItems",
        "options": {}
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        672,
        -16
      ],
      "id": "22b91602-2eee-42a3-aa2f-a2b3dee2f155",
      "name": "Respond to Webhook1"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "Send Action Options",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Action Options": {
      "main": [
        [
          {
            "node": "Respond to Webhook1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "af9de95e4e3acd580f5a15db7699daea3a5632747107f7c2bddef0c8b6c9ed1a"
  }
}

Share the output returned by the last node

[

{

“recipient_id”:
“5474387166017813”,
“message_id”:
“m_E5Ib5KbZuaHeX2pgQXOVdgJZUlf4SYcIW2o2QDW5p4g1HZIwq8bxLva6jyxO57PkWkMicfQBW0YrHSZggPQqPw”

}
]

Information on your n8n setup

  • n8n version: cloud
  • Database (default: SQLite): non used
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): cloud
  • Operating system: macOS

welcome to the n8n community @Kyle-Atienza
I’m using your webhook for messages, but add an IF after If1 (both branches) to check {{ $json.body.entry[0].messaging[0].postback.payload }} == “log_harvest” etc. Postbacks hit the SAME webhook! In Page: App > Webhooks > Subscribe `messaging_postbacks . Tested here!