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
Name | Type | Description |
---|---|---|
id | InputUser | The user to add as contact |
Result
Possible errors
Code | Type | Description |
---|---|---|
400 | CONTACT_ADD_MISSING | Contact to add is missing. |
400 | CONTACT_ID_INVALID | The provided contact ID is invalid. |
400 | CONTACT_REQ_MISSING | Missing contact request. |
400 | MSG_ID_INVALID | Invalid message ID provided. |
Can bots use this method?
No
Related pages
peerSettings
List of actions that are possible when interacting with this user, to be shown as suggested actions in the chat bar