feat!: updated to 177 layer
breaking: `.createGroup` now returns `CreateGroupResult`
This commit is contained in:
parent
dc1624e8bc
commit
bf2f7999a6
9 changed files with 52 additions and 18 deletions
|
@ -36,7 +36,7 @@ describe('5. worker', async function () {
|
|||
|
||||
it('should throw errors', async function () {
|
||||
try {
|
||||
await port.call({ _: 'test.useError' })
|
||||
await port.call({ _: 'test.useConfigSimple' })
|
||||
throw new Error('should have thrown')
|
||||
} catch (e) {
|
||||
expect(e).to.be.an.instanceOf(tl.RpcError)
|
||||
|
|
|
@ -42,7 +42,7 @@ import { addChatMembers } from './methods/chats/add-chat-members.js'
|
|||
import { archiveChats } from './methods/chats/archive-chats.js'
|
||||
import { banChatMember } from './methods/chats/ban-chat-member.js'
|
||||
import { createChannel } from './methods/chats/create-channel.js'
|
||||
import { createGroup } from './methods/chats/create-group.js'
|
||||
import { createGroup, CreateGroupResult } from './methods/chats/create-group.js'
|
||||
import { createSupergroup } from './methods/chats/create-supergroup.js'
|
||||
import { deleteChannel } from './methods/chats/delete-channel.js'
|
||||
import { deleteChatPhoto } from './methods/chats/delete-chat-photo.js'
|
||||
|
@ -1175,6 +1175,7 @@ export interface TelegramClient extends ITelegramClient {
|
|||
*
|
||||
* @param chatId ID of the chat or its username
|
||||
* @param users ID(s) of the user(s) to add
|
||||
* @returns List of users that were failed to be invited (may be empty)
|
||||
*/
|
||||
addChatMembers(
|
||||
chatId: InputPeerLike,
|
||||
|
@ -1188,7 +1189,7 @@ export interface TelegramClient extends ITelegramClient {
|
|||
*/
|
||||
forwardCount?: number
|
||||
},
|
||||
): Promise<void>
|
||||
): Promise<tl.RawMissingInvitee[]>
|
||||
/**
|
||||
* Archive one or more chats
|
||||
*
|
||||
|
@ -1266,7 +1267,7 @@ export interface TelegramClient extends ITelegramClient {
|
|||
* @default 0 (i.e. messages don't expire)
|
||||
*/
|
||||
ttlPeriod?: number
|
||||
}): Promise<Chat>
|
||||
}): Promise<CreateGroupResult>
|
||||
/**
|
||||
* Create a new supergroup
|
||||
*
|
||||
|
|
|
@ -32,6 +32,7 @@ export { addChatMembers } from './methods/chats/add-chat-members.js'
|
|||
export { archiveChats } from './methods/chats/archive-chats.js'
|
||||
export { banChatMember } from './methods/chats/ban-chat-member.js'
|
||||
export { createChannel } from './methods/chats/create-channel.js'
|
||||
export type { CreateGroupResult } from './methods/chats/create-group.js'
|
||||
export { createGroup } from './methods/chats/create-group.js'
|
||||
export { createSupergroup } from './methods/chats/create-supergroup.js'
|
||||
export { deleteChannel } from './methods/chats/delete-channel.js'
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { tl } from '@mtcute/tl'
|
||||
|
||||
import { MaybeArray } from '../../../types/utils.js'
|
||||
import { ITelegramClient } from '../../client.types.js'
|
||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||
|
@ -10,6 +12,7 @@ import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
|||
*
|
||||
* @param chatId ID of the chat or its username
|
||||
* @param users ID(s) of the user(s) to add
|
||||
* @returns List of users that were failed to be invited (may be empty)
|
||||
*/
|
||||
export async function addChatMembers(
|
||||
client: ITelegramClient,
|
||||
|
@ -24,7 +27,7 @@ export async function addChatMembers(
|
|||
*/
|
||||
forwardCount?: number
|
||||
},
|
||||
): Promise<void> {
|
||||
): Promise<tl.RawMissingInvitee[]> {
|
||||
const { forwardCount = 100 } = params
|
||||
|
||||
const chat = await resolvePeer(client, chatId)
|
||||
|
@ -32,23 +35,31 @@ export async function addChatMembers(
|
|||
if (!Array.isArray(users)) users = [users]
|
||||
|
||||
if (isInputPeerChat(chat)) {
|
||||
const missing: tl.RawMissingInvitee[] = []
|
||||
|
||||
for (const user of users) {
|
||||
const p = await resolveUser(client, user)
|
||||
|
||||
const updates = await client.call({
|
||||
const { updates, missingInvitees } = await client.call({
|
||||
_: 'messages.addChatUser',
|
||||
chatId: chat.chatId,
|
||||
userId: p,
|
||||
fwdLimit: forwardCount,
|
||||
})
|
||||
client.handleClientUpdate(updates)
|
||||
missing.push(...missingInvitees)
|
||||
}
|
||||
|
||||
return missing
|
||||
} else if (isInputPeerChannel(chat)) {
|
||||
const updates = await client.call({
|
||||
const { updates, missingInvitees } = await client.call({
|
||||
_: 'channels.inviteToChannel',
|
||||
channel: toInputChannel(chat),
|
||||
users: await resolvePeerMany(client, users, toInputUser),
|
||||
})
|
||||
client.handleClientUpdate(updates)
|
||||
} else throw new MtInvalidPeerTypeError(chatId, 'chat or channel')
|
||||
|
||||
return missingInvitees
|
||||
}
|
||||
throw new MtInvalidPeerTypeError(chatId, 'chat or channel')
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { tl } from '@mtcute/tl'
|
||||
|
||||
import { MaybeArray } from '../../../types/utils.js'
|
||||
import { ITelegramClient } from '../../client.types.js'
|
||||
import { Chat, InputPeerLike } from '../../types/index.js'
|
||||
|
@ -5,6 +7,14 @@ import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
|||
import { toInputUser } from '../../utils/peer-utils.js'
|
||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||
|
||||
// @exported
|
||||
export interface CreateGroupResult {
|
||||
/** Chat that was created */
|
||||
chat: Chat
|
||||
/** Users that were failed to be invited */
|
||||
missing: tl.RawMissingInvitee[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a legacy group chat
|
||||
*
|
||||
|
@ -32,7 +42,7 @@ export async function createGroup(
|
|||
*/
|
||||
ttlPeriod?: number
|
||||
},
|
||||
): Promise<Chat> {
|
||||
): Promise<CreateGroupResult> {
|
||||
const { title } = params
|
||||
let { users } = params
|
||||
|
||||
|
@ -40,15 +50,18 @@ export async function createGroup(
|
|||
|
||||
const peers = await resolvePeerMany(client, users, toInputUser)
|
||||
|
||||
const res = await client.call({
|
||||
const { updates, missingInvitees } = await client.call({
|
||||
_: 'messages.createChat',
|
||||
title,
|
||||
users: peers,
|
||||
})
|
||||
|
||||
assertIsUpdatesGroup('messages.createChat', res)
|
||||
assertIsUpdatesGroup('messages.createChat', updates)
|
||||
|
||||
client.handleClientUpdate(res)
|
||||
client.handleClientUpdate(updates)
|
||||
|
||||
return new Chat(res.chats[0])
|
||||
return {
|
||||
chat: new Chat(updates.chats[0]),
|
||||
missing: missingInvitees,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
TL schema and related utils used for mtcute.
|
||||
|
||||
Generated from TL layer **176** (last updated on 17.03.2024).
|
||||
Generated from TL layer **177** (last updated on 01.04.2024).
|
||||
|
||||
## About
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -11,7 +11,10 @@
|
|||
"autoDownloadSettings": ["video_size_max", "file_size_max"],
|
||||
"botInfo": ["user_id"],
|
||||
"boost": ["user_id"],
|
||||
"botBusinessConnection": ["user_id"],
|
||||
"businessRecipients": ["users"],
|
||||
"businessBotRecipients": ["users", "exclude_users"],
|
||||
"contactBirthday": ["contact_id"],
|
||||
"channel": ["id"],
|
||||
"channelAdminLogEvent": ["user_id"],
|
||||
"channelAdminLogEventActionChangeLinkedChat": ["prev_value", "new_value"],
|
||||
|
@ -59,7 +62,7 @@
|
|||
"inputUserFromMessage": ["user_id"],
|
||||
"keyboardButtonUserProfile": ["user_id"],
|
||||
"mediaAreaChannelPost": ["channel_id"],
|
||||
"message": ["via_bot_id"],
|
||||
"message": ["via_bot_id", "via_business_bot_id"],
|
||||
"messageActionChannelMigrateFrom": ["chat_id"],
|
||||
"messageActionChatAddUser": ["users"],
|
||||
"messageActionChatCreate": ["users"],
|
||||
|
@ -74,10 +77,12 @@
|
|||
"messageUserVote": ["user_id"],
|
||||
"messageUserVoteInputOption": ["user_id"],
|
||||
"messageUserVoteMultiple": ["user_id"],
|
||||
"missingInvitee": ["user_id"],
|
||||
"payments.paymentForm": ["bot_id"],
|
||||
"payments.paymentReceipt": ["bot_id"],
|
||||
"peerChannel": ["channel_id"],
|
||||
"peerChat": ["chat_id"],
|
||||
"peerSettings": ["business_bot_id"],
|
||||
"peerUser": ["user_id"],
|
||||
"phoneCall": ["admin_id", "participant_id"],
|
||||
"phoneCallAccepted": ["admin_id", "participant_id"],
|
||||
|
@ -90,6 +95,9 @@
|
|||
"readParticipantDate": ["user_id"],
|
||||
"recentMeUrlChat": ["chat_id"],
|
||||
"recentMeUrlUser": ["user_id"],
|
||||
"requestedPeerChannel": ["chat_id"],
|
||||
"requestedPeerChat": ["chat_id"],
|
||||
"requestedPeerUser": ["user_id"],
|
||||
"secureFile": ["size"],
|
||||
"statsGroupTopAdmin": ["user_id"],
|
||||
"statsGroupTopInviter": ["user_id"],
|
||||
|
@ -144,7 +152,7 @@
|
|||
"updateUserTyping": ["user_id"],
|
||||
"user": ["id"],
|
||||
"userEmpty": ["id"],
|
||||
"userFull": ["id"],
|
||||
"userFull": ["id", "personal_channel_id"],
|
||||
"userStories": ["user_id"],
|
||||
"webAuthorization": ["bot_id"],
|
||||
"_": "Dummy line teehee~"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@mtcute/tl",
|
||||
"version": "176.0.0",
|
||||
"version": "177.0.0",
|
||||
"description": "TL schema used for mtcute",
|
||||
"main": "index.js",
|
||||
"author": "alina sireneva <alina@tei.su>",
|
||||
|
|
Loading…
Reference in a new issue