{
  "name": "Duyệt câu trả lời qua Telegram",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "callback_query",
          "message"
        ],
        "additionalFields": {
          "chatIds": "DIEN_CHAT_ID_TELEGRAM_CUA_BAN"
        }
      },
      "id": "d2b947ba-aefe-45d1-957c-9280074b412e",
      "name": "Bạn bấm nút hoặc gõ câu sửa",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.4,
      "position": [
        0,
        288
      ],
      "webhookId": "5e90bfad-0e15-4c2c-8087-1660e1314113"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "hanh_dong",
              "name": "hanh_dong",
              "value": "={{ $json.callback_query?.data ? $json.callback_query.data.split(\"|\")[0] : \"van_ban\" }}",
              "type": "string"
            },
            {
              "id": "comment_id",
              "name": "comment_id",
              "value": "={{ $json.callback_query?.data ? $json.callback_query.data.split(\"|\")[1] : \"\" }}",
              "type": "string"
            },
            {
              "id": "query_id",
              "name": "query_id",
              "value": "={{ $json.callback_query?.id ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "chat_id",
              "name": "chat_id",
              "value": "={{ $json.callback_query?.message?.chat?.id ?? $json.message?.chat?.id ?? \"\" }}",
              "type": "string"
            },
            {
              "id": "van_ban",
              "name": "van_ban",
              "value": "={{ $json.callback_query ? \"\" : ($json.message?.text ?? \"\") }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "8b4de16e-5693-46b7-9e1f-f42ddfc85468",
      "name": "Bóc lệnh từ Telegram",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        288
      ],
      "notes": "Một trigger nhận hai loại việc: bấm nút thì có callback_query, còn gõ câu sửa thì chỉ có message."
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 1
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.hanh_dong }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "dang"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Đăng"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 1
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.hanh_dong }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "bo"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Bỏ qua"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "loose",
                  "version": 1
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.hanh_dong }}",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "rightValue": "sua"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Xin sửa"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Câu sửa bạn gõ"
        }
      },
      "id": "b360196c-4bc7-4320-abc1-71cac8409218",
      "name": "Bạn muốn làm gì",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        448,
        256
      ]
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "DIEN_ID_BANG_CUA_BAN",
          "cachedResultName": "CHON LAI BANG CUA BAN"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "comment_id",
              "keyValue": "={{ $json.comment_id }}"
            }
          ]
        },
        "limit": 1,
        "orderBy": true
      },
      "id": "af3bf8d3-9ea5-47db-ac39-d8a112c385fc",
      "name": "Lấy bản nháp đã lưu",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        672,
        0
      ]
    },
    {
      "parameters": {
        "httpRequestMethod": "POST",
        "graphApiVersion": "v23.0",
        "node": "={{ $(\"Bóc lệnh từ Telegram\").item.json.comment_id }}",
        "edge": "comments",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "message",
                "value": "={{ $json.cau_tra_loi }}"
              }
            ]
          }
        }
      },
      "id": "cda24f64-1bed-4311-a615-cf296be3154b",
      "name": "Đăng bản nháp lên Facebook",
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        896,
        0
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "DIEN_ID_BANG_CUA_BAN",
          "cachedResultName": "CHON LAI BANG CUA BAN"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "comment_id",
              "keyValue": "={{ $(\"Bóc lệnh từ Telegram\").item.json.comment_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "trang_thai": "={{ $json.id ? \"da_dang\" : \"loi_khi_dang\" }}"
          },
          "schema": [
            {
              "id": "trang_thai",
              "displayName": "trang_thai",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "19b500f4-23f1-499e-b9cf-4bdf20c875db",
      "name": "Đánh dấu đã đăng",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1120,
        0
      ]
    },
    {
      "parameters": {
        "resource": "callback",
        "queryId": "={{ $(\"Bóc lệnh từ Telegram\").item.json.query_id }}",
        "additionalFields": {
          "show_alert": "={{ $json.trang_thai !== \"da_dang\" }}",
          "text": "={{ $json.trang_thai === \"da_dang\" ? \"Đã đăng câu trả lời lên Facebook\" : \"CHƯA ĐĂNG ĐƯỢC. Facebook trả lỗi, chưa có gì lên fanpage. Bấm Đăng lại để thử nữa.\" }}"
        }
      },
      "id": "2dd9223b-9b5f-4768-aa44-778595ff2de8",
      "name": "Báo đã đăng",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1344,
        0
      ],
      "webhookId": "aeb91769-f738-437a-924e-4a5cdba1fc67"
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "DIEN_ID_BANG_CUA_BAN",
          "cachedResultName": "CHON LAI BANG CUA BAN"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "comment_id",
              "keyValue": "={{ $json.comment_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "trang_thai": "bo_qua"
          },
          "schema": [
            {
              "id": "trang_thai",
              "displayName": "trang_thai",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "b57e289d-87f2-4fc2-b882-7ef950021976",
      "name": "Đánh dấu bỏ qua",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        672,
        192
      ]
    },
    {
      "parameters": {
        "resource": "callback",
        "queryId": "={{ $(\"Bóc lệnh từ Telegram\").item.json.query_id }}",
        "additionalFields": {
          "show_alert": false,
          "text": "Đã bỏ qua, không đăng gì cả"
        }
      },
      "id": "df92158f-444a-4a77-9ad0-37c2129861ae",
      "name": "Báo đã bỏ qua",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        896,
        192
      ],
      "webhookId": "c6797552-0daf-46df-9bec-2c6ece886177"
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "DIEN_ID_BANG_CUA_BAN",
          "cachedResultName": "CHON LAI BANG CUA BAN"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "comment_id",
              "keyValue": "={{ $json.comment_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "trang_thai": "cho_sua"
          },
          "schema": [
            {
              "id": "trang_thai",
              "displayName": "trang_thai",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "d5a2870c-5050-404a-a90e-fa28b7efa92b",
      "name": "Đánh dấu chờ bạn gõ câu mới",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        672,
        384
      ],
      "notes": "Chỉ một bình luận được ở trạng thái chờ sửa tại một thời điểm. Câu bạn gõ tiếp theo sẽ được gán cho bình luận này."
    },
    {
      "parameters": {
        "chatId": "={{ $(\"Bóc lệnh từ Telegram\").item.json.chat_id }}",
        "text": "Bạn gõ câu muốn đăng, hệ thống sẽ đăng đúng nguyên văn, không nhờ AI viết lại.",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "f3b39489-d6c7-41b0-8da0-fbd05db65fe9",
      "name": "Mời bạn gõ câu mới",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        896,
        384
      ],
      "webhookId": "db72af1b-1ecd-4a69-8786-5225f9b47c9b"
    },
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "DIEN_ID_BANG_CUA_BAN",
          "cachedResultName": "CHON LAI BANG CUA BAN"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "trang_thai",
              "keyValue": "cho_sua"
            }
          ]
        },
        "limit": 1,
        "orderBy": true,
        "orderByColumn": "updatedAt"
      },
      "id": "85372a81-f5ad-46c8-8e70-7a2bac8501dd",
      "name": "Tìm bình luận đang chờ sửa",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        672,
        576
      ]
    },
    {
      "parameters": {
        "httpRequestMethod": "POST",
        "graphApiVersion": "v23.0",
        "node": "={{ $json.comment_id }}",
        "edge": "comments",
        "options": {
          "queryParameters": {
            "parameter": [
              {
                "name": "message",
                "value": "={{ $(\"Bóc lệnh từ Telegram\").item.json.van_ban }}"
              }
            ]
          }
        }
      },
      "id": "2244b49b-7e38-4d98-9e4b-407a594ff5c7",
      "name": "Đăng đúng câu bạn gõ",
      "type": "n8n-nodes-base.facebookGraphApi",
      "typeVersion": 1,
      "position": [
        896,
        576
      ],
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "DIEN_ID_BANG_CUA_BAN",
          "cachedResultName": "CHON LAI BANG CUA BAN"
        },
        "matchType": "allConditions",
        "filters": {
          "conditions": [
            {
              "keyName": "comment_id",
              "keyValue": "={{ $(\"Tìm bình luận đang chờ sửa\").item.json.comment_id }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "trang_thai": "={{ $json.id ? \"da_dang_ban_sua\" : \"loi_khi_dang\" }}",
            "cau_tra_loi": "={{ $(\"Bóc lệnh từ Telegram\").item.json.van_ban }}"
          },
          "schema": [
            {
              "id": "trang_thai",
              "displayName": "trang_thai",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "cau_tra_loi",
              "displayName": "cau_tra_loi",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ]
        },
        "options": {}
      },
      "id": "28ebb58c-d04c-470b-9e67-27a45f233c5b",
      "name": "Lưu câu bạn đã sửa",
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1120,
        576
      ]
    },
    {
      "parameters": {
        "chatId": "={{ $(\"Bóc lệnh từ Telegram\").item.json.chat_id }}",
        "text": "={{ $json.trang_thai === \"da_dang_ban_sua\" ? \"Đã đăng đúng câu bạn gõ lên Facebook.\" : \"Chưa đăng được câu bạn gõ. Facebook trả lỗi nên chưa có gì lên fanpage.\" }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "id": "4cb60216-619f-49f0-bc33-65f155ed3df7",
      "name": "Báo đã đăng câu sửa",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1344,
        576
      ],
      "webhookId": "914ade8a-7563-4df3-9419-d822d26d4787"
    },
    {
      "parameters": {
        "content": "## BẠN PHẢI ĐIỀN\n### Chat ID, ngay node bên dưới\n\nÔ **Chat IDs** trong node trigger đang để `DIEN_CHAT_ID_TELEGRAM_CUA_BAN`. Thay bằng mã cuộc trò chuyện của chính bạn.\n\nĐây không phải ô cho đẹp. Nó là khóa cửa.\n\nBỏ trống thì **bất kỳ ai nhắn cho bot cũng điều khiển được việc đăng bài lên fanpage của bạn**, chỉ cần họ biết tên bot.",
        "height": 300,
        "width": 320,
        "color": 3
      },
      "id": "25b5939c-695a-4588-a4b0-d0dcb80c2608",
      "name": "Sticky Note c8ee2450",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -64,
        48
      ]
    },
    {
      "parameters": {
        "content": "### Nhánh sửa tay\n\nBấm Sửa không đăng gì cả, nó chỉ đánh dấu bình luận đang chờ. Câu bạn gõ ngay sau đó được đăng nguyên văn, không nhờ AI viết lại.\n\nVì vậy chỉ một bình luận được ở trạng thái chờ sửa tại một thời điểm. Bấm Sửa hai câu liên tiếp rồi mới gõ thì câu gõ sẽ vào bình luận bạn bấm sau cùng.",
        "height": 260,
        "width": 320,
        "color": 4
      },
      "id": "9fee7cba-8105-4f4c-9c64-196b37e14083",
      "name": "Sticky Note 1324bc44",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        624,
        752
      ]
    },
    {
      "parameters": {
        "content": "# BẮT ĐẦU Ở ĐÂY\n\nĐây là **cổng duyệt** của hệ thống. Luồng chính đẩy bản nháp sang Telegram, bạn bấm Đăng, Sửa hoặc Bỏ qua ở đó, và workflow này thực thi.\n\n**Ba việc phải làm:**\n\n**1.** Điền Chat ID vào node trigger. Xem khối BẠN PHẢI ĐIỀN.\n\n**2.** Chọn lại **bảng lưu của bạn** trong sáu node Data Table. Phải là đúng cái bảng luồng chính đang dùng, khác bảng là bấm nút không tìm ra bản nháp.\n\n**3.** Chọn credential Telegram và credential Facebook loại Page cho các node tương ứng.\n\n---\n\n### VÌ SAO CẦN WORKFLOW NÀY\n\nKhông có nó thì hệ thống chỉ còn hai lựa chọn cho mỗi bình luận khó: liều đăng, hoặc bỏ rơi người ta.\n\nĐây chính là chỗ bạn đứng bên trong hệ thống thay vì đứng ngoài nhìn nó chạy.",
        "height": 420,
        "width": 460,
        "color": 5
      },
      "id": "01851b53-741f-4709-9775-40b5a16d39c9",
      "name": "BẮT ĐẦU Ở ĐÂY",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -64,
        -320
      ]
    }
  ],
  "connections": {
    "Bóc lệnh từ Telegram": {
      "main": [
        [
          {
            "node": "Bạn muốn làm gì",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lấy bản nháp đã lưu": {
      "main": [
        [
          {
            "node": "Đăng bản nháp lên Facebook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Đăng bản nháp lên Facebook": {
      "main": [
        [
          {
            "node": "Đánh dấu đã đăng",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Đánh dấu đã đăng": {
      "main": [
        [
          {
            "node": "Báo đã đăng",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Đánh dấu bỏ qua": {
      "main": [
        [
          {
            "node": "Báo đã bỏ qua",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tìm bình luận đang chờ sửa": {
      "main": [
        [
          {
            "node": "Đăng đúng câu bạn gõ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Bạn bấm nút hoặc gõ câu sửa": {
      "main": [
        [
          {
            "node": "Bóc lệnh từ Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Bạn muốn làm gì": {
      "main": [
        [
          {
            "node": "Lấy bản nháp đã lưu",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Đánh dấu bỏ qua",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Đánh dấu chờ bạn gõ câu mới",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Tìm bình luận đang chờ sửa",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Đánh dấu chờ bạn gõ câu mới": {
      "main": [
        [
          {
            "node": "Mời bạn gõ câu mới",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Đăng đúng câu bạn gõ": {
      "main": [
        [
          {
            "node": "Lưu câu bạn đã sửa",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lưu câu bạn đã sửa": {
      "main": [
        [
          {
            "node": "Báo đã đăng câu sửa",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": true
  },
  "nodeGroups": []
}