contacts.GetTopPeers
Get most used peers
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.GetTopPeers({
offset: 43,
limit: 100,
hash: BigInt("-4156887774564"),
correspondents: true,
botsPm: true,
botsInline: true,
phoneCalls: true,
forwardUsers: true,
forwardChats: true,
groups: true,
channels: true,
})
);
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.contacts.TopPeers = await client.invoke(
new Api.contacts.GetTopPeers({
offset: 43,
limit: 100,
hash: BigInt("-4156887774564"),
correspondents: true,
botsPm: true,
botsInline: true,
phoneCalls: true,
forwardUsers: true,
forwardChats: true,
groups: true,
channels: true,
})
);
console.log(result); // prints the result
})();
Parameters
| Name | Type | Description |
|---|---|---|
| flags | # | Flags, see TL conditional fields |
| correspondents | flags.0?true | Users we've chatted most frequently with |
| botsPm | flags.1?true | Most used bots |
| botsInline | flags.2?true | Most used inline bots |
| phoneCalls | flags.3?true | Most frequently called users |
| forwardUsers | flags.4?true | Users to which the users often forwards messages to |
| forwardChats | flags.5?true | Chats to which the users often forwards messages to |
| groups | flags.10?true | Often-opened groups and supergroups |
| channels | flags.15?true | Most frequently visited channels |
| offset | int | Offset for pagination |
| limit | int | Maximum number of results to return, see pagination |
| hash | long | Hash for pagination, for more info click here |
Result
Possible errors
| Code | Type | Description |
|---|---|---|
| 400 | TYPES_EMPTY | No top peer type was provided. |
Can bots use this method?
No
Related pages
Pagination in the API
How to fetch results from large lists of objects.