Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Error when use api.listenMQTT (SyntaxError: Unexpected token ↓ in JSON at position 0) #898

Closed
kiznick opened this issue Dec 27, 2021 · 1 comment

Comments

@kiznick
Copy link

kiznick commented Dec 27, 2021

Error when use api.listenMqtt
Code

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


login({appState: JSON.parse(fs.readFileSync('appstate.json', 'utf8'))}, (err, api) => {
    if(err) return console.error(err);
    console.log(`[/] Login Success`);

    api.setOptions({
        listenEvents: true,
        selfListen: true
    });

    console.log(`[!] Start Listening`);
    
    let stopListening = api.listenMqtt((err, event) => {
        if(err) return console.error(err);
        console.log(event);
    });
});

Error

undefined:1
↓<%�☺↓♣
^

SyntaxError: Unexpected token ↓ in JSON at position 0
    at JSON.parse (<anonymous>)
    at MqttClient.<anonymous> (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\facebook-chat-api\src\listenMqtt.js:117:28)
    at MqttClient.emit (node:events:369:20)
    at MqttClient._handlePublish (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\lib\client.js:1162:12)
    at MqttClient._handlePacket (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\lib\client.js:351:12)
    at work (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\lib\client.js:283:12)
    at Writable.writable._write (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\lib\client.js:294:5)
    at doWrite (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at Writable.write (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:334:11)
    at Duplexify.ondata (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:619:20)
    at Duplexify.emit (node:events:369:20)
    at addChunk (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Duplexify.Readable.push (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:245:10)
    at Duplexify._forward (C:\Users\admin\Desktop\nodejs\fbapi\node_modules\duplexify\index.js:170:26)
@kiznick
Copy link
Author

kiznick commented Dec 27, 2021

Edit listenMqtt.js follow pull request #897

@kiznick kiznick closed this as completed Dec 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant