GramJS

contacts.AcceptContact

If the peer settings of a new user allow us to add them as contact, add that user as contact

Example

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.AcceptContact({
      id: "username",
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "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: Api.Updates = await client.invoke(
    new Api.contacts.AcceptContact({
      id: "username",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
idInputUserThe user to add as contact

Result

Updates

Possible errors

CodeTypeDescription
400CONTACT_ADD_MISSINGContact to add is missing.
400CONTACT_ID_INVALIDThe provided contact ID is invalid.
400CONTACT_REQ_MISSINGMissing contact request.
400MSG_ID_INVALIDInvalid message ID provided.

Can bots use this method?

No

peerSettings

List of actions that are possible when interacting with this user, to be shown as suggested actions in the chat bar