2023-10-09 05:59:48 +03:00
|
|
|
import { BaseTelegramClient, Long } from '@mtcute/core'
|
2023-10-16 19:23:53 +03:00
|
|
|
import { assertTypeIs } from '@mtcute/core/utils.js'
|
2023-09-22 15:32:28 +03:00
|
|
|
|
2023-10-16 19:23:53 +03:00
|
|
|
import { User } from '../../types/index.js'
|
2021-04-25 17:10:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get list of contacts from your Telegram contacts list.
|
|
|
|
*/
|
2023-10-09 05:59:48 +03:00
|
|
|
export async function getContacts(client: BaseTelegramClient): Promise<User[]> {
|
|
|
|
const res = await client.call({
|
2021-04-25 17:10:37 +03:00
|
|
|
_: 'contacts.getContacts',
|
2021-11-23 00:03:59 +03:00
|
|
|
hash: Long.ZERO,
|
2021-04-25 17:10:37 +03:00
|
|
|
})
|
|
|
|
assertTypeIs('getContacts', res, 'contacts.contacts')
|
|
|
|
|
2023-10-09 05:59:48 +03:00
|
|
|
return res.users.map((user) => new User(user))
|
2021-04-25 17:10:37 +03:00
|
|
|
}
|