{
  "name": "TuVanDichVu_SoiDa_Melatech",
  "nodes": [
    {
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        250,
        100
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "message",
        "responseMode": "onReceived",
        "responseData": "success",
        "responseContentType": "text/plain"
      }
    },
    {
      "name": "ParseMessage",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        100
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "text",
              "value": "={{$json[\"entry\"][0].messaging[0].message.text}}"
            },
            {
              "name": "senderId",
              "value": "={{$json[\"entry\"][0].messaging[0].sender.id}}"
            }
          ],
          "json": [
            {
              "name": "attachments",
              "value": "={{$json[\"entry\"][0].messaging[0].message.attachments}}"
            }
          ]
        },
        "keepOnlySet": false
      }
    },
    {
      "name": "CheckOptions",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        650,
        100
      ],
      "parameters": {
        "rules": {
          "rules": [
            {
              "value1": "={{$json.text}}",
              "operation": "contains",
              "value2": "t\u01b0 v\u1ea5n soi da"
            },
            {
              "value1": "={{$json.text}}",
              "operation": "contains",
              "value2": "t\u01b0 v\u1ea5n da"
            },
            {
              "value1": "={{$json.text}}",
              "operation": "contains",
              "value2": "d\u1ecbch v\u1ee5"
            },
            {
              "value1": "={{$json.text}}",
              "operation": "contains",
              "value2": "D\u1ecbch v\u1ee5"
            }
          ]
        },
        "ignoreCase": true,
        "fallbackOutput": "extraOutput"
      }
    },
    {
      "name": "GS_Append_New",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        850,
        50
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "T\u00ean",
            "value": "={{$json.text}}"
          },
          {
            "column": "ID Facebook",
            "value": "={{$json.senderId}}"
          },
          {
            "column": "State",
            "value": "1"
          }
        ]
      }
    },
    {
      "name": "FB_AskName",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1050,
        50
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Ch\u00e0o b\u1ea1n! \u0110\u1ec3 ph\u00e2n t\u00edch da ch\u00ednh x\u00e1c, Melatech c\u1ea7n m\u1ed9t s\u1ed1 th\u00f4ng tin t\u1eeb b\u1ea1n. \u0110\u1ea7u ti\u00ean, b\u1ea1n vui l\u00f2ng cho bi\u1ebft H\u1ecc T\u00caN c\u1ee7a m\u00ecnh nh\u00e9?"
          }
        }
      }
    },
    {
      "name": "OpenAI_Service",
      "type": "n8n-nodes-base.openAIGPT",
      "typeVersion": 1,
      "position": [
        850,
        150
      ],
      "parameters": {
        "model": "gpt-4",
        "messages": [
          {
            "role": "system",
            "content": "B\u1ea1n l\u00e0 chuy\u00ean gia t\u01b0 v\u1ea5n spa Melatech."
          },
          {
            "role": "user",
            "content": "Kh\u00e1ch h\u00e0ng y\u00eau c\u1ea7u t\u01b0 v\u1ea5n d\u1ecbch v\u1ee5: {{$json.text}}. Vui l\u00f2ng t\u01b0 v\u1ea5n chi ti\u1ebft v\u1ec1 c\u00e1c d\u1ecbch v\u1ee5 Melatech cung c\u1ea5p."
          }
        ]
      }
    },
    {
      "name": "FB_ServiceReply",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1050,
        150
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "={{$node[\"OpenAI_Service\"].json.text}}"
          }
        }
      }
    },
    {
      "name": "GS_Lookup",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        850,
        250
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "lookupColumn": "ID Facebook",
        "lookupValue": "={{$json.senderId}}"
      }
    },
    {
      "name": "IF_UserExists",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1050,
        250
      ],
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$node[\"GS_Lookup\"].json.length}}",
              "operation": "greaterThan",
              "value2": 0
            }
          ]
        }
      }
    },
    {
      "name": "FB_Greet",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1250,
        200
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Xin ch\u00e0o! M\u00ecnh l\u00e0 chatbot c\u1ee7a Melatech Spa. Melatech l\u00e0 trung t\u00e2m chuy\u00ean ch\u0103m s\u00f3c da. B\u1ea1n mu\u1ed1n t\u01b0 v\u1ea5n d\u1ecbch v\u1ee5 g\u00ec h\u00f4m nay?",
            "quick_replies": [
              {
                "content_type": "text",
                "title": "T\u01b0 v\u1ea5n d\u1ecbch v\u1ee5",
                "payload": "tuvan_dichvu"
              },
              {
                "content_type": "text",
                "title": "T\u01b0 v\u1ea5n soi da",
                "payload": "tuvan_soida"
              }
            ]
          }
        }
      }
    },
    {
      "name": "CheckState",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 1,
      "position": [
        1250,
        300
      ],
      "parameters": {
        "rules": {
          "rules": [
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].State}}",
              "operation": "equals",
              "value2": "1"
            },
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].State}}",
              "operation": "equals",
              "value2": "2"
            },
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].State}}",
              "operation": "equals",
              "value2": "3"
            },
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].State}}",
              "operation": "equals",
              "value2": "4"
            },
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].State}}",
              "operation": "equals",
              "value2": "5"
            },
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].State}}",
              "operation": "equals",
              "value2": "6"
            }
          ]
        }
      }
    },
    {
      "name": "GS_UpdateName",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1450,
        200
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "T\u00ean",
            "value": "={{$json.text}}"
          },
          {
            "column": "State",
            "value": "2"
          }
        ]
      }
    },
    {
      "name": "FB_AskAge",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1650,
        200
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "C\u1ea3m \u01a1n b\u1ea1n. Vui l\u00f2ng nh\u1eadp TU\u1ed4I c\u1ee7a b\u1ea1n."
          }
        }
      }
    },
    {
      "name": "GS_UpdateAge",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1450,
        300
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "Tu\u1ed5i",
            "value": "={{$json.text}}"
          },
          {
            "column": "State",
            "value": "3"
          }
        ]
      }
    },
    {
      "name": "FB_AskPhone",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1650,
        300
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Tuy\u1ec7t v\u1eddi! B\u1ea1n h\u00e3y cung c\u1ea5p s\u1ed1 \u0111i\u1ec7n tho\u1ea1i c\u1ee7a m\u00ecnh."
          }
        }
      }
    },
    {
      "name": "GS_UpdatePhone",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1450,
        400
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "S\u1ed1 \u0111i\u1ec7n tho\u1ea1i",
            "value": "={{$json.text}}"
          },
          {
            "column": "State",
            "value": "4"
          }
        ]
      }
    },
    {
      "name": "FB_AskFront",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1650,
        400
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Vui l\u00f2ng g\u1eedi \u1ea3nh ho\u1eb7c ch\u1ee5p m\u1eb7t ch\u00ednh di\u1ec7n (kh\u00f4ng makeup)."
          }
        }
      }
    },
    {
      "name": "GS_UpdateFront",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1450,
        500
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "\u1ea2nh m\u1eb7t ch\u00ednh di\u1ec7n",
            "value": "={{$json.attachments[0].payload.url}}"
          },
          {
            "column": "State",
            "value": "5"
          }
        ]
      }
    },
    {
      "name": "FB_AskLeft",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1650,
        500
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Gi\u1edd h\u00e3y g\u1eedi \u1ea3nh ho\u1eb7c ch\u1ee5p m\u1eb7t tr\u00e1i g\u01b0\u01a1ng m\u1eb7t."
          }
        }
      }
    },
    {
      "name": "GS_UpdateLeft",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1450,
        600
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "\u1ea2nh m\u1eb7t tr\u00e1i",
            "value": "={{$json.attachments[0].payload.url}}"
          },
          {
            "column": "State",
            "value": "6"
          }
        ]
      }
    },
    {
      "name": "FB_AskRight",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1650,
        600
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Gi\u1edd h\u00e3y g\u1eedi \u1ea3nh ho\u1eb7c ch\u1ee5p m\u1eb7t ph\u1ea3i g\u01b0\u01a1ng m\u1eb7t."
          }
        }
      }
    },
    {
      "name": "GS_UpdateRight",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1450,
        700
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "\u1ea2nh m\u1eb7t ph\u1ea3i",
            "value": "={{$json.attachments[0].payload.url}}"
          },
          {
            "column": "State",
            "value": "7"
          }
        ]
      }
    },
    {
      "name": "FB_FinalThanks",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1650,
        700
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$json.senderId}}"
          },
          "message": {
            "text": "Tuy\u1ec7t v\u1eddi! B\u1ea1n h\u00e3y th\u01b0\u1edfng th\u1ee9c m\u1ed9t ly n\u01b0\u1edbc v\u00e0 \u0111\u1ee3i \u00edt ph\u00fat, m\u00ecnh s\u1ebd g\u1eedi th\u00f4ng tin ph\u00e2n t\u00edch da ngay sau \u0111\u00e2y."
          }
        }
      }
    },
    {
      "name": "OpenAI_SkinAnalysis",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1850,
        700
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "authentication": "headerAuth",
        "headerAuth": {
          "name": "Authorization",
          "value": "Bearer <redacted-credential>"
        },
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "model": "gpt-4",
          "messages": [
            {
              "role": "system",
              "content": "B\u1ea1n l\u00e0 m\u1ed9t chuy\u00ean gia da li\u1ec5u."
            },
            {
              "role": "user",
              "content": "D\u1ef1a tr\u00ean c\u00e1c th\u00f4ng tin sau:\n- T\u00ean: {{$node[\"GS_Lookup\"].json[0].T\u00ean}}\n- Tu\u1ed5i: {{$node[\"GS_Lookup\"].json[0].Tu\u1ed5i}}\n- \u1ea2nh g\u01b0\u01a1ng m\u1eb7t: {{$node[\"GS_Lookup\"].json[0]['\u1ea2nh m\u1eb7t ch\u00ednh di\u1ec7n']}}, {{$node[\"GS_Lookup\"].json[0]['\u1ea2nh m\u1eb7t tr\u00e1i']}}, {{$node[\"GS_Lookup\"].json[0]['\u1ea2nh m\u1eb7t ph\u1ea3i']}}\nH\u00e3y ph\u00e2n t\u00edch t\u00ecnh tr\u1ea1ng da kh\u00e1ch h\u00e0ng theo c\u00e1c ch\u1ec9 s\u1ed1:\n1. \u0110\u1ed9 \u1ea9m\n2. \u0110\u1ed9 nh\u1eddn\n3. L\u1ed7 ch\u00e2n l\u00f4ng\n4. N\u1ebfp nh\u0103n\n5. \u0110\u1ed9 \u0111\u00e0n h\u1ed3i\n6. \u0110\u1ed9 \u0111\u1ec1u m\u00e0u\n7. S\u1eafc t\u1ed1\n8. \u0110\u1ed1m n\u00e2u\n9. M\u1ee5n vi\u00eam\n10. M\u1ee5n \u1ea9n\n11. M\u1ee5n \u0111\u1ea7u \u0111en\n12. T\u00ecnh tr\u1ea1ng v\u00f9ng m\u1eaft\n13. \u0110\u1ed9 c\u0103ng b\u00f3ng\n14. K\u1ebft c\u1ea5u da\nTr\u00ecnh b\u00e0y ng\u1eafn g\u1ecdn, chuy\u00ean nghi\u1ec7p v\u00e0 m\u1eddi kh\u00e1ch \u0111\u1ebfn spa Melatech (164 Khu\u1ea5t Duy Ti\u1ebfn, H\u00e0 N\u1ed9i)."
            }
          ]
        }
      }
    },
    {
      "name": "FB_SendAnalysis",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        2050,
        700
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$node[\"GS_Lookup\"].json[0]['ID Facebook']}}"
          },
          "message": {
            "text": "={{$json.choices[0].message.content}}"
          }
        }
      }
    },
    {
      "name": "Delay3Days",
      "type": "n8n-nodes-base.delay",
      "typeVersion": 1,
      "position": [
        2250,
        700
      ],
      "parameters": {
        "delayFor": 3,
        "timeUnit": "days"
      }
    },
    {
      "name": "IF_NotVisited",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        2450,
        700
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"GS_Lookup\"].json[0].\"\u0110\u00e3 \u0111\u1ebfn spa\"}}",
              "operation": "equals",
              "value2": "No"
            }
          ]
        }
      }
    },
    {
      "name": "FB_Reminder",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        2650,
        700
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "={{$node[\"GS_Lookup\"].json[0]['ID Facebook']}}"
          },
          "message": {
            "text": "B\u1ea1n \u01a1i! \u0110\u1eebng qu\u00ean l\u00e0n da c\u1ea7n b\u1ea1n y\u00eau th\u01b0\u01a1ng m\u1ed7i ng\u00e0y. N\u1ebfu b\u1ea1n c\u1ea7n h\u1ed7 tr\u1ee3 th\u00eam, \u0111\u1ed9i ng\u0169 chuy\u00ean gia c\u1ee7a Melatech lu\u00f4n s\u1eb5n s\u00e0ng t\u1ea1i spa. H\u1eb9n g\u1eb7p b\u1ea1n t\u1ea1i Licogi 13 \u2013 Khu\u1ea5t Duy Ti\u1ebfn nh\u00e9."
          }
        }
      }
    },
    {
      "name": "GS_UpdateReminder",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        2850,
        700
      ],
      "parameters": {
        "authentication": "serviceAccount",
        "sheetId": "1qOy18YwLQru0OmX6E2ZeHuTjq-PC2UbH0QQtdiksDYE",
        "range": "MELATECH",
        "keyRow": 1,
        "valueInputMode": "RAW",
        "rowData": [
          {
            "column": "Ng\u00e0y g\u1eedi nh\u1eafc l\u1ea1i",
            "value": "={{(new Date()).toLocaleDateString('en-GB')}}"
          }
        ]
      }
    },
    {
      "name": "CronWeekly",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        650,
        800
      ],
      "parameters": {
        "mode": "everyWeek",
        "dayOfWeek": "Monday",
        "hour": 8,
        "minute": 0
      }
    },
    {
      "name": "OpenAI_Report",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        850,
        800
      ],
      "parameters": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "POST",
        "authentication": "headerAuth",
        "headerAuth": {
          "name": "Authorization",
          "value": "Bearer <redacted-credential>"
        },
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "model": "gpt-4",
          "messages": [
            {
              "role": "system",
              "content": "B\u1ea1n l\u00e0 tr\u1ee3 l\u00fd spa Melatech."
            },
            {
              "role": "user",
              "content": "H\u00e3y t\u1ed5ng h\u1ee3p b\u00e1o c\u00e1o tu\u1ea7n n\u00e0y: s\u1ed1 kh\u00e1ch nh\u1eafn tin, s\u1ed1 \u1ea3nh \u0111\u1ea7y \u0111\u1ee7, s\u1ed1 kh\u00e1ch \u0111\u1ebfn spa v\u00e0 t\u00ecnh tr\u1ea1ng da ph\u1ed5 bi\u1ebfn."
            }
          ]
        }
      }
    },
    {
      "name": "FB_SendReport",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1050,
        800
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v17.0/me/messages?access_token=EAAKnfGfn2JEBPAh0wEwS1DiPQkIEnda6rPZBUrN4Rjmm6T6ZC5QJmYBI1gbwYzzEZAhXWvTtSMut6ORmZCIAqGt6dyl4J5HZBrUzRp4LGZCZBTkb2Ugtrlkjbwvzf1d18oAEyiLc3Ya9g4nkz5i58d4M0BZBZA6UujN9fHxY2mHitXlZCfJkvRRjeSc5nstg1sweLiX9MsVQZDZZ",
        "method": "POST",
        "bodyContentType": "json",
        "jsonParameters": true,
        "bodyParametersJson": {
          "recipient": {
            "id": "61569562411931"
          },
          "message": {
            "text": "={{$json.choices[0].message.content}}"
          }
        }
      }
    }
  ],
  "connections": {
    "Webhook": {
      "main": [
        {
          "node": "ParseMessage",
          "type": "main",
          "index": 0
        }
      ]
    },
    "ParseMessage": {
      "main": [
        {
          "node": "CheckOptions",
          "type": "main",
          "index": 0
        }
      ]
    },
    "CheckOptions": {
      "main": [
        {
          "node": "GS_Append_New",
          "type": "main",
          "index": 0
        },
        {
          "node": "OpenAI_Service",
          "type": "main",
          "index": 1
        }
      ],
      "extraOutput": [
        {
          "node": "GS_Lookup",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_Append_New": {
      "main": [
        {
          "node": "FB_AskName",
          "type": "main",
          "index": 0
        }
      ]
    },
    "OpenAI_Service": {
      "main": [
        {
          "node": "FB_ServiceReply",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_Lookup": {
      "main": [
        {
          "node": "IF_UserExists",
          "type": "main",
          "index": 0
        }
      ]
    },
    "IF_UserExists": {
      "main1": [
        {
          "node": "CheckState",
          "type": "main",
          "index": 0
        }
      ],
      "main2": [
        {
          "node": "FB_Greet",
          "type": "main",
          "index": 0
        }
      ]
    },
    "CheckState": {
      "main": [
        {
          "node": "GS_UpdateName",
          "type": "main",
          "index": 0
        },
        {
          "node": "GS_UpdateAge",
          "type": "main",
          "index": 1
        },
        {
          "node": "GS_UpdatePhone",
          "type": "main",
          "index": 2
        },
        {
          "node": "GS_UpdateFront",
          "type": "main",
          "index": 3
        },
        {
          "node": "GS_UpdateLeft",
          "type": "main",
          "index": 4
        },
        {
          "node": "GS_UpdateRight",
          "type": "main",
          "index": 5
        }
      ]
    },
    "GS_UpdateName": {
      "main": [
        {
          "node": "FB_AskAge",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_UpdateAge": {
      "main": [
        {
          "node": "FB_AskPhone",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_UpdatePhone": {
      "main": [
        {
          "node": "FB_AskFront",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_UpdateFront": {
      "main": [
        {
          "node": "FB_AskLeft",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_UpdateLeft": {
      "main": [
        {
          "node": "FB_AskRight",
          "type": "main",
          "index": 0
        }
      ]
    },
    "GS_UpdateRight": {
      "main": [
        {
          "node": "FB_FinalThanks",
          "type": "main",
          "index": 0
        }
      ]
    },
    "FB_FinalThanks": {
      "main": [
        {
          "node": "OpenAI_SkinAnalysis",
          "type": "main",
          "index": 0
        }
      ]
    },
    "OpenAI_SkinAnalysis": {
      "main": [
        {
          "node": "FB_SendAnalysis",
          "type": "main",
          "index": 0
        }
      ]
    },
    "FB_SendAnalysis": {
      "main": [
        {
          "node": "Delay3Days",
          "type": "main",
          "index": 0
        }
      ]
    },
    "Delay3Days": {
      "main": [
        {
          "node": "IF_NotVisited",
          "type": "main",
          "index": 0
        }
      ]
    },
    "IF_NotVisited": {
      "main": [
        {
          "node": "FB_Reminder",
          "type": "main",
          "index": 0
        }
      ],
      "main2": [
        {
          "node": "GS_UpdateReminder",
          "type": "main",
          "index": 0
        }
      ]
    },
    "CronWeekly": {
      "main": [
        {
          "node": "OpenAI_Report",
          "type": "main",
          "index": 0
        }
      ]
    },
    "OpenAI_Report": {
      "main": [
        {
          "node": "FB_SendReport",
          "type": "main",
          "index": 0
        }
      ]
    }
  }
}