phanquocdat123 commited on
Commit
977fc4d
·
verified ·
1 Parent(s): c7cdaa0

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +24 -0
server.js CHANGED
@@ -118,6 +118,30 @@ app.get('/', (req, res) => {
118
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
119
  });
120
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  app.post('/webhook', async (req, res) => {
122
  let body = req.body;
123
  if (body.object === 'page') {
 
118
  res.sendFile(path.join(__dirname, 'public', 'index.html'));
119
  });
120
 
121
+ // =========================================================
122
+ // 🎯 1. ROUTE XÁC MINH WEBHOOK VỚI FACEBOOK (PHƯƠNG THỨC GET)
123
+ // =========================================================
124
+ app.get('/webhook', (req, res) => {
125
+ const mode = req.query['hub.mode'];
126
+ const token = req.query['hub.verify_token'];
127
+ const challenge = req.query['hub.challenge'];
128
+
129
+ // Lấy mã xác thực bạn đã cài trong Variables/Secrets trên Hugging Face
130
+ const VERIFY_TOKEN = process.env.FB_VERIFY_TOKEN;
131
+
132
+ if (mode && token) {
133
+ if (mode === 'subscribe' && token === VERIFY_TOKEN) {
134
+ console.log('✅ [Facebook] Xác thực Webhook thành công!');
135
+ return res.status(200).send(challenge);
136
+ } else {
137
+ console.log('❌ [Facebook] Xác thực thất bại: Sai mã VERIFY_TOKEN');
138
+ return res.sendStatus(403);
139
+ }
140
+ }
141
+ res.sendStatus(400);
142
+ });
143
+
144
+
145
  app.post('/webhook', async (req, res) => {
146
  let body = req.body;
147
  if (body.object === 'page') {