src/controllers/chatBotController.js
// Sends response messages via the Send API
Sends response messages via the Send API
Sends response messages via the Send API
function callSendAPI(sender_psid, response) {
    let request_body = {
        "recipient": {
            "id": sender_psid
        },
        "message": { "text": response }
    };
    request({
        "uri": "https://graph.facebook.com/v7.0/me/messages",
        "qs": { "access_token": process.env.FB_PAGE_TOKEN },
        "method": "POST",
        "json": request_body
    }, (err, res, body) => {
        if (!err) {
            console.log('message sent!');
        } else {
            console.error("Unable to send message:" + err);
        }
    });
}
function callSendAPI ( sender_psid , response ) { let request_body = { "recipient" : { "id" : sender_psid } , "message" : { "text" : response } } ; request ( { "uri" : "https://graph.facebook.com/v7.0/me/messages" , "qs" : { "access_token" : process . env . FB_PAGE_TOKEN } , "method" : "POST" , "json" : request_body } , ( err , res , body ) => { if ( ! err ) { console . log ( 'message sent!' ) ; } else { console . error ( "Unable to send message:" + err ) ; } } ) ; }
Sends response messages via the Send API
Sends response messages via the Send API
// Construct the message body // Send the HTTP request to the Messenger Platform