telegram api javascript

Solutions on MaxInterview for telegram api javascript by the best coders in the world

showing results for - "telegram api javascript"
Lucia
25 Jun 2016
1const { TelegramClient } = require("telegram");
2const { StringSession } = require("telegram/sessions");
3const input = require("input"); // npm i input
4
5const apiId = 123456;
6const apiHash = "123456abcdfg";
7const stringSession = new StringSession(""); // fill this later with the value from session.save()
8
9(async () => {
10  console.log("Loading interactive example...");
11  const client = new TelegramClient(stringSession, apiId, apiHash, {
12    connectionRetries: 5,
13  });
14  await client.start({
15    phoneNumber: async () => await input.text("Please enter your number: "),
16    password: async () => await input.text("Please enter your password: "),
17    phoneCode: async () =>
18      await input.text("Please enter the code you received: "),
19    onError: (err) => console.log(err),
20  });
21  console.log("You should now be connected.");
22  console.log(client.session.save()); // Save this string to avoid logging in again
23  await client.sendMessage("me", { message: "Hello!" });
24})();
25