Glitch with Facebook Bot Messenger


#1

I am new to Glitch, I am facing issue with Bot messenger. When I try to send message using PSID. Its giving
Error

code:100
error_subcode:2018001
fbtrace_id:“BeVBXQ325a7”
message:"(#100) No matching user found"
type:“OAuthException”

My Code:

sendTextMessage(event.sender.id, “Postback called”);

function sendTextMessage(recipientId, messageText) {
var messageData = {
recipient: {
id: recipientId
},
message: {
text: messageText
}
};

callSendAPI(messageData);
}

function callSendAPI(messageData) {
request({
uri: ‘https://graph.facebook.com/v2.6/me/messages’,
qs: { access_token: process.env.PAGE_ACCESS_TOKEN },
method: ‘POST’,
json: messageData

}, 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);
}

});
}

Kindly help me to resole this issue


#2

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.


#3

Thanks Garth,

Where we need to use api keys

I am subscribed to right page

Subscribed pages: HelixDemo

page-scoped access token - Yes

event.sender.id


#4

I took same code from

In this I added

PAGE_ACCESS_TOKEN
VERIFY_TOKEN
event.game_play - will be tigger when close Instant game.

This is been get triggered correctly. When I try to send “Thanks” message using PSID I am getting above error.


#5

Hi @Gareth ,
Any update.
My requirement is to send Thanks message after playing instant game.


#6

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.


#7

Thanks @Gareth, I will do the same and get back to you if any issue.


#8

Hi @Gareth,

I had addded all events

Selected events: messages, messaging_postbacks, messaging_optins, message_deliveries, message_reads, messaging_payments, messaging_pre_checkouts, messaging_checkout_updates, messaging_account_linking, messaging_referrals, message_echoes, messaging_game_plays, standby, messaging_handovers, messaging_policy_enforcement

and generate new Page Access Token.

Still I am getting same error.


#9

Pls explain me where and how to use App Secret. Is it necessary to use it?


#10

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.


#11

@Gareth,

app.get('/webhook', (req, res)

Is not getting triggered, Is there any reason?


#12

When specifying the webhook URL did you provide your Glitch URL appended with /webhook?


#13

https://quickdemo.glitch.me/webhook

This is the Callback URL I have given.


#14

It looks like you have the debugger enabled. Try disabling it and trying again.


#15

Sorry Mr. @Gareth, I am getting same error after disable debugger.


#16

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.