Skip to content

Instantly share code, notes, and snippets.

@painor
Created February 9, 2022 21:41
Show Gist options
  • Save painor/f660ed42b94fa4b4cb0bd33ca9b595af to your computer and use it in GitHub Desktop.
Save painor/f660ed42b94fa4b4cb0bd33ca9b595af to your computer and use it in GitHub Desktop.
Make a call in telegram using GramJS
import { StoreSession} from "telegram/sessions";
import { TelegramClient } from "telegram/client/TelegramClient";
import { Api } from "./tl";
import { generateRandomBigInt, readBigIntFromBuffer, readBufferFromBigInt, sha256 } from "telegram/Helpers";
import bigInt from "big-integer";
const apiId = ;
const apiHash = "";
(async () => {
console.log("Loading interactive example...");
const session = new StoreSession("my_session");
const client = new TelegramClient(session, apiId, apiHash, {});
await client.connect();
const dhConfig = await client.invoke(new Api.messages.GetDhConfig({
version: 0,
randomLength: 256
}));
if (dhConfig instanceof Api.messages.DhConfigNotModified) {
throw Error("Invalid DHConfig");
}
let a = bigInt.zero;
let p = readBigIntFromBuffer(dhConfig.p, false, false);
let g = bigInt(dhConfig.g);
while (!(bigInt.one.lesser(a) && a.lesser(p.minus(1)))) {
a = generateRandomBigInt();
}
const ga = g.modPow(a, p);
const gaHash = await sha256(readBufferFromBigInt(ga, 256, false, false));
const userToCall = "username";
const res = await client.invoke(new Api.phone.RequestCall({
userId: userToCall,
gAHash: gaHash,
randomId: Math.floor(Math.random() * 0x7ffffffa),
protocol: new Api.PhoneCallProtocol({
minLayer: 93,
maxLayer: 93,
udpP2p: true,
udpReflector: true,
libraryVersions: [
// taken from TDESKTOP
"4.0.0",
"3.0.0",
"2.7.7",
"2.4.4"
]
})
}));
console.log("CALL HAS STARTED!");
console.log("res is", res);
//await client.sendMessage("me", { message: "Hello!" });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment