您可以使用下面的代碼發送快速答覆FB。
var replyfunc = function()
{
var quick_replies = ['a', 'b', 'c'];
var qrArray = [];
var text = "your text";
for (var count in quick_replies) {
var obj = {};
obj.content_type = "text",
obj.title = quick_replies[count],
obj.payload = "DEVELOPER_DEFINED_PAYLOAD_FOR_PICKING_" + quick_replies[count]
qrArray.push(obj);
}
var body = JSON.stringify({
recipient: { id },
// message: { text },
"message": {
"text": text,
"quick_replies": qrArray
}
});
sendResponse(body);
}
var sendResponse = function (body) {
const qs = 'access_token=' + encodeURIComponent(YOUR_FB_PAGE_TOKEN);
return fetch('https://graph.facebook.com/me/messages?' + qs, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body,
})
.then(rsp => rsp.json())
.then(json => {
if (json.error && json.error.message) {
throw new Error(json.error.message);
}
return json;
});
}