Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.94k stars 597 forks source link

connecting to facebook page #565

Open CRGavrila opened 6 years ago

CRGavrila commented 6 years ago

Hello, i'm just got in touch with this api :) and i don't understand why is not connecting to a facebook page for simple echo message

const login = require("facebook-chat-api");

var credentials = {email: "my email", password: "my password"};

// Create simple echo bot login(credentials,{pageID: "my page id"}, (err, api) => { if(err) return console.error(err);

api.listen((err, message) => {
    api.sendMessage(message.body, message.threadID);
});

});

i also saw that function login(loginData, options, callback) { if(utils.getType(options) === 'Function' || utils.getType(options) === 'AsyncFunction') { callback = options; options = {}; } option should be id of the page

I'm missing someting can someone give me a hint ? Thx

Schmavery commented 6 years ago

Hi @CRGavrila, Unfortunately afaik most of our users don't use this api for pages (as there are already official apis for sending messages from non-user accounts) so it's possible there are some outstanding issues. The code snippet you quoted from the api is where we handle some "overloading" of the login function. You can see this if statement checks if options is a function -- this happens when the user only passes in two arguments: loginData and callback, and doesn't provide an options variable.