import { Api } from 'telegram' ; import { Snake } from '../../client' ; import { TypeReplyMarkup , BuildReplyMarkup } from '../../Utils/ReplyMarkup' ; import { Entities , ParseEntities } from '../../Utils/Entities' ; import { _parseMessageText } from 'telegram/client/messageParse' ; import BigInt from 'big-integer' ; import * as Update from '../../Update' ; export interface editMessageMoreParams { noWebpage ? : boolean ; media ? : Api . TypeInputMedia ; replyMarkup ? : TypeReplyMarkup ; entities ? : Entities [ ] ; scheduleDate ? : number ; parseMode ? : string ; } export async function EditMessage ( snakeClient , chatId , messageId , text , more ? ) { try { let parseMode = '' ; let replyMarkup ; if ( more ) { if ( more . parseMode ) { parseMode = more . parseMode . toLowerCase ( ) ; delete more . parseMode ; } } let [ parseText , entities ] = await _parseMessageText ( snakeClient . client , text , parseMode ) ; if ( more ) { if ( more . entities ) { entities = await ParseEntities ( more . entities ) ; parseText = text ; } if ( more . replyMarkup ) { replyMarkup = BuildReplyMarkup ( more . replyMarkup ! ) ; delete more . replyMarkup ; } } let results = await snakeClient . client . invoke ( new Api . messages . EditMessage ( { peer : chatId , id : messageId , message : parseText , entities : entities , replyMarkup : replyMarkup , ... more , } ) ) ; return await createResults ( results , snakeClient ) ; } catch ( error ) { return snakeClient . _handleError ( error , `telegram.editMessage(${ chatId },${ messageId },${ text },${ more ? JSON . stringify ( more , null , 2 ) : '' })` ) ; } } async function createResults ( results , snakeClient ) { if ( results instanceof Api . Updates ) { results as Api . Updates ; if ( results . updates ?. length > 0 ) { for ( let i = 0 ; i < results . updates . length ; i ++ ) { if ( results . updates [ i ] instanceof Api . UpdateEditChannelMessage ) { let arc = results . updates [ i ] as Api . UpdateEditChannelMessage ; return arc ; } if ( results . updates [ i ] instanceof Api . UpdateEditMessage ) { let arc = results . updates [ i ] as Api . UpdateEditMessage ; return arc ; } } } } }