Schmavery / facebook-chat-api

Unofficial Facebook Chat API for Nodejs
MIT License
1.93k stars 596 forks source link

Listen issues #763

Open Alcap opened 4 years ago

Alcap commented 4 years ago

Hi,

Did anyone notice some change in behaviour on facebook's end? I have an api.listen on my code and it was working just fine and all of the sudden it stopped.

Any code that that I place in the callback doesn't get executed when a message is received. This code was working fine just a few days ago and now, nothing. There's no errors provided, so I'm at a loss on how to go on the troubleshooting and how to fix this.

Thanks!

Alcap commented 4 years ago

Actually, I've tried to pick up the example code and run it as vanilla as possible and it is still unable to react when someone sends a message to any thread. I've looked up how to increase verbosity of the listen functions, but couldn't find anything of relevance... Any tips?

Thanks

AstroCB commented 4 years ago

I'm also experiencing this issue – my listen handler is no longer receiving messages.

There was a Messenger outage yesterday; perhaps this is related?

BadAimWeeb commented 4 years ago

Facebook Messenger is using WebSocket now. image great, now we need to rewrite that listen.js file

HossamMohsen7 commented 4 years ago

I have the same issue too. I think they now use websockets only.

I think they are using a MQTT over websockets protocol.

HossamMohsen7 commented 4 years ago

This might help too: https://github.com/tulir/fbchat-asyncio/blob/yet-another-rewrite/fbchat/_client.py#L2749-L2882

ccfiel commented 4 years ago

This might help too: https://github.com/tulir/fbchat-asyncio/blob/yet-another-rewrite/fbchat/_client.py#L2749-L2882

I did try this one but still the same problem

dinhphuc commented 4 years ago

I have the same issue too.

ghost commented 4 years ago

I also have the same issue.

Schmavery commented 4 years ago

If anyone has time, they could experiment with hooking up something like https://www.npmjs.com/package/mqtt maybe

HossamMohsen7 commented 4 years ago

@Schmavery Actually I did. It worked but the library itself needs some modification to work with the facebook protocol.

HossamMohsen7 commented 4 years ago

I'll try to get a PR ready when I can.

PixelHir commented 4 years ago

Stopped working today

PixelHir commented 4 years ago

for now i think that this could work as a replacement until the issue is resolved

HossamMohsen7 commented 4 years ago

PR is ready. Waiting to be merged.

ghost commented 4 years ago

@7osCraft I have this error on login:

ReferenceError: defaultFuncs is not defined
    at Object.listenMqtt (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:413:3)
    at C:\Users\Administrator\Downloads\messenger-bot-node\index.js:107:9
    at C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\index.js:446:14
    at tryCatcher (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\bluebird\js\main\util.js:26:23)
    at Promise._settlePromiseFromHandler (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\bluebird\js\main\promise.js:510:31)
    at Promise._settlePromiseAt (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\bluebird\js\main\promise.js:584:18)
    at Async._drainQueue (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\bluebird\js\main\async.js:128:12)
    at Async._drainQueues (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\bluebird\js\main\async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\bluebird\js\main\async.js:15:14)
    at processImmediate (internal/timers.js:439:21)

And listening doesn't work. This error is not showing on API from @Schmavery repo using the same code.

ac-opensource commented 4 years ago

@KMatuszak do an npm install ac-opensource/facebook-chat-api for now, I fixed it on mine

AstroCB commented 4 years ago

Listen is still not working for me, even with @ac-opensource's fix.

ghost commented 4 years ago

For me it works after @ac-opensource fix, but it looks like listenMqtt is listening by default for everything, not only for messages.

HossamMohsen7 commented 4 years ago

@KMatuszak yeah sorry will fix that

HossamMohsen7 commented 4 years ago

Issue fixed. Yes, listenMqtt listens for everything that listen was polling.

HossamMohsen7 commented 4 years ago

@KMatuszak Please tell me if you find any errors.

HossamMohsen7 commented 4 years ago

@AstroCB is there any logs you could provide?

ghost commented 4 years ago

Everything works fine now for me :slightly_smiling_face:

ghost commented 4 years ago

@7osCraft Out of curiosity, I will ask if these changes related to MQTT can have any effect on the speed of message capture? After these changes my bot responds much faster.

PixelHir commented 4 years ago

Shouldn't we just replace the listen function with mqtt?

The .listen() is obsolete anyway now and they work basically in the same way.

PixelHir commented 4 years ago

Shouldn't we just replace the listen function with mqtt?

The .listen() is obsolete anyway now and they work basically in the same way.

I actually take that back, .getUserInfo() now only returns an array of ids i submitted

[ '100010956664***', '100015763590***', '100017030117***', '100036272225***', '100028694583***', '100011812170***', '100022199253***', '100027434141***', '100009891793***', '100012392437***' ]

dinhphuc commented 4 years ago

@7osCraft Maybe merge not yet. How to use this?

HossamMohsen7 commented 4 years ago

@KMatuszak Yes it's actually faster. Before mqtt it was polling facebook servers at some rate which I think the maximum is 250ms. But now with the mqtt protocol it's faster because you're just waiting for messages from the server and the connection is always open and no polling/requesting is happening.

HossamMohsen7 commented 4 years ago

@PixelHir I didn't change any other function so mqtt changes shouldn't affect getUserInfo. I'll test to see if facebook changed something.

HossamMohsen7 commented 4 years ago

@seakBz npm install 7osCraft/facebook-chat-api

AstroCB commented 4 years ago

Working perfectly for me now!

ghost commented 4 years ago

@7osCraft After a few hours of running my bot I got this error:

C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:223
                                                delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
                                                                                         ^

TypeError: Cannot read property 'data' of undefined
    at parseDelta (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:223:48)
    at MqttClient.<anonymous> (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:91:5)
    at MqttClient.emit (events.js:210:5)
    at MqttClient._handlePublish (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:1162:12)
    at MqttClient._handlePacket (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:351:12)
    at work (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:283:12)
    at Writable.writable._write (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:294:5)
    at doWrite (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at Writable.write (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:334:11)
    at Duplexify.ondata (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:619:20)
    at Duplexify.emit (events.js:210:5)
    at addChunk (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Duplexify.Readable.push (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:245:10)
    at Duplexify._forward (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\index.js:170:26)
PixelHir commented 4 years ago

@PixelHir I didn't change any other function so mqtt changes shouldn't affect getUserInfo. I'll test to see if facebook changed something.

I think that facebook is sending data in a different way now, I can try inspecting it later

HossamMohsen7 commented 4 years ago

@7osCraft After a few hours of running my bot I got this error:

C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:223
                                                delta.deltaMessageReply.repliedToMessage.data === undefined ? [] :
                                                                                         ^

TypeError: Cannot read property 'data' of undefined
    at parseDelta (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:223:48)
    at MqttClient.<anonymous> (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\facebook-chat-api\src\listenMqtt.js:91:5)
    at MqttClient.emit (events.js:210:5)
    at MqttClient._handlePublish (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:1162:12)
    at MqttClient._handlePacket (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:351:12)
    at work (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:283:12)
    at Writable.writable._write (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\lib\client.js:294:5)
    at doWrite (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at Writable.write (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:334:11)
    at Duplexify.ondata (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:619:20)
    at Duplexify.emit (events.js:210:5)
    at addChunk (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Duplexify.Readable.push (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:245:10)
    at Duplexify._forward (C:\Users\Administrator\Downloads\messenger-bot-node\node_modules\duplexify\index.js:170:26)

@KMatuszak I think that happened to me once in the old polling system. Will push and update right now.

HossamMohsen7 commented 4 years ago

@KMatuszak Pushed an update. Could you please try now?

ghost commented 4 years ago

Yup, but i need some time to make sure the error will not occur again.

ghost commented 4 years ago

Now it spams JSON's in the console 😛

HossamMohsen7 commented 4 years ago

Yeah that was a mistake I need to fix it

HossamMohsen7 commented 4 years ago

@KMatuszak All good now please install again and sorry for that

ghost commented 4 years ago

Now everything is working perfectly, thank you 🙂

thanhdatpd commented 4 years ago

@7osCraft Hi, after run listenMqtt about 2 hour or early, it throw an error: ERR! Error: Connection refused: Server unavailable then all devices session expired (facebook/messager app,web) and need login again. I just run some time and not sure when it crash, did you face it? I will use log silly to see more and post here for error. Sorry, my English so bad :((

Edit 1: i trying run until now is 4 hour without any error, why?

Tanuki33 commented 4 years ago

@seakBz npm install 7osCraft/facebook-chat-api

i use this, and this hapend

ERR! markAsRead   error: 1357031,
ERR! markAsRead   errorSummary: 'This content is no longer available',
ERR! markAsRead   errorDescription: 'The content you requested cannot be displayed at the moment. It may be temporarily unavailable, the link you clicked on may have expired or you may not have permission to view this page.',
ERR! markAsRead   payload: null,
ERR! markAsRead   bootloadable: {},
ERR! markAsRead   ixData: {},
ERR! markAsRead   bxData: {},
ERR! markAsRead   gkxData: {},
ERR! markAsRead   qexData: {},
ERR! markAsRead   lid: '6764586712811045864' }
{ __ar: 1,
  error: 1357031,
  errorSummary: 'This content is no longer available',
  errorDescription: 'The content you requested cannot be displayed at the moment. It may be temporarily unavailable, the link you clicked on may have expired or you may not have permission to view this page.',
  payload: null,
  bootloadable: {},
  ixData: {},
  bxData: {},
  gkxData: {},
  qexData: {},
  lid: '6764586712811045864' }

but the bot working fine

PixelHir commented 4 years ago

@seakBz npm install 7osCraft/facebook-chat-api

i use this, and this hapend

ERR! markAsRead   error: 1357031,
ERR! markAsRead   errorSummary: 'This content is no longer available',
ERR! markAsRead   errorDescription: 'The content you requested cannot be displayed at the moment. It may be temporarily unavailable, the link you clicked on may have expired or you may not have permission to view this page.',
ERR! markAsRead   payload: null,
ERR! markAsRead   bootloadable: {},
ERR! markAsRead   ixData: {},
ERR! markAsRead   bxData: {},
ERR! markAsRead   gkxData: {},
ERR! markAsRead   qexData: {},
ERR! markAsRead   lid: '6764586712811045864' }
{ __ar: 1,
  error: 1357031,
  errorSummary: 'This content is no longer available',
  errorDescription: 'The content you requested cannot be displayed at the moment. It may be temporarily unavailable, the link you clicked on may have expired or you may not have permission to view this page.',
  payload: null,
  bootloadable: {},
  ixData: {},
  bxData: {},
  gkxData: {},
  qexData: {},
  lid: '6764586712811045864' }

but the bot working fine

This message shows up when youre accessing something that Facebook doesnt allow you to Can you try removing the markAsRead function?

Tanuki33 commented 4 years ago

yey no more err spam and bot run faster! ty! 👍

kentnek commented 4 years ago

listenMqtt works great so far, however events (message.type === "event") are not picked up.

HossamMohsen7 commented 4 years ago

@kentnek Make sure listenEvents is set to true in the options.

kentnek commented 4 years ago

@7osCraft it's always been true in my code. Below is my setup:

api.setOptions({
  logLevel: "warn",   
  listenEvents: true,
  forceLogin: true
});
PixelHir commented 4 years ago

For some reason, this happens Screenshot_20191203-091118

Not sure why it happened, the code was running in background

Tanuki33 commented 4 years ago

EDIT : i reinstall 7osCraft/facebook-chat-api , work again.. I just realized today, handleMessageRequest not working.

      api.getThreadList(1000, null, ["PENDING"], (err, list) => {
        if (err) return console.error(err.errorSummary);
        for (var prop in list) {
          if (list.hasOwnProperty(prop)) {
            api.handleMessageRequest(list[prop].threadID, true, err => {
              console.log(err);
            });
            console.log("is grup? = " + list[prop].isGroup +"\n" + list[prop].name + "\nCannot Reply? = " + list[prop].cannotReplyReason;
            );
          }
        }

no error output

Tanuki33 commented 4 years ago

For some reason, this happens Screenshot_20191203-091118

Not sure why it happened, the code was running in background

i got this to when use changenickname (on my case) try to reinstall 7osCraft/facebook-chat-api module