Я пытаюсь разработать бота для FB Messenger и постоянно сталкиваюсь с их документацией. В настоящее время я пытался добавить текст приветствия и кнопку Get_Started в JavaScript, так что я смогу легко их изменить. Кажется, что большая часть их документации находится в PHP, или они просто говорят вам добавить ее, отправив запрос POST с помощью CURL, что сработало для меня, но опять же, это не так модульно. Я не могу найти подходящую документацию в JavaScript. и единственное, что это: https://www.techiediaries.com/build-messenger-bot-nodejs/ Но я не могу найти место, где вы действительно вызываете приветствие или функции начала работы. есть также это https://github.com/fbsamples/original-coast-clothing, но я все еще не могу найти, где они запускают обратные передачи Greetings и Get_Started. Только файл json, в котором он хранится /locales/en_US.json "profile".
В моем коде сейчас
// Accepts POST requests at /webhook endpoint
app.post('/webhook', (req, res) => {
// Parse the request body from the POST
let body = req.body;
// Check the webhook event is from a Page subscription
if (body.object === 'page') {
// Iterate over each entry - there may be multiple if batched
body.entry.forEach(function(entry) {
// Get the webhook event. entry.messaging is an array, but
// will only ever contain one event, so we get index 0
let webhook_event = entry.messaging[0];
console.log(webhook_event);
// Get the sender PSID
let sender_psid = webhook_event.sender.id;
console.log('Sender PSID: ' + sender_psid);
// Check if the event is a message or postback and
// pass the event to the appropriate handler function
if (webhook_event.message) {
handleMessage(sender_psid, webhook_event.message);
} else if (webhook_event.postback) {
handlePostback(sender_psid, webhook_event.postback);
}
});
// Return a '200 OK' response to all events
res.status(200).send('EVENT_RECEIVED');
} else {
// Return a '404 Not Found' if event is not from a page subscription
res.sendStatus(404);
}
});
function setupGreetingText(res){
var messageData = {
"greeting":[
{
"locale":"default",
"text":"Greeting text for default local !"
}, {
"locale":"en_US",
"text":"Greeting text for en_US local !"
}
]};
request({
"uri": "https://graph.facebook.com/v2.6/me/messages",
"qs": { "access_token": process.env.PAGE_ACCESS_TOKEN },
"method": 'POST',
"headers": {'Content-Type': 'application/json'},
"form": messageData
},
function (error, response, body) {
if (!error && response.statusCode == 200) {
// Print out the response body
res.send(body);
} else {
// TODO: Handle errors
res.send(body);
}
});
}
, но я все еще не знаю, как его запустить .