makara-filip / ts-messenger-api

The unofficial API for FB Messenger communication
MIT License
51 stars 13 forks source link

[Help Wanted] unable to listen to incoming message. #18

Closed stevewas closed 3 years ago

stevewas commented 3 years ago

hello, I'm trying to listen to incoming messages and echo it back however I can't seem to get it to work. If you are free can you check it out and let me know what I'm doing wrong. I tried referencing the documentation but cannot find where 'addEventListener' is at.

using vanilla javascript Mac os x 12.0 node v16.10.0

const facebookLogin = require('ts-messenger-api').default;

(async () => { const api = await facebookLogin({ email: 'EMAIL', password: 'PASSWORD' }, {listenEvents: true}); // const friends = await api.getFriendsList(); // console.log(friends) await api.listen(); api.listener.addEventListener('message', (msg) => console.log(msg));

})();

the error I'm getting

info login Logging in... info login Redirected to https:\/\/www.facebook.com\/ info login Logged in info login Request to reconnect info login Done logging in. /Users/USER/Desktop/facebook/index.js:13 api.listener.addEventListener('message', (msg) => console.log(msg)); ^

TypeError: api.listener.addEventListener is not a function at /Users/USER/Desktop/facebook/index.js:13:20 at processTicksAndRejections (node:internal/process/task_queues:96:5)

stevewas commented 3 years ago

got it to work used

api.listener.on('message', (msg) => console.log(msg));