phanquocdat123 commited on
Commit
4a614fd
·
verified ·
1 Parent(s): 6d19ac1

Update routes/facebook.js

Browse files
Files changed (1) hide show
  1. routes/facebook.js +9 -11
routes/facebook.js CHANGED
@@ -82,23 +82,20 @@ module.exports = (processChatLogicWithTrace) => {
82
  let cleanReply = mainReply.replace(/\[\[?([^\]]+)\]?\]/g, '').replace(/\s+/g, ' ').trim();
83
  if (!cleanReply) cleanReply = mainReply;
84
 
85
- // 🎯 CƠ CHẾ FIRE & FORGET (BỎ AWAIT - CHẠY NGẦM KHÔNG CHỜ PHẢN HỒI TỪ FACEBOOK)
86
  if (mainReply.includes('SHOW_ORDER_FORM')) {
87
  console.log("📋 [FB] Gửi form chốt đơn gợi ý (Chạy ngầm)...");
88
  let guideText = `${cleanReply}\n\n(Mẹ nhấn vào nút "📝 Nhập thông tin" phía dưới hoặc nhắn tin theo mẫu: Tên: Hồng, SĐT: 093xxx, Địa chỉ: số nhà...)`;
89
 
90
- facebookService.sendResponse(sender_psid, {
91
- text: guideText,
92
- quick_replies: [{
93
- content_type: "text",
94
- title: "📝 Nhập thông tin",
95
- payload: "Tên: , SĐT: , Bé: , Nặng: , Địa chỉ: ACTION_SUBMIT_FORM"
96
- }]
97
- }).catch(err => console.error("❌ Lỗi gửi Form ngầm:", err.message));
98
 
99
  } else if (extractedButtons.length > 0) {
100
  console.log("🔘 [FB] Gửi danh sách nút bấm hành động (Chạy ngầm)...");
101
- let quickReplies = extractedButtons.map(btnText => {
 
 
102
  let parts = btnText.split('|');
103
  return {
104
  content_type: "text",
@@ -107,9 +104,10 @@ module.exports = (processChatLogicWithTrace) => {
107
  };
108
  }).filter(item => item.title !== "");
109
 
 
110
  facebookService.sendResponse(sender_psid, {
111
  text: cleanReply,
112
- quick_replies: quickReplies
113
  }).catch(err => console.error("❌ Lỗi gửi nút bấm ngầm:", err.message));
114
 
115
  } else {
 
82
  let cleanReply = mainReply.replace(/\[\[?([^\]]+)\]?\]/g, '').replace(/\s+/g, ' ').trim();
83
  if (!cleanReply) cleanReply = mainReply;
84
 
85
+ // 🎯 CƠ CHẾ FIRE & FORGET (CHẠY NGẦM KHÔNG CHỜ PHẢN HỒI TỪ FACEBOOK)
86
  if (mainReply.includes('SHOW_ORDER_FORM')) {
87
  console.log("📋 [FB] Gửi form chốt đơn gợi ý (Chạy ngầm)...");
88
  let guideText = `${cleanReply}\n\n(Mẹ nhấn vào nút "📝 Nhập thông tin" phía dưới hoặc nhắn tin theo mẫu: Tên: Hồng, SĐT: 093xxx, Địa chỉ: số nhà...)`;
89
 
90
+ // Đóng gói trực tiếp thành văn bản sạch để tránh lỗi logic chuỗi trong Service
91
+ facebookService.sendResponse(sender_psid, guideText)
92
+ .catch(err => console.error("❌ Lỗi gửi văn bản Form ngầm:", err.message));
 
 
 
 
 
93
 
94
  } else if (extractedButtons.length > 0) {
95
  console.log("🔘 [FB] Gửi danh sách nút bấm hành động (Chạy ngầm)...");
96
+
97
+ // Xây dựng mảng cấu trúc quick_replies hợp lệ
98
+ let quickRepliesPayload = extractedButtons.map(btnText => {
99
  let parts = btnText.split('|');
100
  return {
101
  content_type: "text",
 
104
  };
105
  }).filter(item => item.title !== "");
106
 
107
+ // Gửi qua một Object có thuộc tính văn bản tường minh
108
  facebookService.sendResponse(sender_psid, {
109
  text: cleanReply,
110
+ quick_replies: quickRepliesPayload
111
  }).catch(err => console.error("❌ Lỗi gửi nút bấm ngầm:", err.message));
112
 
113
  } else {