mathew-kurian / FacebookMessengerBot.js

:mailbox: Simple, light-weight Facebook Messenger Bot API for Node with ES6 support (via. Promises)
https://developers.facebook.com/docs/messenger-platform
117 stars 24 forks source link

Repeating "Unhandled rejection Error" - problem with async operations? #22

Open tobsch opened 7 years ago

tobsch commented 7 years ago

Hi there,

I'm having constant problems with your example code. Code:

bot.on('message', async message => {
    const {sender} = message;

    let out, buttons;

    await sender.fetch(`first_name,last_name,profile_pic`, true); // true: use cache

    // ---- send text
    out = new Elements();
    out.add({text: `hey ${sender.first_name}! what up`});
    await bot.send(sender.id, out);

    // wait for 1s
    await Bot.wait(1000);
});

Leads to

Unhandled rejection Error: cannot GET /v2.6/...?access_token=&fields=first_name%2Clast_name%2Cprofile_pic (400)
    at Response.toError (/Users/tobias/Projects/dreamer/node_modules/facebook-messenger-bot/node_modules/superagent/lib/node/response.js:106:13)
    at Response.setStatusProperties (/Users/tobias/Projects/dreamer/node_modules/facebook-messenger-bot/node_modules/superagent/lib/node/response.js:183:12)
    at new Response (/Users/tobias/Projects/dreamer/node_modules/facebook-messenger-bot/node_modules/superagent/lib/node/response.js:42:8)
    at Stream.<anonymous> (/Users/tobias/Projects/dreamer/node_modules/facebook-messenger-bot/node_modules/superagent/lib/node/index.js:918:22)
    at emitNone (events.js:91:20)
    at Stream.emit (events.js:185:7)
    at Unzip.<anonymous> (/Users/tobias/Projects/dreamer/node_modules/facebook-messenger-bot/node_modules/superagent/lib/node/utils.js:108:12)
    at emitNone (events.js:91:20)
    at Unzip.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:974:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Tracing deeper, the message coming from fb is:

Tried accessing nonexisting field (first_name) on node type (Page)

I am chatting with the bot in dev mode, but not as page. Whenever I re-focus the chat window, it triggers the "on message" callback and repeats this, Could this be connected to some "focus" event that is treated as "message" event or something?

Any Ideas what this could be? including the exception.

Node version is 7.4.0.

Best,

Tobias

tobsch commented 7 years ago

Okay, I obviously selected to many webhooks from the list. Would be great if the module would recognize the webhooks it does not support and not trigger a "message" callback...