How to use a Test DC?
I need to use a Test DC during development. I've tried to use the code:
client.session.setDC(dcNumber, IP, port)
as well as
stringSession.setDC(dcNumber, IP, port)
But the client still automatically connects to the real DC instead and I don't know of a way to change the DC. So in my case it ends up connecting to vesta.web.telegram.org.
I have passed in my Test DC parameters to the function call obtained from my.telegram.org.
Would be much appreciated if anyone knows how to change to a Test DC using this library. Thanks in advance.
are you running it in node or browser? I don't think those methods work in browsers because the DC domains are hardcoded there.
I'm running it in the browser. Is there no way for me to change to a Test DC on the browser version?
Reason being, during development I may need to keep signing in and out of telegram so will end up hitting the flood limit. You mentioned the DCs are hardcoded, I think you're referring to the 4 DCs that telegram have, that's fine those need to be hard coded anyway.
The only thing I need is to be able to connect to a DC with a test number and test IP which I got from my.telegram.org. But even that doesn't work when I call SetDC. It keeps getting overridden by the code that's already been written in the library somewhere.
I used another library in Flutter called TDLib and that allowed me to use a TestDC but that library is not even maintained nor does it have nearly as many features as this library provides. I like this library because it's based off of Telethon so it has everything I need except the fact that somehow I can't connect to a TestDC lol. That's the one thing I'm missing right now.
You'll need to change it manually for now. there is a function https://github.com/gram-js/gramjs/blob/89e62a66f00415358ab504fd32118641c2417f0c/gramjs/extensions/PromisedWebSockets.ts#L68 that's called getWebSocketLink you need to patch that and add _test at the end to use test servers so something like this
getWebSocketLink(ip: string, port: number) {
if (port === 443) {
return `wss://${ip}:${port}/apiws_test`;
} else {
return `ws://${ip}:${port}/apiws_test`;
}
}
Oh nice, thanks. I'll try give it a go and see if it works.
You'll need to change it manually for now. there is a function
https://github.com/gram-js/gramjs/blob/89e62a66f00415358ab504fd32118641c2417f0c/gramjs/extensions/PromisedWebSockets.ts#L68
that's called
getWebSocketLinkyou need to patch that and add _test at the end to use test servers so something like thisgetWebSocketLink(ip: string, port: number) { if (port === 443) { return `wss://${ip}:${port}/apiws_test`; } else { return `ws://${ip}:${port}/apiws_test`; } }
What should I do if I'm running in node
you can use https://gram.js.org/beta/classes/sessions_abstract.session.html#setdc with the ip/port of the test server (you can find those in the same page you got your api_id,hash from)