3

That end point was removed with new version of telgraf https://github.com/telegraf/telegraf/releases/tag/v4.0.0#:~:text=ctx.updateSubTypes

How we can detect the message type with new API

enter image description here

this is the old ctx retrun

Hasan Tezcan
  • 1,116
  • 1
  • 11
  • 23

2 Answers2

3

This is an alternative usage to ctx.updatesubtypes AKA getting message type in telegraf 3.

bot.use((ctx, next) => {
    console.log(`Message Type is: ${getMessageType(ctx.message)}`); 
    // Message Type is: STICKER or Message Type is: TEXT
});
const getMessageType = (message) => {
    var keys = Object.keys(message);
    var messageType = keys.pop();
    console.log(messageType);
    return messageType.toUpperCase();
};

source is: https://stackoverflow.com/a/58052712/10694425

Hasan Tezcan
  • 1,116
  • 1
  • 11
  • 23
0

A good alternative to using ctx.updatesubtypes in 4.6.0 is:

bot.use((ctx, next) => {
  let message_type = "";
  let keys = Object.keys(ctx.message);
  
  if (keys.includes("text")) {
    message_type = "text";
  } else if (keys.includes("sticker")) {
    message_type = "sticker";
  } else if (keys.includes("photo")) {
    message_type = "photo";
  }
  console.log(`Message Type is: ${message_type}`);
  next();
});