Open amirpdlll opened 4 years ago
I'll look at it later. But for now, could you turn on debugging.
I have created .env file in root and I have added this line DEBUG=ig:*
I checked it again I face same error and there is extra information
ig:mqtt:mqttot edge-mqtt.facebook.com:443: Disconnected. +0ms
what is wrong ? how can I fix it ?
thanks
I'll look at it later. But for now, could you turn on debugging.
In command line I see these commands
Device off ig:mqtt:realtime:direct Updated foreground state: {"inForegroundApp":false,"inForegroundDevice":false,"keepAliveTimeout":900} +0ms In App ig:mqtt:realtime:direct Updated foreground state: {"inForegroundApp":true,"inForegroundDevice":true,"keepAliveTimeout":60} +2s
and about one minute after it , it gets disconnected.
if this is the problem 'keepAliveTimeout' how can I increase it ?
I'll look at it later. But for now, could you turn on debugging.
In command line I see these commands
Device off ig:mqtt:realtime:direct Updated foreground state: {"inForegroundApp":false,"inForegroundDevice":false,"keepAliveTimeout":900} +0ms In App ig:mqtt:realtime:direct Updated foreground state: {"inForegroundApp":true,"inForegroundDevice":true,"keepAliveTimeout":60} +2s
and about one minute after it , it gets disconnected.
if this is the problem 'keepAliveTimeout' how can I increase it ?
I have increased it but nothing changed !
I'm experiencing the same problem. For now, you can try an older version (0.1.x). Edit: seems like the old version still works fine
I'm experiencing the same problem. For now, you can try an older version (0.1.x). Edit: seems like the old version still works fine
Thanks you ,
I have used https://github.com/Nerixyz/instagram_mqtt#below-015-old
and now my code is
import {FbnsClient, RealtimeClient} from './src';
import {IgApiClient} from 'instagram-private-api';
(async () => {
const ig = new IgApiClient();
// norm
```al login
ig.state.generateDevice('USERNAME');
await ig.account.login('USERNAME', 'PASSWORD');
// now `ig` is a client with a valid session
// Initialize the client
// This includes logging in (if you are below 0.1.6)
// ig.account.login ...
const fbns = new FbnsClient(ig);
await fbns.connect();
const realtime = new RealtimeClient(ig);
await realtime.connect();
console.log('we are here');
// whenever something gets sent and has no event, this is called
realtime.on('receive', (topic, messages) => {
console.log('receive', topic, messages);
});
realtime.on('direct', (messages) => {
console.log('receive2');
});
// this is called with a wrapper use {message} to only get the message from the wrapper
realtime.on('message', (messages) => {
console.log('receive2');
});
})();
but I think I made mistake because I'm newbie , actually I don't know how to grab new messages and I didn't find example , when I launch this I just got this :
https://prnt.sc/qy1uss
Can you please provide example of using old version ?
thank you
In a new folder I have installed this version and using example in the tree that you mentioned I created example.ts
this is the code
> import { IgApiClientRealtime, withRealtime } from './src';
> import { GraphQLSubscriptions } from './src/realtime/subscriptions';
> import { IgApiClient } from 'instagram-private-api';
> import { SkywalkerSubscriptions } from './src/realtime/subscriptions';
>
> (async () => {
> // this extends the IgApiClient with realtime features
> const ig: IgApiClientRealtime = withRealtime(new IgApiClient());
> // normal login
> ig.state.generateDevice('USERNAME');
> await ig.account.login('USERNAME', 'PASSWORD');
> // now `ig` is a client with a valid session
>
> // an example on how to subscribe to live comments
> const subToLiveComments = (broadcastId) =>
> // you can add other GraphQL subs using .subscribe
> ig.realtime.graphQlSubscribe(GraphQLSubscriptions.getLiveRealtimeCommentsSubscription(broadcastId));
>
> // whenever something gets sent and has no event, this is called
> ig.realtime.on('receive', (topic, messages) => {
> console.log('receive', topic, messages);
> });
> ig.realtime.on('direct', logEvent('direct'));
> // this is called with a wrapper use {message} to only get the message from the wrapper
> ig.realtime.on('message', logEvent('messageWrapper'));
> // whenever something gets sent to /ig_realtime_sub and has no event, this is called
> ig.realtime.on('realtimeSub', logEvent('realtimeSub'));
> // whenever the client has a fatal error
> ig.realtime.on('error', console.error);
> ig.realtime.on('close', () => console.error('RealtimeClient closed'));
> // connect
> // this will resolve once all initial subscriptions have been sent
> await ig.realtime.connect({
> // optional
> graphQlSubs: [
> // these are some subscriptions
> GraphQLSubscriptions.getAppPresenceSubscription(),
> GraphQLSubscriptions.getClientConfigUpdateSubscription(),
> GraphQLSubscriptions.getZeroProvisionSubscription(ig.state.phoneId),
> GraphQLSubscriptions.getDirectStatusSubscription(),
> GraphQLSubscriptions.getDirectTypingSubscription(ig.state.cookieUserId),
> GraphQLSubscriptions.getAsyncAdSubscription(ig.state.cookieUserId),
> ],
> // optional
> skywalkerSubs: [
> SkywalkerSubscriptions.directSub(ig.state.cookieUserId),
> SkywalkerSubscriptions.liveSub(ig.state.cookieUserId)
> ],
> // optional
> // this enables you to get direct messages
> irisData: await ig.feed.directInbox().request(),
> // optional
> // in here you can change connect options
> // available are all properties defined in MQTToTConnectionClientInfo
> connectOverrides: {
> },
> });
>
> // simulate turning the device off after 2s and turning it back on after another 2s
> setTimeout(() => {
> console.log('Device off');
> // from now on, you won't receive any realtime-data as you "aren't in the app"
> // the keepAliveTimeout is somehow a 'constant' by instagram
> ig.realtime.direct.sendForegroundState({inForegroundApp: false, inForegroundDevice: false, keepAliveTimeout: 900});
> }, 2000);
> setTimeout(() => {
> console.log('In App');
> ig.realtime.direct.sendForegroundState({inForegroundApp: true, inForegroundDevice: true, keepAliveTimeout: 60});
> }, 4000);
> })();
>
> /**
> * A wrapper function to log to the console
> * @param name
> * @returns {(data) => void}
> */
> function logEvent(name) {
> return data => console.log(name, data);
> }
when I launch it using ts-node example.ts
I face this error
I don't know may be I'm making mistake !
After ig.state.generateDevice('USERNAME');
add await ig.qe.syncLoginExperiments()
Version 0.2.1
might fix your issue.
Version
0.2.1
might fix your issue.
thank you so much , for now I'm testing 1.1 , this is good but on windows some time it break and get back to command line This is my command line : https://prnt.sc/qy42wk
I'm going to test v 2.1 thank you
Version
0.2.1
might fix your issue.
Thank you , I have tested 2.1 and seems it is working properly , thank to you and your support :)
Version
0.2.1
might fix your issue.
How can I get user_id and send response? there was not send direct message and response in example !
Version
0.2.1
might fix your issue. thank you so much ,Version
0.2.1
might fix your issue.How can I get user_id and send response? there was not send direct message and response in example !
Found https://github.com/Nerixyz/instagram_mqtt/issues/12 thank you
unfortunately , 2.1 is like 2.0 and it got disconnected after about 1 or 2 minutes , is there any way to solve it ? thanks
when I use 1.17 in command line , without raising any error it exit operating https://prnt.sc/qz957p
beside when I'm using fbns (push in example) I get igSentryBlockError
why is it happening and how can I fix it ? thanks
Disabling getClientConfigUpdateSubscription and getZeroProvisionSubscription works. I don't know why that's the case.
I'm getting the same error (using 0.2.1).
I also receive all events twice... 🤔 For example:
ig.fbns.push$.subscribe((data) => {
if(data.collapseKey === "direct_v2_message"){
console.log('message received', data.message)
}
});
For one message sent, it logs two "message received" (with the same content).
Disabling getClientConfigUpdateSubscription and getZeroProvisionSubscription works. I don't know why that's the case.
after disabling it's working thanks
I'm getting the same error (using 0.2.1).
I'm using V 1.17 and real time , for now it's working good , try it
Ah, I'm using the FBNS client.
Ah, I'm using the FBNS client.
Why you don't use real time ?
Is it better? I need to trigger a function when a message is received, and as I'm making a chatbot I need to keep the bot logged forever.
Is it better? I need to trigger a function when a message is received, and as I'm making a chatbot I need to keep the bot logged forever.
Realtime would be in this case more reliable. The notifications are managed by facebook and if you're receiving many messages at once, it will omit some notifications. Realtime on the other hand will most likely still send the messages. And in addition you can get the entire message/image etc. and you don't have to fetch this on your own.
I tested realtime and that's amazing! 😮 Thank you so much @Nerixyz!
What is the right way to keep connection for long time?
So, now I am using all tips above. But where can I catch MQTT Client disconnect rightly?
'error'
event or 'disconnect'
? And then, should I call realtime.connect
as a first times or there is a method to reconnecting?
I am using instagram-mqtt@0.2.13
But where can I catch MQTT Client disconnect rightly?
Currently, an error is emitted if the connection is closed unexpectedly. If you call.disconnect()
, the disconnect
event is fired.
So, I need write something like
realtime.on('error', err => {
if (disconnect_error) {
//realtime.connect as first times
}
})
yes? And will my handlers working with new connection (as error
handler)?
So, I need write something like
I just updated the package (0.2.14). Now, the client reconnects (and subscribes) automatically so you don't have to do anything.
Vielen Dank, ich hoffe, dass ich keine Probleme haben werde.
So, I need write something like
I just updated the package (0.2.14). Now, the client reconnects (and subscribes) automatically so you don't have to do anything.
Hey @Nerixyz great work, but i am using 0.2.16 with both Realtime and Fbns . my connection is still disconnecting after some time and not reconnecting what should i do. thanks
Same for me! It closes the node process... and never reconnects (as the node process is closed).
ClientDisconnectedError: MQTToTClient got disconnected.
at SafeSubscriber._next (/home/container/node_modules/instagram_mqtt/dist/realtime/realtime.client.js:152:30)
at SafeSubscriber.__tryOrUnsub (/home/container/node_modules/rxjs/internal/Subscriber.js:205:16)
at SafeSubscriber.next (/home/container/node_modules/rxjs/internal/Subscriber.js:143:22)
at Subscriber._next (/home/container/node_modules/rxjs/internal/Subscriber.js:89:26)
at Subscriber.next (/home/container/node_modules/rxjs/internal/Subscriber.js:66:18)
at Subject.next (/home/container/node_modules/rxjs/internal/Subject.js:60:25)
at MQTToTClient.setDisconnected (/home/container/node_modules/mqtts/dist/mqtt.client.js:329:30)
at Object.disconnect (/home/container/node_modules/mqtts/dist/mqtt.client.js:97:26)
at TLSSocket.<anonymous> (/home/container/node_modules/mqtts/dist/transport/tls.transport.js:20:52)
at TLSSocket.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
There's a "new" alpha version which aims to fix some of these issues by not usign rxjs and instead relying on regular events and streams. The events are fully typed so they will work fine with TypeScript. There should also be autocomplete support (at least in WebStorm) for the events. You can get the alpha version here (it's on the alpha
branch).
I'm testing it, but I made my own parser for iris messages. Is there still a way to receive all iris messages as they are, without being parsed?
Is there still a way to receive all iris messages as they are, without being parsed?
There are Mixins now, you may want to use them (like the other ones do). But what's the problem with the parsing?
There are Mixins now, you may want to use them (like the other ones do).
All right 👍
But what's the problem with the parsing?
I made my own parser, so it means I have to rewrite it?
I made my own parser, so it means I have to rewrite it?
If you still have a need for it, yeah. But the only difference was the handling of direct_v2/inbox
which will be sent on threadUpdate
.
How about this error? @Nerixyz ? i'm using alpha latest version. how to get connect again
how to get connect again
If you're using the default settings, then the client should reconnect automatically. The error is emitted either way. If the client doesn't reconnect, please paate the debug log here (DEBUG=*
).
how to get connect again
If you're using the default settings, then the client should reconnect automatically. The error is emitted either way. If the client doesn't reconnect, please paate the debug log here (
DEBUG=*
).
Hi @Nerixyz thanks for answer, btw can you give me a fbns example for alpha version?
Hi @Nerixyz Thanks!
i just tested and working
before i using await ig.fbns.connect( { autoReconnect:true } )
fix by await ig.fbns.connect()
There's a "new" alpha version which aims to fix some of these issues by not usign rxjs and instead relying on regular events and streams. The events are fully typed so they will work fine with TypeScript. There should also be autocomplete support (at least in WebStorm) for the events. You can get the alpha version here (it's on the
alpha
branch).
Hey @Nerixyz @Androz2091 , i am not able to use the alpha and got following error after installing
i am using
WebStorm IDE Node 10.13.0 OS Linux Fedora 30 Package Manager YARN
i have also tried NPM but when i install it with npm it gives error instagram-private-api not found at run time but it actually installed
@jafferkazmi572 You have to update your node to at least v.12.
@jafferkazmi572 You have to update your node to at least v.12.
Ok Thanks
The library is working fine and I appreciate you , but when I connect using command line windows with command
first every thing works fine and all events are printing , but after about one minute I face error
Please see this image is taken from command line https://prnt.sc/qxvzji
thanks