gram-js/gramjs add contact to contact list by phone number

305 Views Asked by At

there is add contact method but it ask parameter of user id how can i get the user id of telegram members by there phone

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.contacts.AddContact({
      id: "username",
      firstName: "some string here",
      lastName: "some string here",
      phone: "some string here",
      addPhonePrivacyException: true,
    })
  );
  console.log(result); // prints the result
})();

and also getEntity(entity: EntityLike) Using phone numbers (from people in your contact list)

and also this

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.contacts.ResolvePhone({
      phone: "some string here",
    })
  );
  console.log(result); // prints the result
})();

how can I get the users id by there phone number which is not my contact

0

There are 0 best solutions below