Guides

Ephemeral MessagesBOT-ONLY

Bot Walkthrough 8 of 18

Bots can reply to commands with messages that are visible only to the user who sent the command.

Enabling Ephemeral Commands

Register the command with setMyCommands and set isEphemeral to true.

await client.setMyCommands([
  {
    command: "help",
    description: "Show help",
    isEphemeral: true,
  },
]);

Only bot commands with isEphemeral enabled can use ephemeral messages.

Replying to Ephemeral Commands

Context reply methods detect ephemeral commands and send their replies to the same user automatically.

client.command("help", async (ctx) => {
  await ctx.reply("This message is visible only to you.");
});

Editing and Deleting Ephemeral Messages

Inside a handler, use the context shortcuts. They use the current chat automatically.

await ctx.editEphemeralMessageText(receiverUserId, messageId, "Updated message.");
await ctx.deleteEphemeralMessage(receiverUserId, messageId);

Outside a handler, use editEphemeralMessageText and deleteEphemeralMessage and pass the chat ID explicitly.

await client.editEphemeralMessageText(chatId, receiverUserId, messageId, "Updated message.");
await client.deleteEphemeralMessage(chatId, receiverUserId, messageId);