refactor: prettier-ed code, rearranged imports, fixed tests
This commit is contained in:
parent
f2eb033e91
commit
e68c9f4bb5
318 changed files with 1623 additions and 1708 deletions
|
@ -6,3 +6,6 @@ src/tl/types.d.ts
|
||||||
src/tl/types.js
|
src/tl/types.js
|
||||||
src/tl/binary/reader.js
|
src/tl/binary/reader.js
|
||||||
src/tl/binary/writer.js
|
src/tl/binary/writer.js
|
||||||
|
|
||||||
|
**/dist
|
||||||
|
*.d.ts
|
||||||
|
|
13
package.json
13
package.json
|
@ -6,10 +6,9 @@
|
||||||
"license": "LGPL-3.0",
|
"license": "LGPL-3.0",
|
||||||
"author": "Alisa Sireneva <me@tei.su>",
|
"author": "Alisa Sireneva <me@tei.su>",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "lerna run test",
|
"test-all": "pnpm run -r test",
|
||||||
"build": "lerna run build",
|
"lint": "eslint \"packages/**/*.ts\"",
|
||||||
"lint": "eslint packages/**/*.ts",
|
"format": "prettier --write \"packages/**/*.ts\"",
|
||||||
"format": "prettier --write packages/**/*.ts",
|
|
||||||
"publish-all": "node scripts/publish.js all"
|
"publish-all": "node scripts/publish.js all"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -29,9 +28,9 @@
|
||||||
"mocha": "^9.2.2",
|
"mocha": "^9.2.2",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"prettier": "^2.6.2",
|
"prettier": "^2.6.2",
|
||||||
"ts-node": "^10.7.0",
|
"ts-node": "^10.8.1",
|
||||||
"typedoc": "^0.22.15",
|
"typedoc": "^0.23.2",
|
||||||
"typescript": "^4.6.4",
|
"typescript": "^4.7.4",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"dotenv-flow": "^3.2.0",
|
"dotenv-flow": "^3.2.0",
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
"license": "LGPL-3.0",
|
"license": "LGPL-3.0",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha -r ts-node/register tests/**/*.spec.ts",
|
"test": "mocha -r ts-node/register \"tests/**/*.spec.ts\"",
|
||||||
"docs": "npx typedoc",
|
"docs": "npx typedoc",
|
||||||
"build": "tsc"
|
"build": "tsc"
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,7 @@ export {
|
||||||
JsonFileStorage,
|
JsonFileStorage,
|
||||||
LocalstorageStorage,
|
LocalstorageStorage,
|
||||||
tl,
|
tl,
|
||||||
defaultDcs
|
defaultDcs,
|
||||||
} from '@mtcute/core'
|
} from '@mtcute/core'
|
||||||
|
|
||||||
export * from './types'
|
export * from './types'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { computeSrpParams } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { User } from '../../types'
|
import { User } from '../../types'
|
||||||
import { computeSrpParams } from '@mtcute/core'
|
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,9 +9,7 @@ import { TelegramClient } from '../../client'
|
||||||
* @returns On success, `true` is returned
|
* @returns On success, `true` is returned
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function logOut(
|
export async function logOut(this: TelegramClient): Promise<true> {
|
||||||
this: TelegramClient
|
|
||||||
): Promise<true> {
|
|
||||||
await this.call({ _: 'auth.logOut' })
|
await this.call({ _: 'auth.logOut' })
|
||||||
|
|
||||||
this._userId = null
|
this._userId = null
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { SentCode } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { SentCode } from '../../types'
|
||||||
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { SentCode } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { SentCode } from '../../types'
|
||||||
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { User } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { User } from '../../types'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { User, TermsOfService } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { User, TermsOfService } from '../../types'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { User } from '../../types'
|
||||||
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
import { normalizePhoneNumber } from '../../utils/misc-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { User } from '../../types'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new user in Telegram.
|
* Register a new user in Telegram.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { MaybeDynamic, MtArgumentError, User } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { MaybeDynamic, MtArgumentError, User } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility function to quickly authorize on test DC
|
* Utility function to quickly authorize on test DC
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
MaybeDynamic,
|
MaybeDynamic,
|
||||||
MtArgumentError,
|
MtArgumentError,
|
||||||
|
@ -6,12 +9,10 @@ import {
|
||||||
User,
|
User,
|
||||||
MaybeAsync,
|
MaybeAsync,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import {
|
import {
|
||||||
resolveMaybeDynamic,
|
resolveMaybeDynamic,
|
||||||
normalizePhoneNumber,
|
normalizePhoneNumber,
|
||||||
} from '../../utils/misc-utils'
|
} from '../../utils/misc-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the client in an interactive and declarative manner,
|
* Start the client in an interactive and declarative manner,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send an answer to a callback query.
|
* Send an answer to a callback query.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { BotInline, InputInlineResult } from '../../types'
|
import { BotInline, InputInlineResult } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { BotCommands } from '../../types'
|
import { BotCommands } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from "../../types";
|
|
||||||
import { normalizeToInputUser } from "../../utils/peer-utils";
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the menu button set for the given user.
|
* Fetches the menu button set for the given user.
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { InputPeerLike } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { computeSrpParams } from '@mtcute/core'
|
import { computeSrpParams } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Request a callback answer from a bot,
|
* Request a callback answer from a bot,
|
||||||
* i.e. click an inline button that contains data.
|
* i.e. click an inline button that contains data.
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
|
@ -5,7 +7,6 @@ import {
|
||||||
GameHighScore,
|
GameHighScore,
|
||||||
PeersIndex,
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { BotCommands } from '../../types'
|
import { BotCommands } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { BotCommands, MtInvalidPeerTypeError } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
|
||||||
import { assertNever } from '@mtcute/core'
|
import { assertNever } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { BotCommands, MtInvalidPeerTypeError } from '../../types'
|
||||||
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export async function _normalizeCommandScope(
|
export async function _normalizeCommandScope(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
|
@ -17,21 +18,25 @@ export async function _normalizeCommandScope(
|
||||||
const peer = await this.resolvePeer(scope.peer)
|
const peer = await this.resolvePeer(scope.peer)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_: scope.type === 'peer' ? 'botCommandScopePeer' : 'botCommandScopePeerAdmins',
|
_:
|
||||||
peer
|
scope.type === 'peer'
|
||||||
|
? 'botCommandScopePeer'
|
||||||
|
: 'botCommandScopePeerAdmins',
|
||||||
|
peer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'member': {
|
case 'member': {
|
||||||
const chat = await this.resolvePeer(scope.chat)
|
const chat = await this.resolvePeer(scope.chat)
|
||||||
const user = normalizeToInputUser(await this.resolvePeer(scope.user))
|
const user = normalizeToInputUser(
|
||||||
|
await this.resolvePeer(scope.user)
|
||||||
|
)
|
||||||
|
|
||||||
if (!user)
|
if (!user) throw new MtInvalidPeerTypeError(scope.user, 'user')
|
||||||
throw new MtInvalidPeerTypeError(scope.user, 'user')
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
_: 'botCommandScopePeerUser',
|
_: 'botCommandScopePeerUser',
|
||||||
peer: chat,
|
peer: chat,
|
||||||
userId: user
|
userId: user,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from "../../types";
|
|
||||||
import { normalizeToInputUser } from "../../utils/peer-utils";
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a menu button for the given user.
|
* Sets a menu button for the given user.
|
||||||
|
@ -21,6 +22,6 @@ export async function setBotMenuButton(
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'bots.setBotMenuButton',
|
_: 'bots.setBotMenuButton',
|
||||||
userId,
|
userId,
|
||||||
button
|
button,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, Message, MtInvalidPeerTypeError } from '../../types'
|
||||||
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a score of a user in a game
|
* Set a score of a user in a game
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { BotCommands } from '../../types'
|
import { BotCommands } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the default chat permissions for the bot in the supergroup or channel.
|
* Sets the default chat permissions for the bot in the supergroup or channel.
|
||||||
*
|
*
|
||||||
|
@ -14,10 +15,13 @@ export async function setMyDefaultRights(
|
||||||
rights: Omit<tl.RawChatAdminRights, '_'>
|
rights: Omit<tl.RawChatAdminRights, '_'>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.call({
|
await this.call({
|
||||||
_: target === 'group' ? 'bots.setBotGroupDefaultAdminRights' : 'bots.setBotBroadcastDefaultAdminRights',
|
_:
|
||||||
|
target === 'group'
|
||||||
|
? 'bots.setBotGroupDefaultAdminRights'
|
||||||
|
: 'bots.setBotBroadcastDefaultAdminRights',
|
||||||
adminRights: {
|
adminRights: {
|
||||||
_: 'chatAdminRights',
|
_: 'chatAdminRights',
|
||||||
...rights
|
...rights,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import { InputPeerLike } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Archive one or more chats
|
* Archive one or more chats
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { Chat, InputPeerLike } from '../../types'
|
import { Chat, InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
||||||
|
|
||||||
// @alias=deleteSupergroup
|
// @alias=deleteSupergroup
|
||||||
|
|
|
@ -13,8 +13,7 @@ export async function deleteGroup(
|
||||||
chatId: InputPeerLike
|
chatId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const chat = await this.resolvePeer(chatId)
|
const chat = await this.resolvePeer(chatId)
|
||||||
if (!isInputPeerChat(chat))
|
if (!isInputPeerChat(chat)) throw new MtInvalidPeerTypeError(chatId, 'chat')
|
||||||
throw new MtInvalidPeerTypeError(chatId, 'chat')
|
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.deleteChatUser',
|
_: 'messages.deleteChatUser',
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete communication history (for private chats
|
* Delete communication history (for private chats
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
import {
|
import {
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputPeer,
|
normalizeToInputPeer,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import {
|
import {
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
|
|
|
@ -1,16 +1,18 @@
|
||||||
|
import Long from 'long'
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { assertNever, MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
MtInvalidPeerTypeError,
|
MtInvalidPeerTypeError,
|
||||||
ChatEvent, PeersIndex,
|
ChatEvent,
|
||||||
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { assertNever, MaybeArray } from "@mtcute/core";
|
|
||||||
import {
|
import {
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import Long from 'long'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get chat event log ("Recent actions" in official
|
* Get chat event log ("Recent actions" in official
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types'
|
import { InputPeerLike, MtInvalidPeerTypeError, PeersIndex } from '../../types'
|
||||||
import {
|
import {
|
||||||
|
@ -7,7 +9,6 @@ import {
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { ChatMember } from '../../types'
|
import { ChatMember } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
|
import Long from 'long'
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { assertNever } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
ChatMember,
|
ChatMember,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
MtInvalidPeerTypeError,
|
MtInvalidPeerTypeError,
|
||||||
PeersIndex,
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { ArrayWithTotal } from '../../types'
|
import { ArrayWithTotal } from '../../types'
|
||||||
import Long from 'long'
|
|
||||||
import { assertNever } from '@mtcute/core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a chunk of members of some chat.
|
* Get a chunk of members of some chat.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { MtArgumentError, MtNotFoundError } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { MtArgumentError, MtNotFoundError } from '../../types'
|
||||||
import { INVITE_LINK_REGEX } from '../../utils/peer-utils'
|
import { INVITE_LINK_REGEX } from '../../utils/peer-utils'
|
||||||
import { ChatPreview } from '../../types'
|
import { ChatPreview } from '../../types'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
|
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
|
@ -8,7 +10,6 @@ import {
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get basic information about a chat.
|
* Get basic information about a chat.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { Chat, InputPeerLike, MtArgumentError } from '../../types'
|
||||||
import {
|
import {
|
||||||
INVITE_LINK_REGEX,
|
INVITE_LINK_REGEX,
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
|
@ -8,7 +10,6 @@ import {
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
normalizeToInputUser,
|
normalizeToInputUser,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get full information about a chat.
|
* Get full information about a chat.
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { getMarkedPeerId } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { Chat } from '../../types'
|
import { Chat } from '../../types'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { getMarkedPeerId } from '@mtcute/core'
|
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import { sleep } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { isInputPeerChannel } from '../../utils/peer-utils'
|
import { isInputPeerChannel } from '../../utils/peer-utils'
|
||||||
import { sleep } from '@mtcute/core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick a user from a chat.
|
* Kick a user from a chat.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types'
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save or delete a draft message associated with some chat
|
* Save or delete a draft message associated with some chat
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { Chat, InputPeerLike } from '../../types'
|
import { Chat, InputPeerLike } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
InputFileLike,
|
InputFileLike,
|
||||||
|
@ -11,8 +14,6 @@ import {
|
||||||
isInputPeerChat,
|
isInputPeerChat,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { fileIdToInputPhoto, tdFileId } from '@mtcute/file-id'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a new chat photo or video.
|
* Set a new chat photo or video.
|
||||||
|
@ -46,7 +47,7 @@ export async function setChatPhoto(
|
||||||
throw new MtArgumentError("Chat photo can't be external")
|
throw new MtArgumentError("Chat photo can't be external")
|
||||||
if (typeof media === 'string' && media.match(/^file:/)) {
|
if (typeof media === 'string' && media.match(/^file:/)) {
|
||||||
const uploaded = await this.uploadFile({
|
const uploaded = await this.uploadFile({
|
||||||
file: media.substr(5),
|
file: media.substring(5),
|
||||||
})
|
})
|
||||||
inputFile = uploaded.inputFile
|
inputFile = uploaded.inputFile
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
|
||||||
import { InputPeerLike } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unarchive one or more chats
|
* Unarchive one or more chats
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types'
|
||||||
InputPeerLike,
|
|
||||||
MtInvalidPeerTypeError,
|
|
||||||
User,
|
|
||||||
} from '../../types'
|
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
import {
|
|
||||||
InputPeerLike,
|
import { TelegramClient } from '../../client'
|
||||||
MtInvalidPeerTypeError,
|
import { InputPeerLike, MtInvalidPeerTypeError, User } from '../../types'
|
||||||
User,
|
|
||||||
} from '../../types'
|
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import Long from 'long'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { User } from '../../types'
|
import { User } from '../../types'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import Long from 'long'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of contacts from your Telegram contacts list.
|
* Get list of contacts from your Telegram contacts list.
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
import Long from 'long'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { PartialOnly } from '@mtcute/core'
|
import { PartialOnly } from '@mtcute/core'
|
||||||
import Long from 'long'
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Import contacts to your Telegram contacts list.
|
* Import contacts to your Telegram contacts list.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { getMarkedPeerId } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { Conversation, Message } from '../../types'
|
import { Conversation, Message } from '../../types'
|
||||||
import { getMarkedPeerId } from '@mtcute/core'
|
|
||||||
|
|
||||||
// @extension
|
// @extension
|
||||||
interface ConversationsState {
|
interface ConversationsState {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { PartialExcept } from '@mtcute/core'
|
import { PartialExcept } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a folder from given parameters
|
* Create a folder from given parameters
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a folder by its ID
|
* Delete a folder by its ID
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { MtArgumentError } from '../../types'
|
import { MtArgumentError } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,7 +25,11 @@ export async function editFolder(
|
||||||
}
|
}
|
||||||
if (typeof folder === 'number' || typeof folder === 'string') {
|
if (typeof folder === 'number' || typeof folder === 'string') {
|
||||||
const old = await this.getFolders()
|
const old = await this.getFolders()
|
||||||
const found = old.find((it) => it._ === 'dialogFilter' && (it.id === folder || it.title === folder))
|
const found = old.find(
|
||||||
|
(it) =>
|
||||||
|
it._ === 'dialogFilter' &&
|
||||||
|
(it.id === folder || it.title === folder)
|
||||||
|
)
|
||||||
if (!found)
|
if (!found)
|
||||||
throw new MtArgumentError(`Could not find a folder ${folder}`)
|
throw new MtArgumentError(`Could not find a folder ${folder}`)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { MtArgumentError } from '../../types'
|
import { MtArgumentError } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,13 +27,13 @@ export async function findFolder(
|
||||||
const folders = await this.getFolders()
|
const folders = await this.getFolders()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
folders.find((it) => {
|
(folders.find((it) => {
|
||||||
if (it._ === 'dialogFilterDefault') return false
|
if (it._ === 'dialogFilterDefault') return false
|
||||||
if (params.id && it.id !== params.id) return false
|
if (params.id && it.id !== params.id) return false
|
||||||
if (params.title && it.title !== params.title) return false
|
if (params.title && it.title !== params.title) return false
|
||||||
if (params.emoji && it.emoticon !== params.emoji) return false
|
if (params.emoji && it.emoticon !== params.emoji) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}) as tl.RawDialogFilter ?? null
|
}) as tl.RawDialogFilter) ?? null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
MtArgumentError,
|
|
||||||
} from '../../types'
|
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { Dialog, MtArgumentError } from '../../types'
|
||||||
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over dialogs.
|
* Iterate over dialogs.
|
||||||
|
@ -134,9 +132,7 @@ export async function* getDialogs(
|
||||||
return it.id === params!.folder || it.title === params!.folder
|
return it.id === params!.folder || it.title === params!.folder
|
||||||
})
|
})
|
||||||
if (!found)
|
if (!found)
|
||||||
throw new MtArgumentError(
|
throw new MtArgumentError(`Could not find folder ${params.folder}`)
|
||||||
`Could not find folder ${params.folder}`
|
|
||||||
)
|
|
||||||
|
|
||||||
filters = found as tl.RawDialogFilter
|
filters = found as tl.RawDialogFilter
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,13 +147,19 @@ export async function* getDialogs(
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
filters = {
|
filters = {
|
||||||
_: 'dialogFilterDefault'
|
_: 'dialogFilterDefault',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchPinnedDialogsFromFolder = async (): Promise<tl.messages.RawPeerDialogs | null> => {
|
const fetchPinnedDialogsFromFolder =
|
||||||
if (!filters || filters._ === 'dialogFilterDefault' || !filters.pinnedPeers.length) return null
|
async (): Promise<tl.messages.RawPeerDialogs | null> => {
|
||||||
|
if (
|
||||||
|
!filters ||
|
||||||
|
filters._ === 'dialogFilterDefault' ||
|
||||||
|
!filters.pinnedPeers.length
|
||||||
|
)
|
||||||
|
return null
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.getPeerDialogs',
|
_: 'messages.getPeerDialogs',
|
||||||
peers: filters.pinnedPeers.map((peer) => ({
|
peers: filters.pinnedPeers.map((peer) => ({
|
||||||
|
@ -173,12 +175,14 @@ export async function* getDialogs(
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const pinned = params.pinned ?? 'include'
|
const pinned = params.pinned ?? 'include'
|
||||||
let archived = params.archived ?? 'exclude'
|
let archived = params.archived ?? 'exclude'
|
||||||
|
|
||||||
if (filters) {
|
if (filters) {
|
||||||
archived = filters._ !== 'dialogFilterDefault' && filters.excludeArchived ? 'exclude' : 'keep'
|
archived =
|
||||||
|
filters._ !== 'dialogFilterDefault' && filters.excludeArchived
|
||||||
|
? 'exclude'
|
||||||
|
: 'keep'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pinned === 'only') {
|
if (pinned === 'only') {
|
||||||
|
@ -203,7 +207,12 @@ export async function* getDialogs(
|
||||||
let offsetDate = normalizeDate(params.offsetDate) ?? 0
|
let offsetDate = normalizeDate(params.offsetDate) ?? 0
|
||||||
let offsetPeer = params.offsetPeer ?? { _: 'inputPeerEmpty' }
|
let offsetPeer = params.offsetPeer ?? { _: 'inputPeerEmpty' }
|
||||||
|
|
||||||
if (filters && filters._ !== 'dialogFilterDefault' && filters.pinnedPeers.length && pinned === 'include') {
|
if (
|
||||||
|
filters &&
|
||||||
|
filters._ !== 'dialogFilterDefault' &&
|
||||||
|
filters.pinnedPeers.length &&
|
||||||
|
pinned === 'include'
|
||||||
|
) {
|
||||||
const res = await fetchPinnedDialogsFromFolder()
|
const res = await fetchPinnedDialogsFromFolder()
|
||||||
if (res) {
|
if (res) {
|
||||||
const dialogs = this._parseDialogs(res)
|
const dialogs = this._parseDialogs(res)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of folders.
|
* Get list of folders.
|
||||||
* @internal
|
* @internal
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
InputPeerLike,
|
|
||||||
} from '../../types'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { Dialog, InputPeerLike } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get dialogs with certain peers.
|
* Get dialogs with certain peers.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { Dialog, MtTypeAssertionError, PeersIndex } from '../../types'
|
|
||||||
import { getMarkedPeerId } from '@mtcute/core'
|
import { getMarkedPeerId } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { Dialog, MtTypeAssertionError, PeersIndex } from '../../types'
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export function _parseDialogs(
|
export function _parseDialogs(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reorder folders
|
* Reorder folders
|
||||||
|
@ -14,6 +13,6 @@ export async function setFoldersOrder(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
await this.call({
|
await this.call({
|
||||||
_: 'messages.updateDialogFiltersOrder',
|
_: 'messages.updateDialogFiltersOrder',
|
||||||
order
|
order,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { FileDownloadParameters, FileLocation } from '../../types'
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
|
import { FileDownloadParameters, FileLocation } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file and return its contents as a Buffer.
|
* Download a file and return its contents as a Buffer.
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import {
|
||||||
|
fileIdToInputFileLocation,
|
||||||
|
fileIdToInputWebFileLocation,
|
||||||
|
parseFileId,
|
||||||
|
} from '@mtcute/file-id'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { determinePartSize } from '../../utils/file-utils'
|
import { determinePartSize } from '../../utils/file-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import {
|
import {
|
||||||
MtArgumentError,
|
MtArgumentError,
|
||||||
MtUnsupportedError,
|
MtUnsupportedError,
|
||||||
FileDownloadParameters,
|
FileDownloadParameters,
|
||||||
FileLocation,
|
FileLocation,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import {
|
|
||||||
fileIdToInputFileLocation,
|
|
||||||
fileIdToInputWebFileLocation,
|
|
||||||
parseFileId,
|
|
||||||
} from '@mtcute/file-id'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file and return it as an iterable, which yields file contents
|
* Download a file and return it as an iterable, which yields file contents
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Readable } from 'stream'
|
import { Readable } from 'stream'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { FileLocation, FileDownloadParameters } from '../../types'
|
import { FileLocation, FileDownloadParameters } from '../../types'
|
||||||
import { bufferToStream } from '../../utils/stream-utils'
|
import { bufferToStream } from '../../utils/stream-utils'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputFileLike } from '../../types'
|
import { InputFileLike } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { InputFileLike, isUploadedFile, MtArgumentError } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { tdFileId } from '@mtcute/file-id'
|
import { tdFileId } from '@mtcute/file-id'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputFileLike, isUploadedFile, MtArgumentError } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize a {@link InputFileLike} to `InputFile`,
|
* Normalize a {@link InputFileLike} to `InputFile`,
|
||||||
* uploading it if needed.
|
* uploading it if needed.
|
||||||
|
@ -26,7 +27,7 @@ export async function _normalizeInputFile(
|
||||||
} else if (tdFileId.isFileIdLike(input)) {
|
} else if (tdFileId.isFileIdLike(input)) {
|
||||||
if (typeof input === 'string' && input.match(/^file:/)) {
|
if (typeof input === 'string' && input.match(/^file:/)) {
|
||||||
const uploaded = await this.uploadFile({
|
const uploaded = await this.uploadFile({
|
||||||
file: input.substr(5),
|
file: input.substring(5),
|
||||||
...params,
|
...params,
|
||||||
})
|
})
|
||||||
return uploaded.inputFile
|
return uploaded.inputFile
|
||||||
|
|
|
@ -1,9 +1,4 @@
|
||||||
import { TelegramClient } from '../../client'
|
import Long from 'long'
|
||||||
import {
|
|
||||||
InputMediaLike,
|
|
||||||
isUploadedFile,
|
|
||||||
UploadFileLike,
|
|
||||||
} from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import {
|
import {
|
||||||
fileIdToInputDocument,
|
fileIdToInputDocument,
|
||||||
|
@ -11,11 +6,13 @@ import {
|
||||||
parseFileId,
|
parseFileId,
|
||||||
tdFileId,
|
tdFileId,
|
||||||
} from '@mtcute/file-id'
|
} from '@mtcute/file-id'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputMediaLike, isUploadedFile, UploadFileLike } from '../../types'
|
||||||
import { extractFileName } from '../../utils/file-utils'
|
import { extractFileName } from '../../utils/file-utils'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
import { encodeWaveform } from '../../utils/voice-utils'
|
import { encodeWaveform } from '../../utils/voice-utils'
|
||||||
import Long from 'long'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalize an {@link InputMediaLike} to `InputMedia`,
|
* Normalize an {@link InputMediaLike} to `InputMedia`,
|
||||||
|
@ -292,7 +289,7 @@ export async function _normalizeInputMedia(
|
||||||
media.type === 'photo'
|
media.type === 'photo'
|
||||||
)
|
)
|
||||||
} else if (typeof input === 'string' && input.match(/^file:/)) {
|
} else if (typeof input === 'string' && input.match(/^file:/)) {
|
||||||
await upload(input.substr(5))
|
await upload(input.substring(5))
|
||||||
} else {
|
} else {
|
||||||
const parsed =
|
const parsed =
|
||||||
typeof input === 'string' ? parseFileId(input) : input
|
typeof input === 'string' ? parseFileId(input) : input
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
|
import type { ReadStream } from 'fs'
|
||||||
|
import { Readable } from 'stream'
|
||||||
|
import { fromBuffer } from 'file-type'
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { randomLong } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
bufferToStream,
|
bufferToStream,
|
||||||
convertWebStreamToNodeReadable,
|
convertWebStreamToNodeReadable,
|
||||||
readBytesFromStream,
|
readBytesFromStream,
|
||||||
readStreamUntilEnd,
|
readStreamUntilEnd,
|
||||||
} from '../../utils/stream-utils'
|
} from '../../utils/stream-utils'
|
||||||
import type { ReadStream } from 'fs'
|
|
||||||
import { Readable } from 'stream'
|
|
||||||
import { determinePartSize, isProbablyPlainText } from '../../utils/file-utils'
|
import { determinePartSize, isProbablyPlainText } from '../../utils/file-utils'
|
||||||
import { fromBuffer } from 'file-type'
|
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { MtArgumentError, UploadFileLike, UploadedFile } from '../../types'
|
import { MtArgumentError, UploadFileLike, UploadedFile } from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { randomLong } from '@mtcute/core'
|
|
||||||
|
|
||||||
let fs: any = null
|
let fs: any = null
|
||||||
let path: any = null
|
let path: any = null
|
||||||
|
@ -20,7 +21,6 @@ try {
|
||||||
path = require('path')
|
path = require('path')
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
|
|
||||||
const OVERRIDE_MIME: Record<string, string> = {
|
const OVERRIDE_MIME: Record<string, string> = {
|
||||||
// tg doesn't interpret `audio/opus` files as voice messages for some reason
|
// tg doesn't interpret `audio/opus` files as voice messages for some reason
|
||||||
'audio/opus': 'audio/ogg',
|
'audio/opus': 'audio/ogg',
|
||||||
|
@ -135,7 +135,12 @@ export async function uploadFile(
|
||||||
file = convertWebStreamToNodeReadable(file)
|
file = convertWebStreamToNodeReadable(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof file === 'object' && 'headers' in file && 'body' in file && 'url' in file) {
|
if (
|
||||||
|
typeof file === 'object' &&
|
||||||
|
'headers' in file &&
|
||||||
|
'body' in file &&
|
||||||
|
'url' in file
|
||||||
|
) {
|
||||||
// fetch() response
|
// fetch() response
|
||||||
const length = parseInt(file.headers.get('content-length') || '0')
|
const length = parseInt(file.headers.get('content-length') || '0')
|
||||||
if (!isNaN(length) && length) fileSize = length
|
if (!isNaN(length) && length) fileSize = length
|
||||||
|
@ -187,9 +192,7 @@ export async function uploadFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(file instanceof Readable))
|
if (!(file instanceof Readable))
|
||||||
throw new MtArgumentError(
|
throw new MtArgumentError('Could not convert input `file` to stream!')
|
||||||
'Could not convert input `file` to stream!'
|
|
||||||
)
|
|
||||||
|
|
||||||
const partSizeKb = params.partSize ?? determinePartSize(fileSize)
|
const partSizeKb = params.partSize ?? determinePartSize(fileSize)
|
||||||
if (partSizeKb > 512)
|
if (partSizeKb > 512)
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
|
import { assertNever } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
InputMediaLike,
|
InputMediaLike,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
MessageMedia,
|
MessageMedia,
|
||||||
MtArgumentError,
|
MtArgumentError,
|
||||||
MtTypeAssertionError,
|
MtTypeAssertionError,
|
||||||
Photo, RawDocument,
|
Photo,
|
||||||
|
RawDocument,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { parseDocument } from '../../types/media/document-utils'
|
import { parseDocument } from '../../types/media/document-utils'
|
||||||
import { assertNever } from '@mtcute/core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload a media to Telegram servers, without actually
|
* Upload a media to Telegram servers, without actually
|
||||||
|
|
|
@ -43,7 +43,7 @@ export async function createInviteLink(
|
||||||
peer: await this.resolvePeer(chatId),
|
peer: await this.resolvePeer(chatId),
|
||||||
expireDate: normalizeDate(params.expires),
|
expireDate: normalizeDate(params.expires),
|
||||||
usageLimit: params.usageLimit,
|
usageLimit: params.usageLimit,
|
||||||
requestNeeded: params.withApproval
|
requestNeeded: params.withApproval,
|
||||||
})
|
})
|
||||||
|
|
||||||
return new ChatInviteLink(this, res)
|
return new ChatInviteLink(this, res)
|
||||||
|
|
|
@ -46,7 +46,7 @@ export async function editInviteLink(
|
||||||
link,
|
link,
|
||||||
expireDate: normalizeDate(params.expires),
|
expireDate: normalizeDate(params.expires),
|
||||||
usageLimit: params.usageLimit,
|
usageLimit: params.usageLimit,
|
||||||
requestNeeded: params.withApproval
|
requestNeeded: params.withApproval,
|
||||||
})
|
})
|
||||||
|
|
||||||
const peers = PeersIndex.from(res)
|
const peers = PeersIndex.from(res)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { ChatInviteLink, InputPeerLike, PeersIndex, User } from '../../types'
|
import { ChatInviteLink, InputPeerLike, PeersIndex, User } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over users who have joined
|
* Iterate over users who have joined
|
||||||
|
@ -49,8 +50,8 @@ export async function* getInviteLinkMembers(
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// for some reason ts needs annotation, idk
|
// for some reason ts needs annotation, idk
|
||||||
const res: tl.RpcCallReturn['messages.getChatInviteImporters'] = await this.call(
|
const res: tl.RpcCallReturn['messages.getChatInviteImporters'] =
|
||||||
{
|
await this.call({
|
||||||
_: 'messages.getChatInviteImporters',
|
_: 'messages.getChatInviteImporters',
|
||||||
limit: Math.min(100, limit - current),
|
limit: Math.min(100, limit - current),
|
||||||
peer,
|
peer,
|
||||||
|
@ -59,8 +60,7 @@ export async function* getInviteLinkMembers(
|
||||||
q: params.requestedSearch,
|
q: params.requestedSearch,
|
||||||
offsetDate,
|
offsetDate,
|
||||||
offsetUser,
|
offsetUser,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
if (!res.importers.length) break
|
if (!res.importers.length) break
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ export async function* getInviteLinkMembers(
|
||||||
date: new Date(it.date * 1000),
|
date: new Date(it.date * 1000),
|
||||||
isPendingRequest: it.requested!,
|
isPendingRequest: it.requested!,
|
||||||
bio: it.about,
|
bio: it.about,
|
||||||
approvedBy: it.approvedBy
|
approvedBy: it.approvedBy,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
ChatInviteLink,
|
ChatInviteLink,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
MtInvalidPeerTypeError, MtTypeAssertionError,
|
MtInvalidPeerTypeError,
|
||||||
PeersIndex
|
MtTypeAssertionError,
|
||||||
} from "../../types";
|
PeersIndex,
|
||||||
|
} from '../../types'
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get invite links created by some administrator in the chat.
|
* Get invite links created by some administrator in the chat.
|
||||||
|
@ -59,16 +61,15 @@ export async function* getInviteLinks(
|
||||||
let offsetLink: string | undefined = undefined
|
let offsetLink: string | undefined = undefined
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const res: tl.RpcCallReturn['messages.getExportedChatInvites'] = await this.call(
|
const res: tl.RpcCallReturn['messages.getExportedChatInvites'] =
|
||||||
{
|
await this.call({
|
||||||
_: 'messages.getExportedChatInvites',
|
_: 'messages.getExportedChatInvites',
|
||||||
peer,
|
peer,
|
||||||
adminId: admin,
|
adminId: admin,
|
||||||
limit: Math.min(chunkSize, total - current),
|
limit: Math.min(chunkSize, total - current),
|
||||||
offsetDate,
|
offsetDate,
|
||||||
offsetLink,
|
offsetLink,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
if (!res.invites.length) break
|
if (!res.invites.length) break
|
||||||
|
|
||||||
|
@ -76,7 +77,11 @@ export async function* getInviteLinks(
|
||||||
|
|
||||||
const last = res.invites[res.invites.length - 1]
|
const last = res.invites[res.invites.length - 1]
|
||||||
if (last._ === 'chatInvitePublicJoinRequests') {
|
if (last._ === 'chatInvitePublicJoinRequests') {
|
||||||
throw new MtTypeAssertionError('getInviteLinks', 'chatInviteExported', last._)
|
throw new MtTypeAssertionError(
|
||||||
|
'getInviteLinks',
|
||||||
|
'chatInviteExported',
|
||||||
|
last._
|
||||||
|
)
|
||||||
}
|
}
|
||||||
offsetDate = last.date
|
offsetDate = last.date
|
||||||
offsetLink = last.link
|
offsetLink = last.link
|
||||||
|
|
|
@ -2,7 +2,8 @@ import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
ChatInviteLink,
|
ChatInviteLink,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
MtTypeAssertionError, PeersIndex,
|
MtTypeAssertionError,
|
||||||
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
import Long from 'long'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, MtTypeAssertionError, PeersIndex, Poll } from '../../types'
|
import {
|
||||||
|
InputPeerLike,
|
||||||
|
MtTypeAssertionError,
|
||||||
|
PeersIndex,
|
||||||
|
Poll,
|
||||||
|
} from '../../types'
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
import Long from 'long'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close a poll sent by you.
|
* Close a poll sent by you.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike } from '../../types'
|
import { InputPeerLike } from '../../types'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete scheduled messages.
|
* Delete scheduled messages.
|
||||||
|
@ -12,7 +13,7 @@ import { MaybeArray } from '@mtcute/core'
|
||||||
export async function deleteScheduledMessages(
|
export async function deleteScheduledMessages(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike,
|
||||||
ids: MaybeArray<number>,
|
ids: MaybeArray<number>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (!Array.isArray(ids)) ids = [ids]
|
if (!Array.isArray(ids)) ids = [ids]
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ export async function deleteScheduledMessages(
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.deleteScheduledMessages',
|
_: 'messages.deleteScheduledMessages',
|
||||||
peer,
|
peer,
|
||||||
id: ids
|
id: ids,
|
||||||
})
|
})
|
||||||
|
|
||||||
this._handleUpdate(res)
|
this._handleUpdate(res)
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { BotKeyboard, FormattedString, InputMediaLike, ReplyMarkup } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import {
|
||||||
|
BotKeyboard,
|
||||||
|
FormattedString,
|
||||||
|
InputMediaLike,
|
||||||
|
ReplyMarkup,
|
||||||
|
} from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit sent inline message text, media and reply markup.
|
* Edit sent inline message text, media and reply markup.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
BotKeyboard, FormattedString,
|
BotKeyboard,
|
||||||
|
FormattedString,
|
||||||
InputMediaLike,
|
InputMediaLike,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
Message,
|
Message,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit message text, media, reply markup and schedule date.
|
* Edit message text, media, reply markup and schedule date.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { MaybeArray, randomLong } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
FormattedString,
|
FormattedString,
|
||||||
|
@ -7,8 +10,6 @@ import {
|
||||||
MtArgumentError,
|
MtArgumentError,
|
||||||
PeersIndex,
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { MaybeArray, randomLong } from '@mtcute/core'
|
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
|
@ -317,7 +318,7 @@ export async function forwardMessages(
|
||||||
schedule: params.schedule,
|
schedule: params.schedule,
|
||||||
clearDraft: params.clearDraft,
|
clearDraft: params.clearDraft,
|
||||||
forbidForwards: params.forbidForwards,
|
forbidForwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs
|
sendAs: params.sendAs,
|
||||||
})
|
})
|
||||||
} else if (params.captionMedia) {
|
} else if (params.captionMedia) {
|
||||||
captionMessage = await this.sendMedia(toPeer, params.captionMedia, {
|
captionMessage = await this.sendMedia(toPeer, params.captionMedia, {
|
||||||
|
@ -326,7 +327,7 @@ export async function forwardMessages(
|
||||||
schedule: params.schedule,
|
schedule: params.schedule,
|
||||||
clearDraft: params.clearDraft,
|
clearDraft: params.clearDraft,
|
||||||
forbidForwards: params.forbidForwards,
|
forbidForwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs
|
sendAs: params.sendAs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,7 +344,9 @@ export async function forwardMessages(
|
||||||
dropAuthor: params.noAuthor,
|
dropAuthor: params.noAuthor,
|
||||||
dropMediaCaptions: params.noCaption,
|
dropMediaCaptions: params.noCaption,
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
|
sendAs: params.sendAs
|
||||||
|
? await this.resolvePeer(params.sendAs)
|
||||||
|
: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
assertIsUpdatesGroup('messages.forwardMessages', res)
|
assertIsUpdatesGroup('messages.forwardMessages', res)
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { InputPeerLike, Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
|
||||||
import { normalizeDate } from '../../utils/misc-utils'
|
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import {
|
||||||
|
InputPeerLike,
|
||||||
|
Message,
|
||||||
|
MtTypeAssertionError,
|
||||||
|
PeersIndex,
|
||||||
|
} from '../../types'
|
||||||
|
import { normalizeDate } from '../../utils/misc-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a chunk of the chat history.
|
* Retrieve a chunk of the chat history.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import { getMarkedPeerId, MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { InputPeerLike, PeersIndex, MessageReactions } from '../../types'
|
import { InputPeerLike, PeersIndex, MessageReactions } from '../../types'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
import { getMarkedPeerId, MaybeArray } from '@mtcute/core'
|
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
import { TelegramClient } from '../../client'
|
import { tl } from '@mtcute/tl'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
isInputPeerChannel,
|
isInputPeerChannel,
|
||||||
normalizeToInputChannel,
|
normalizeToInputChannel,
|
||||||
} from '../../utils/peer-utils'
|
} from '../../utils/peer-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import {
|
||||||
import { Message, InputPeerLike, MtTypeAssertionError, PeersIndex } from '../../types'
|
Message,
|
||||||
|
InputPeerLike,
|
||||||
|
MtTypeAssertionError,
|
||||||
|
PeersIndex,
|
||||||
|
} from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a single message in chat by its ID
|
* Get a single message in chat by its ID
|
||||||
|
@ -93,18 +99,33 @@ export async function getMessages(
|
||||||
// (channels have their own message numbering)
|
// (channels have their own message numbering)
|
||||||
switch (peer._) {
|
switch (peer._) {
|
||||||
case 'inputPeerSelf':
|
case 'inputPeerSelf':
|
||||||
if (!(msg.peerId._ === 'peerUser' && msg.peerId.userId === this._userId))
|
if (
|
||||||
|
!(
|
||||||
|
msg.peerId._ === 'peerUser' &&
|
||||||
|
msg.peerId.userId === this._userId
|
||||||
|
)
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
break;
|
break
|
||||||
case 'inputPeerUser':
|
case 'inputPeerUser':
|
||||||
case 'inputPeerUserFromMessage':
|
case 'inputPeerUserFromMessage':
|
||||||
if (!(msg.peerId._ === 'peerUser' && msg.peerId.userId === peer.userId))
|
if (
|
||||||
|
!(
|
||||||
|
msg.peerId._ === 'peerUser' &&
|
||||||
|
msg.peerId.userId === peer.userId
|
||||||
|
)
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
break;
|
break
|
||||||
case 'inputPeerChat':
|
case 'inputPeerChat':
|
||||||
if (!(msg.peerId._ === 'peerChat' && msg.peerId.chatId === peer.chatId))
|
if (
|
||||||
|
!(
|
||||||
|
msg.peerId._ === 'peerChat' &&
|
||||||
|
msg.peerId.chatId === peer.chatId
|
||||||
|
)
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import {
|
|
||||||
InputPeerLike,
|
|
||||||
PeerReaction,
|
|
||||||
PeersIndex,
|
|
||||||
} from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, PeerReaction, PeersIndex } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get users who have reacted to the message.
|
* Get users who have reacted to the message.
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
Message,
|
Message,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { SessionConnection } from '@mtcute/core'
|
import { SessionConnection } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { parseInlineMessageId } from '../../utils/inline-utils'
|
import { parseInlineMessageId } from '../../utils/inline-utils'
|
||||||
|
|
||||||
// @extension
|
// @extension
|
||||||
|
@ -25,9 +26,8 @@ export async function _normalizeInline(
|
||||||
let connection = this.primaryConnection
|
let connection = this.primaryConnection
|
||||||
if (id.dcId !== connection.params.dc.id) {
|
if (id.dcId !== connection.params.dc.id) {
|
||||||
if (!(id.dcId in this._connectionsForInline)) {
|
if (!(id.dcId in this._connectionsForInline)) {
|
||||||
this._connectionsForInline[
|
this._connectionsForInline[id.dcId] =
|
||||||
id.dcId
|
await this.createAdditionalConnection(id.dcId)
|
||||||
] = await this.createAdditionalConnection(id.dcId)
|
|
||||||
}
|
}
|
||||||
connection = this._connectionsForInline[id.dcId]
|
connection = this._connectionsForInline[id.dcId]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { normalizeToInputUser } from '../../utils/peer-utils'
|
import { normalizeToInputUser } from '../../utils/peer-utils'
|
||||||
import { FormattedString, MtClientError } from '../../types'
|
import { FormattedString, MtClientError } from '../../types'
|
||||||
|
@ -32,7 +33,7 @@ export async function _parseEntities(
|
||||||
throw new MtClientError(`Parse mode ${mode} is not registered.`)
|
throw new MtClientError(`Parse mode ${mode} is not registered.`)
|
||||||
}
|
}
|
||||||
|
|
||||||
;[text, entities] = await this._parseModes[mode].parse(text)
|
;[text, entities] = this._parseModes[mode].parse(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace mentionName entities with input ones
|
// replace mentionName entities with input ones
|
||||||
|
|
|
@ -10,11 +10,11 @@ import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
*/
|
*/
|
||||||
export async function readReactions(
|
export async function readReactions(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
chatId: InputPeerLike,
|
chatId: InputPeerLike
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.readReactions',
|
_: 'messages.readReactions',
|
||||||
peer: await this.resolvePeer(chatId)
|
peer: await this.resolvePeer(chatId),
|
||||||
})
|
})
|
||||||
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
this._handleUpdate(createDummyUpdate(res.pts, res.ptsCount))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
import { Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { SearchFilters } from '../../types'
|
import { SearchFilters } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,7 +86,8 @@ export async function* searchGlobal(
|
||||||
if (!msgs.length) break
|
if (!msgs.length) break
|
||||||
|
|
||||||
const last = msgs[msgs.length - 1]
|
const last = msgs[msgs.length - 1]
|
||||||
offsetRate = (res as tl.messages.RawMessagesSlice).nextRate ?? last.raw.date
|
offsetRate =
|
||||||
|
(res as tl.messages.RawMessagesSlice).nextRate ?? last.raw.date
|
||||||
offsetPeer = last.chat.inputPeer
|
offsetPeer = last.chat.inputPeer
|
||||||
offsetId = last.id
|
offsetId = last.id
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { InputPeerLike, Message, MtTypeAssertionError, PeersIndex } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { SearchFilters } from '../../types'
|
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import {
|
||||||
|
InputPeerLike,
|
||||||
|
Message,
|
||||||
|
MtTypeAssertionError,
|
||||||
|
PeersIndex,
|
||||||
|
} from '../../types'
|
||||||
|
import { SearchFilters } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search for messages inside a specific chat
|
* Search for messages inside a specific chat
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { InputPeerLike, Message, FormattedString, ReplyMarkup } from '../../types'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import {
|
||||||
|
InputPeerLike,
|
||||||
|
Message,
|
||||||
|
FormattedString,
|
||||||
|
ReplyMarkup,
|
||||||
|
} from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy a message (i.e. send the same message,
|
* Copy a message (i.e. send the same message,
|
||||||
* but do not forward it).
|
* but do not forward it).
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { randomLong } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
BotKeyboard, InputFileLike,
|
BotKeyboard,
|
||||||
InputMediaLike,
|
InputMediaLike,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
Message, MtArgumentError, PeersIndex,
|
Message,
|
||||||
|
MtArgumentError,
|
||||||
|
PeersIndex,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import {
|
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
|
||||||
normalizeDate,
|
|
||||||
normalizeMessageId,
|
|
||||||
} from '../../utils/misc-utils'
|
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
import { randomLong } from '@mtcute/core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a group of media.
|
* Send a group of media.
|
||||||
|
@ -141,8 +141,7 @@ export async function sendMediaGroup(
|
||||||
|
|
||||||
const msg = await this.getMessages(peer, replyTo)
|
const msg = await this.getMessages(peer, replyTo)
|
||||||
|
|
||||||
if (!msg)
|
if (!msg) throw new tl.errors.MessageNotFoundError()
|
||||||
throw new tl.errors.MessageNotFoundError()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const multiMedia: tl.RawInputSingleMedia[] = []
|
const multiMedia: tl.RawInputSingleMedia[] = []
|
||||||
|
@ -157,13 +156,17 @@ export async function sendMediaGroup(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputMedia = await this._normalizeInputMedia(media, {
|
const inputMedia = await this._normalizeInputMedia(
|
||||||
|
media,
|
||||||
|
{
|
||||||
progressCallback: params.progressCallback?.bind(null, i),
|
progressCallback: params.progressCallback?.bind(null, i),
|
||||||
// i have no fucking clue why we should upload it manually,
|
// i have no fucking clue why we should upload it manually,
|
||||||
// but otherwise Telegram throws MEDIA_INVALID
|
// but otherwise Telegram throws MEDIA_INVALID
|
||||||
// fuck my life
|
// fuck my life
|
||||||
uploadPeer: peer
|
uploadPeer: peer,
|
||||||
}, true)
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
|
||||||
const [message, entities] = await this._parseEntities(
|
const [message, entities] = await this._parseEntities(
|
||||||
// some types dont have `caption` field, and ts warns us,
|
// some types dont have `caption` field, and ts warns us,
|
||||||
|
@ -194,7 +197,9 @@ export async function sendMediaGroup(
|
||||||
replyMarkup,
|
replyMarkup,
|
||||||
clearDraft: params.clearDraft,
|
clearDraft: params.clearDraft,
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
|
sendAs: params.sendAs
|
||||||
|
? await this.resolvePeer(params.sendAs)
|
||||||
|
: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
assertIsUpdatesGroup('_findMessageInUpdate', res)
|
assertIsUpdatesGroup('_findMessageInUpdate', res)
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { randomLong } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
BotKeyboard,
|
BotKeyboard,
|
||||||
|
@ -9,8 +12,6 @@ import {
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
|
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
import { randomLong } from '@mtcute/core'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a single media (a photo or a document-based media)
|
* Send a single media (a photo or a document-based media)
|
||||||
|
@ -184,7 +185,9 @@ export async function sendMedia(
|
||||||
entities,
|
entities,
|
||||||
clearDraft: params.clearDraft,
|
clearDraft: params.clearDraft,
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
|
sendAs: params.sendAs
|
||||||
|
? await this.resolvePeer(params.sendAs)
|
||||||
|
: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
const msg = this._findMessageInUpdate(res)
|
const msg = this._findMessageInUpdate(res)
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
|
@ -6,7 +8,6 @@ import {
|
||||||
PeersIndex,
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send or remove a reaction.
|
* Send or remove a reaction.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { InputPeerLike, Message, PeersIndex } from '../../types'
|
|
||||||
import { MaybeArray } from '@mtcute/core'
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { InputPeerLike, Message, PeersIndex } from '../../types'
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ export async function sendScheduled(
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.sendScheduledMessages',
|
_: 'messages.sendScheduledMessages',
|
||||||
peer: await this.resolvePeer(peer),
|
peer: await this.resolvePeer(peer),
|
||||||
id: (ids as number[])
|
id: ids as number[],
|
||||||
})
|
})
|
||||||
|
|
||||||
assertIsUpdatesGroup('sendScheduled', res)
|
assertIsUpdatesGroup('sendScheduled', res)
|
||||||
|
@ -60,17 +61,9 @@ export async function sendScheduled(
|
||||||
const msgs = res.updates
|
const msgs = res.updates
|
||||||
.filter(
|
.filter(
|
||||||
(u) =>
|
(u) =>
|
||||||
u._ === 'updateNewMessage' ||
|
u._ === 'updateNewMessage' || u._ === 'updateNewChannelMessage'
|
||||||
u._ === 'updateNewChannelMessage'
|
|
||||||
)
|
|
||||||
.map(
|
|
||||||
(u) =>
|
|
||||||
new Message(
|
|
||||||
this,
|
|
||||||
(u as any).message,
|
|
||||||
peers
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
.map((u) => new Message(this, (u as any).message, peers))
|
||||||
|
|
||||||
this._pushConversationMessage(msgs[msgs.length - 1])
|
this._pushConversationMessage(msgs[msgs.length - 1])
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { getMarkedPeerId, randomLong } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
import { inputPeerToPeer } from '../../utils/peer-utils'
|
import { inputPeerToPeer } from '../../utils/peer-utils'
|
||||||
import {
|
import { normalizeDate, normalizeMessageId } from '../../utils/misc-utils'
|
||||||
normalizeDate,
|
|
||||||
normalizeMessageId,
|
|
||||||
} from '../../utils/misc-utils'
|
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
Message,
|
Message,
|
||||||
BotKeyboard,
|
BotKeyboard,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
MtTypeAssertionError,
|
MtTypeAssertionError,
|
||||||
MtArgumentError, FormattedString, PeersIndex,
|
MtArgumentError,
|
||||||
|
FormattedString,
|
||||||
|
PeersIndex,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { getMarkedPeerId, randomLong } from '@mtcute/core'
|
|
||||||
import { createDummyUpdate } from '../../utils/updates-utils'
|
import { createDummyUpdate } from '../../utils/updates-utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,8 +143,7 @@ export async function sendText(
|
||||||
|
|
||||||
const msg = await this.getMessages(peer, replyTo)
|
const msg = await this.getMessages(peer, replyTo)
|
||||||
|
|
||||||
if (!msg)
|
if (!msg) throw new tl.errors.MessageNotFoundError()
|
||||||
throw new tl.errors.MessageNotFoundError()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
|
@ -160,7 +159,9 @@ export async function sendText(
|
||||||
entities,
|
entities,
|
||||||
clearDraft: params.clearDraft,
|
clearDraft: params.clearDraft,
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await this.resolvePeer(params.sendAs) : undefined
|
sendAs: params.sendAs
|
||||||
|
? await this.resolvePeer(params.sendAs)
|
||||||
|
: undefined,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res._ === 'updateShortSentMessage') {
|
if (res._ === 'updateShortSentMessage') {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
import { TelegramClient } from '../../client'
|
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { InputPeerLike, TypingStatus } from '../../types'
|
|
||||||
import { assertNever } from '@mtcute/core'
|
import { assertNever } from '@mtcute/core'
|
||||||
|
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import { InputPeerLike, TypingStatus } from '../../types'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends a current user/bot typing event
|
* Sends a current user/bot typing event
|
||||||
* to a conversation partner or group.
|
* to a conversation partner or group.
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { MaybeArray } from '@mtcute/core'
|
||||||
|
|
||||||
import { TelegramClient } from '../../client'
|
import { TelegramClient } from '../../client'
|
||||||
import {
|
import {
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
|
@ -6,10 +9,8 @@ import {
|
||||||
PeersIndex,
|
PeersIndex,
|
||||||
Poll,
|
Poll,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import { MaybeArray } from '@mtcute/core'
|
|
||||||
import { assertTypeIs } from '../../utils/type-assertion'
|
import { assertTypeIs } from '../../utils/type-assertion'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send or retract a vote in a poll.
|
* Send or retract a vote in a poll.
|
||||||
|
@ -41,9 +42,7 @@ export async function sendVote(
|
||||||
if (!msg) throw new tl.errors.MessageNotFoundError()
|
if (!msg) throw new tl.errors.MessageNotFoundError()
|
||||||
|
|
||||||
if (!(msg.media instanceof Poll))
|
if (!(msg.media instanceof Poll))
|
||||||
throw new MtArgumentError(
|
throw new MtArgumentError('This message does not contain a poll')
|
||||||
'This message does not contain a poll'
|
|
||||||
)
|
|
||||||
|
|
||||||
poll = msg.media
|
poll = msg.media
|
||||||
options = options.map((opt) => {
|
options = options.map((opt) => {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue