feat: updated to layer 200

This commit is contained in:
alina sireneva
2025-03-08 11:55:06 +03:00
parent 5be050811f
commit a5bc0979e5
20 changed files with 238 additions and 10 deletions

View File

@@ -233,6 +233,7 @@ import { getUniqueStarGift } from './methods/premium/get-unique-star-gift.js'
import { iterBoosters } from './methods/premium/iter-boosters.js'
import { iterSavedStarGifts } from './methods/premium/iter-saved-star-gifts.js'
import { iterStarsTransactions } from './methods/premium/iter-stars-transactions.js'
import { togglePinnedStarGifts } from './methods/premium/pin-star-gift.js'
import { sendStarGift } from './methods/premium/send-star-gift.js'
import { setBusinessIntro } from './methods/premium/set-business-intro.js'
import { setBusinessWorkHours } from './methods/premium/set-business-work-hours.js'
@@ -4881,6 +4882,16 @@ export interface TelegramClient extends ITelegramClient {
*/
chunkSize?: number
}): AsyncIterableIterator<StarsTransaction>
/**
* Toggles whether one or more star gift is pinned to the top of the list
*/
togglePinnedStarGifts(
params: {
/** One or more gifts to pin */
gifts: MaybeArray<InputStarGift>
/** Peer where the gift is sent */
peer: InputPeerLike
}): Promise<void>
/**
* Send a star gift to a user.
*
@@ -6870,6 +6881,9 @@ TelegramClient.prototype.iterSavedStarGifts = function (...args) {
TelegramClient.prototype.iterStarsTransactions = function (...args) {
return iterStarsTransactions(this._client, ...args)
}
TelegramClient.prototype.togglePinnedStarGifts = function (...args) {
return togglePinnedStarGifts(this._client, ...args)
}
TelegramClient.prototype.sendStarGift = function (...args) {
return sendStarGift(this._client, ...args)
}

View File

@@ -233,6 +233,7 @@ export { getUniqueStarGift } from './methods/premium/get-unique-star-gift.js'
export { iterBoosters } from './methods/premium/iter-boosters.js'
export { iterSavedStarGifts } from './methods/premium/iter-saved-star-gifts.js'
export { iterStarsTransactions } from './methods/premium/iter-stars-transactions.js'
export { togglePinnedStarGifts } from './methods/premium/pin-star-gift.js'
export { sendStarGift } from './methods/premium/send-star-gift.js'
export { setBusinessIntro } from './methods/premium/set-business-intro.js'
export { setBusinessWorkHours } from './methods/premium/set-business-work-hours.js'

View File

@@ -1,3 +1,4 @@
import type { tl } from '@mtcute/tl'
import type { ITelegramClient } from '../../client.types.js'
import type { InputPeerLike } from '../../types/index.js'
import { MtArgumentError } from '../../../types/errors.js'
@@ -5,8 +6,8 @@ import { randomLong } from '../../../utils/long-utils.js'
import { Message, PeersIndex } from '../../types/index.js'
import { assertIsUpdatesGroup } from '../../updates/utils.js'
import { normalizeDate } from '../../utils/misc-utils.js'
import { resolvePeer } from '../users/resolve-peer.js'
import { resolvePeer } from '../users/resolve-peer.js'
import { _normalizeQuickReplyShortcut } from './send-common.js'
import { _getTypingTimerId } from './set-typing.js'
@@ -79,6 +80,12 @@ export interface ForwardMessageOptions {
*/
allowPaidFloodskip?: boolean
/**
* Whether to allow payment for messages.
* If set, the value represents the maximum number of stars to be paid
*/
allowPaidMessages?: tl.Long
/** Video timestamp to use for the forwarded video */
videoTimestamp?: number
}
@@ -142,6 +149,7 @@ export async function forwardMessagesById(
quickReplyShortcut: _normalizeQuickReplyShortcut(params.quickReply),
allowPaidFloodskip,
videoTimestamp,
allowPaidStars: params.allowPaidMessages,
})
assertIsUpdatesGroup('messages.forwardMessages', res)

View File

@@ -126,6 +126,12 @@ export interface CommonSendParams {
*/
allowPaidFloodskip?: boolean
/**
* Whether to allow payment for messages.
* If set, the value represents the maximum number of stars to be paid
*/
allowPaidMessages?: tl.Long
/**
* ID of a message effect to use when sending the message
* (see {@link TelegramClient.getAvailableMessageEffects})

View File

@@ -118,6 +118,7 @@ export async function sendMediaGroup(
quickReplyShortcut,
effect: params.effect,
allowPaidFloodskip: params.allowPaidFloodskip,
allowPaidStars: params.allowPaidMessages,
},
{ chainId },
)

View File

@@ -114,6 +114,7 @@ export async function sendMedia(
quickReplyShortcut,
effect: params.effect,
allowPaidFloodskip: params.allowPaidFloodskip,
allowPaidStars: params.allowPaidMessages,
},
{ chainId },
)

View File

@@ -86,6 +86,7 @@ export async function sendText(
quickReplyShortcut,
effect: params.effect,
allowPaidFloodskip: params.allowPaidFloodskip,
allowPaidStars: params.allowPaidMessages,
},
{ chainId },
)

View File

@@ -0,0 +1,33 @@
import type { ITelegramClient } from '../../client.types.js'
import type { InputPeerLike } from '../../types/peers/peer.js'
import type { InputStarGift } from '../../types/premium/stars-gift.js'
import { type MaybeArray, parallelMap } from '@fuman/utils'
import { assertTrue } from '../../../utils/type-assertions.js'
import { resolvePeer } from '../users/resolve-peer.js'
import { _normalizeInputStarGift } from './_normalize-input-star-gift.js'
/**
* Toggles whether one or more star gift is pinned to the top of the list
*/
export async function togglePinnedStarGifts(
client: ITelegramClient,
params: {
/** One or more gifts to pin */
gifts: MaybeArray<InputStarGift>
/** Peer where the gift is sent */
peer: InputPeerLike
},
): Promise<void> {
const gifts = await parallelMap(
Array.isArray(params.gifts) ? params.gifts : [params.gifts],
it => _normalizeInputStarGift(client, it),
)
const res = await client.call({
_: 'payments.toggleStarGiftsPinnedToTop',
stargift: gifts,
peer: await resolvePeer(client, params.peer),
})
assertTrue('payments.toggleStarGiftsPinnedToTop', res)
}

View File

@@ -515,6 +515,11 @@ export class Message {
return this.raw._ === 'message' && this.raw.videoProcessingPending!
}
/** If this message was paid, the number of stars spent sending it */
get sendPrice(): tl.Long | null {
return this.raw._ === 'message' ? this.raw.paidMessageStars ?? null : null
}
/**
* Generated permalink to this message, only for groups and channels
*

View File

@@ -491,6 +491,11 @@ export class Chat {
return getMarkedPeerId(this.raw.migratedTo)
}
/** If this chat has paid messages enabled, price of one message in stars */
get paidMessagePrice(): tl.Long | null {
return this.raw._ === 'channel' ? this.raw.sendPaidMessagesStars ?? null : null
}
/**
* Create a mention for the chat.
*

View File

@@ -374,6 +374,11 @@ export class FullChat extends Chat {
get starGiftsCount(): number {
return this.full._ === 'channelFull' ? this.full.stargiftsCount ?? 0 : 0
}
/** Whether you can enable paid messages in this chat */
get paidMessagesAvailable(): boolean {
return this.full._ === 'channelFull' && this.full.paidMessagesAvailable!
}
}
memoizeGetters(FullChat, [

View File

@@ -119,6 +119,48 @@ export class PeerSettings {
get geoDistance(): number | null {
return this.raw.geoDistance ?? null
}
/**
* Price of paid messages to this peer for the current user
* (note that this might differ from {@link User.paidMessagePrice},
* because the user might have added us to their contacts or wrote first,
* in which case the messages are free regardless)
*/
get paidMessagePrice(): tl.Long | null {
return this.raw.chargePaidMessageStars ?? null
}
/**
* Month and year when the user registered.
* Only available for users who contacted us first.
*/
get registrationDate(): string | null {
return this.raw.registrationMonth ?? null
}
/**
* ISO country code of the user's phone number.
* Only available for users who contacted us first.
*/
get phoneCountry(): string | null {
return this.raw.phoneCountry ?? null
}
/**
* Date when the user has last changed their name.
* Only available for users who contacted us first.
*/
get nameChangeDate(): Date | null {
return this.raw.nameChangeDate ? new Date(this.raw.nameChangeDate * 1000) : null
}
/**
* Date when the user has last changed their photo.
* Only available for users who contacted us first.
*/
get photoChangeDate(): Date | null {
return this.raw.photoChangeDate ? new Date(this.raw.photoChangeDate * 1000) : null
}
}
makeInspectable(PeerSettings)

View File

@@ -453,6 +453,11 @@ export class User {
return this.raw.profileColor ? new ChatColors(this.raw.id, this.raw.profileColor) : null
}
/** If this user has paid messages enabled, price of one message in stars */
get paidMessagePrice(): tl.Long | null {
return this.raw.sendPaidMessagesStars ?? null
}
/**
* Create a mention for the user.
*

View File

@@ -29,6 +29,11 @@ export class SavedStarGift {
return this.raw.refunded!
}
/** Whether this gift is pinned to the top of the list */
get pinned(): boolean {
return this.raw.pinnedToTop!
}
/** Whether this gift can be upgraded to a unique gift */
get canUpgrade(): boolean {
return this.raw.canUpgrade!

View File

@@ -29,6 +29,8 @@ import { StarGift } from './stars-gift.js'
* - `star_gift`: This transaction is either a star gift to a user (if outgoing), or converting a star gift to stars (if incoming)
* - `star_gift_upgrade`: This transaction is for a star gift upgrade
* - `star_gift_transfer`: This transaction is for a star gift transfer
* - `paid_message`: This transaction is a payment for a paid message
* - `premium_gift`: This transaction is a payment for a premium gift to a user
* - `api_*`: This transaction is a payment for paid API features
* - `api_floodskip`: This transaction is a payment for a paid bot broadcast
*/
@@ -142,6 +144,20 @@ export type StarsTransactionType =
/** The upgraded gift */
gift: StarGiftUnique
}
| {
type: 'paid_message'
/** Related peer */
peer: Peer
/** The number of messages paid for */
count: number
}
| {
type: 'premium_gift'
/** Related peer */
peer: Peer
/** Number of months paid for */
months: number
}
| {
type: 'api_floodskip'
/** The number of billed API calls */
@@ -248,6 +264,22 @@ export class StarsTransaction {
}
}
if (this.raw.paidMessages) {
return {
type: 'paid_message',
peer,
count: this.raw.paidMessages,
}
}
if (this.raw.premiumGiftMonths) {
return {
type: 'premium_gift',
peer,
months: this.raw.premiumGiftMonths,
}
}
if (this.raw.stargift) {
if (this.raw.stargift._ === 'starGift') {
return {

View File

@@ -15,6 +15,16 @@ function replaceType<
return Object.assign(obj, { _: type })
}
function dropFields<T extends tlCompat.TlObject, const Fields extends (keyof T)[]>(
obj: T,
fields: Fields,
): Omit<T, Fields[number]> {
for (let i = 0; i < fields.length; i++) {
delete obj[fields[i]]
}
return obj
}
function mapCompatStarGift(obj: tlCompat.TypeStarGift): tl.TypeStarGift {
switch (obj._) {
case 'starGiftUnique_layer197':
@@ -30,20 +40,30 @@ function mapCompatStarGift(obj: tlCompat.TypeStarGift): tl.TypeStarGift {
}
}
function mapCompatObject(obj: tlCompat.TlObject): tl.TlObject {
function mapCompatEmojiStatus(obj: tlCompat.TypeEmojiStatus): tl.TypeEmojiStatus {
switch (obj._) {
case 'starGiftUnique_layer197':
case 'starGiftUnique_layer198':
return mapCompatStarGift(obj)
case 'emojiStatus_layer197':
return {
...obj,
_: 'emojiStatus',
documentId: obj.documentId,
}
default:
return obj
}
}
function mapCompatMessageMedia(obj: tlCompat.TypeMessageMedia): tl.TypeMessageMedia {
switch (obj._) {
case 'messageMediaDocument_layer197':
return replaceType(obj, 'messageMediaDocument')
case 'channelFull_layer197':
return replaceType(obj, 'channelFull')
default:
return obj
}
}
function mapCompatMessageAction(obj: tlCompat.TypeMessageAction): tl.TypeMessageAction {
switch (obj._) {
case 'messageActionStarGiftUnique_layer197':
return {
...obj,
@@ -61,6 +81,45 @@ function mapCompatObject(obj: tlCompat.TlObject): tl.TlObject {
}
}
function mapCompatObject(obj: tlCompat.TlObject): tl.TlObject {
switch (obj._) {
case 'starGiftUnique_layer197':
case 'starGiftUnique_layer198':
return mapCompatStarGift(obj)
case 'emojiStatus_layer197':
return mapCompatEmojiStatus(obj)
case 'messageMediaDocument_layer197':
return mapCompatMessageMedia(obj)
case 'channelFull_layer197':
return replaceType(obj, 'channelFull')
case 'messageActionStarGiftUnique_layer197':
case 'messageActionStarGift_layer197':
return mapCompatMessageAction(obj)
case 'userFull_layer199':
return replaceType(dropFields(obj, ['premiumGifts']), 'userFull')
case 'user_layer199':
return {
...obj,
_: 'user',
emojiStatus: obj.emojiStatus ? mapCompatEmojiStatus(obj.emojiStatus) : undefined,
}
case 'channel_layer199':
return {
...obj,
_: 'channel',
emojiStatus: obj.emojiStatus ? mapCompatEmojiStatus(obj.emojiStatus) : undefined,
}
case 'message_layer199':
return {
...obj,
_: 'message',
media: obj.media ? mapCompatMessageMedia(obj.media) : undefined,
}
default:
return obj
}
}
function wrapReader(reader: (r: unknown) => unknown) {
return (r: unknown) => mapCompatObject(reader(r) as tlCompat.TlObject)
}

View File

@@ -2,7 +2,7 @@
TL schema and related utils used for mtcute.
Generated from TL layer **199** (last updated on 12.02.2025).
Generated from TL layer **200** (last updated on 08.03.2025).
## About

File diff suppressed because one or more lines are too long

View File

@@ -7,3 +7,8 @@ messageActionStarGiftUnique_layer197#26077b99 flags:# upgrade:flags.0?true trans
messageActionStarGift_layer197#d8f4f0a7 flags:# name_hidden:flags.0?true saved:flags.2?true converted:flags.3?true upgraded:flags.5?true refunded:flags.9?true can_upgrade:flags.10?true gift:StarGift message:flags.1?TextWithEntities convert_stars:flags.4?long upgrade_msg_id:flags.5?int upgrade_stars:flags.8?long = MessageAction;
// LAYER 198
starGiftUnique_layer198#f2fe7e4a flags:# id:long title:string slug:string num:int owner_id:flags.0?Peer owner_name:flags.1?string owner_address:flags.2?string attributes:Vector<StarGiftAttribute> availability_issued:int availability_total:int = StarGift;
// LAYER 199
userFull_layer199#4d975bbc flags:# blocked:flags.0?true phone_calls_available:flags.4?true phone_calls_private:flags.5?true can_pin_message:flags.7?true has_scheduled:flags.12?true video_calls_available:flags.13?true voice_messages_forbidden:flags.20?true translations_disabled:flags.23?true stories_pinned_available:flags.26?true blocked_my_stories_from:flags.27?true wallpaper_overridden:flags.28?true contact_require_premium:flags.29?true read_dates_private:flags.30?true flags2:# sponsored_enabled:flags2.7?true can_view_revenue:flags2.9?true bot_can_manage_emoji_status:flags2.10?true id:int53 about:flags.1?string settings:PeerSettings personal_photo:flags.21?Photo profile_photo:flags.2?Photo fallback_photo:flags.22?Photo notify_settings:PeerNotifySettings bot_info:flags.3?BotInfo pinned_msg_id:flags.6?int common_chats_count:int folder_id:flags.11?int ttl_period:flags.14?int theme_emoticon:flags.15?string private_forward_name:flags.16?string bot_group_admin_rights:flags.17?ChatAdminRights bot_broadcast_admin_rights:flags.18?ChatAdminRights premium_gifts:flags.19?Vector<PremiumGiftOption> wallpaper:flags.24?WallPaper stories:flags.25?PeerStories business_work_hours:flags2.0?BusinessWorkHours business_location:flags2.1?BusinessLocation business_greeting_message:flags2.2?BusinessGreetingMessage business_away_message:flags2.3?BusinessAwayMessage business_intro:flags2.4?BusinessIntro birthday:flags2.5?Birthday personal_channel_id:flags2.6?int53 personal_channel_message:flags2.6?int stargifts_count:flags2.8?int starref_program:flags2.11?StarRefProgram bot_verification:flags2.12?BotVerification = UserFull;
user_layer199#4b46c37e flags:# self:flags.10?true contact:flags.11?true mutual_contact:flags.12?true deleted:flags.13?true bot:flags.14?true bot_chat_history:flags.15?true bot_nochats:flags.16?true verified:flags.17?true restricted:flags.18?true min:flags.20?true bot_inline_geo:flags.21?true support:flags.23?true scam:flags.24?true apply_min_photo:flags.25?true fake:flags.26?true bot_attach_menu:flags.27?true premium:flags.28?true attach_menu_enabled:flags.29?true flags2:# bot_can_edit:flags2.1?true close_friend:flags2.2?true stories_hidden:flags2.3?true stories_unavailable:flags2.4?true contact_require_premium:flags2.10?true bot_business:flags2.11?true bot_has_main_app:flags2.13?true id:int53 access_hash:flags.0?long first_name:flags.1?string last_name:flags.2?string username:flags.3?string phone:flags.4?string photo:flags.5?UserProfilePhoto status:flags.6?UserStatus bot_info_version:flags.14?int restriction_reason:flags.18?Vector<RestrictionReason> bot_inline_placeholder:flags.19?string lang_code:flags.22?string emoji_status:flags.30?EmojiStatus usernames:flags2.0?Vector<Username> stories_max_id:flags2.5?int color:flags2.8?PeerColor profile_color:flags2.9?PeerColor bot_active_users:flags2.12?int bot_verification_icon:flags2.14?long = User;
channel_layer199#e00998b7 flags:# creator:flags.0?true left:flags.2?true broadcast:flags.5?true verified:flags.7?true megagroup:flags.8?true restricted:flags.9?true signatures:flags.11?true min:flags.12?true scam:flags.19?true has_link:flags.20?true has_geo:flags.21?true slowmode_enabled:flags.22?true call_active:flags.23?true call_not_empty:flags.24?true fake:flags.25?true gigagroup:flags.26?true noforwards:flags.27?true join_to_send:flags.28?true join_request:flags.29?true forum:flags.30?true flags2:# stories_hidden:flags2.1?true stories_hidden_min:flags2.2?true stories_unavailable:flags2.3?true signature_profiles:flags2.12?true id:int53 access_hash:flags.13?long title:string username:flags.6?string photo:ChatPhoto date:int restriction_reason:flags.9?Vector<RestrictionReason> admin_rights:flags.14?ChatAdminRights banned_rights:flags.15?ChatBannedRights default_banned_rights:flags.18?ChatBannedRights participants_count:flags.17?int usernames:flags2.0?Vector<Username> stories_max_id:flags2.4?int color:flags2.7?PeerColor profile_color:flags2.8?PeerColor emoji_status:flags2.9?EmojiStatus level:flags2.10?int subscription_until_date:flags2.11?int bot_verification_icon:flags2.13?long = Chat;
message_layer199#96fdbbe9 flags:# out:flags.1?true mentioned:flags.4?true media_unread:flags.5?true silent:flags.13?true post:flags.14?true from_scheduled:flags.18?true legacy:flags.19?true edit_hide:flags.21?true pinned:flags.24?true noforwards:flags.26?true invert_media:flags.27?true flags2:# offline:flags2.1?true video_processing_pending:flags2.4?true id:int from_id:flags.8?Peer from_boosts_applied:flags.29?int peer_id:Peer saved_peer_id:flags.28?Peer fwd_from:flags.2?MessageFwdHeader via_bot_id:flags.11?int53 via_business_bot_id:flags2.0?int53 reply_to:flags.3?MessageReplyHeader date:int message:string media:flags.9?MessageMedia reply_markup:flags.6?ReplyMarkup entities:flags.7?Vector<MessageEntity> views:flags.10?int forwards:flags.10?int replies:flags.23?MessageReplies edit_date:flags.15?int post_author:flags.16?string grouped_id:flags.17?long reactions:flags.20?MessageReactions restriction_reason:flags.22?Vector<RestrictionReason> ttl_period:flags.25?int quick_reply_shortcut_id:flags.30?int effect:flags2.2?long factcheck:flags2.3?FactCheck report_delivery_until_date:flags2.5?int = Message;

View File

@@ -1,6 +1,6 @@
{
"name": "@mtcute/tl",
"version": "199.1.0",
"version": "200.0.0",
"description": "TL schema used for mtcute",
"author": "alina sireneva <alina@tei.su>",
"license": "MIT",