}, function (error, response, body) {
if (!error && response.statusCode == 200) {
var recipientId = body.recipient_id;
var messageId = body.message_id;
console.log("Successfully sent generic message with id %s to recipient %s",
messageId, recipientId);
} else {
console.error("Unable to send message.");
console.error(response);
console.error(error);
}
A few things to check are that your api keys are valid and you’re subscribed to the right page and that you’re using the same page-scoped access token to send the message that was used when you received the PSID.
In that case, you want to make sure you’re subscribed to all of the correct webhook events - under Webhook select ‘edit Events’ and select all the necessary Page Subscription Fields (select all if you’re unsure while in development). Then generate a new Page token and update the .env file in Glitch with it. Make sure the page you’re subscribed to is the same one you’re generating a token for.
The only way I was able to reproduce your error was when I didn’t have all needed permissions set, or I was using an old Page Token created prior to specifying the full permissions.
App Secret isn’t needed for this app. You only need to generate a Page Token for the same page you’ve created a webhook for and have subscribed to and add it to PAGE_ACCESS_TOKEN in .env on Glitch. As well as a user-created ‘verify’ token which can be any string you make up. It needs to match on both Facebook and in the VERIFY_TOKEN value .env on Glitch.
Sorry to hear that. I tried remixing your exact app and it’s working fine for me. This confirms that it isn’t a problem with Glitch or the code used, it’s a setup problem. I suggest you walk through the setup steps again and ensure you’ve followed them correctly:
Create the app on Facebook, add your verify token to the .env file on Glitch and register the ‘Page’ type webhook using the verify token on Facebook (setting the webhook url to the Glitch one with ‘/webhook’ on the end). Then add messenger to your app on Facebook, edit the webhook permissions to include all actions and subscribe to your Facebook page. Generate a page token for that same page and copy and paste the page token into the .env file. Then send a message to your Facebook page to test.