GramJS

messages.EditMessage

Edit message

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.messages.EditMessage({
      peer: "username",
      id: 43,
      noWebpage: true,
      message: "Hello there!",
      media: new Api.InputMediaUploadedPhoto({
        file: await client.uploadFile({
          file: new CustomFile(
            "file.bin",
            fs.statSync("../file.bin").size,
            "../file.bin"
          ),
          workers: 1,
        }),
        stickers: [
          new Api.InputDocument({
            id: BigInt("-4156887774564"),
            accessHash: BigInt("-4156887774564"),
            fileReference: Buffer.from("arbitrary data here"),
          }),
        ],
        ttlSeconds: 43,
      }),
      scheduleDate: 43,
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.Updates = await client.invoke(
    new Api.messages.EditMessage({
      peer: "username",
      id: 43,
      noWebpage: true,
      message: "Hello there!",
      media: new Api.InputMediaUploadedPhoto({
        file: await client.uploadFile({
          file: new CustomFile(
            "file.bin",
            fs.statSync("../file.bin").size,
            "../file.bin"
          ),
          workers: 1,
        }),
        stickers: [
          new Api.InputDocument({
            id: BigInt("-4156887774564"),
            accessHash: BigInt("-4156887774564"),
            fileReference: Buffer.from("arbitrary data here"),
          }),
        ],
        ttlSeconds: 43,
      }),
      scheduleDate: 43,
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
flags#Flags, see TL conditional fields
noWebpageflags.1?trueDisable webpage preview
peerInputPeerWhere was the message sent
idintID of the message to edit
messageflags.11?stringNew message
mediaflags.14?InputMediaNew attached media
replyMarkupflags.2?ReplyMarkupReply markup for inline keyboards
entitiesflags.3?Vector<MessageEntity>Message entities for styled text
scheduleDateflags.15?intScheduled message date for scheduled messages

Result

Updates

Possible errors

CodeTypeDescription
400BUTTON_DATA_INVALIDThe data of one or more of the buttons you provided is invalid.
400BUTTON_TYPE_INVALIDThe type of one or more of the buttons you provided is invalid.
400BUTTON_URL_INVALIDButton URL invalid.
400CHANNEL_INVALIDThe provided channel is invalid.
400CHANNEL_PRIVATEYou haven't joined this channel/supergroup.
403CHAT_ADMIN_REQUIREDYou must be an admin in this chat to do this.
403CHAT_WRITE_FORBIDDENYou can't write in this chat.
400ENTITIES_TOO_LONGYou provided too many styled message entities.
403INLINE_BOT_REQUIREDOnly the inline bot can edit message.
400INPUT_USER_DEACTIVATEDThe specified user was deleted.
400MEDIA_CAPTION_TOO_LONGThe caption is too long.
400MEDIA_GROUPED_INVALIDYou tried to send media of different types in an album.
400MEDIA_NEW_INVALIDThe new media is invalid.
400MEDIA_PREV_INVALIDPrevious media invalid.
403MESSAGE_AUTHOR_REQUIREDMessage author required.
400MESSAGE_EDIT_TIME_EXPIREDYou can't edit this message anymore, too much time has passed since its creation.
400MESSAGE_EMPTYThe provided message is empty.
400MESSAGE_ID_INVALIDThe provided message id is invalid.
400MESSAGE_NOT_MODIFIEDThe provided message data is identical to the previous message data, the message wasn't modified.
400MESSAGE_TOO_LONGThe provided message is too long.
400MSG_ID_INVALIDInvalid message ID provided.
400PEER_ID_INVALIDThe provided peer id is invalid.
400REPLY_MARKUP_INVALIDThe provided reply markup is invalid.
400SCHEDULE_DATE_INVALIDInvalid schedule date provided.
400USER_BANNED_IN_CHANNELYou're banned from sending messages in supergroups/channels.

Can bots use this method?

Yes

Styled text with message entities

How to create styled text with message entities

Scheduled messages

Telegram allows scheduling messages