I'm trying to log my data from my bot and I use this script:
bot.use((ctx, next) => {
console.log(ctx.from);
if(ctx.updateSubTypes[0] == "text") {
bot.telegram.sendMessage(-4..5, "@" + ctx.from.username + " said: " + ctx.message.text)
} else {
bot.telegram.sendMessage(-4..5, "@" + ctx.from.username + " sent a " + ctx.updateSubTypes[0]);
}
next();
})
This code works well with the usernames, but what if the user doesn't have one. I would like to know if there is a possibility to have the first_name with a link to the user profile using just the user ID, so I could anytime check the profile of users who are running my bot.
Thank you in advance!
I got it to work like this:
bot.use((ctx, next) => {
if(ctx.updateSubTypes[0] == "text") {
bot.telegram.sendMessage(-4..5, `<a href="tg://user?id=${ctx.from.id}">${ctx.from.first_name}</a> sent : ${ctx.message.text}`, {parse_mode: 'HTML'})
} else {
bot.telegram.sendMessage(-4..5, `<a href="tg://user?id=${ctx.from.id}">${ctx.from.first_name}</a> sent a ${ctx.updateSubTypes[0]}`, {parse_mode: 'HTML'})
}
next();
})
I hope this will help you in case you have the same issue.
ctx.updateSubTypes
is no longer supported after telegraf 4.0.3
.
But I don't know what is the new alternative for this method?
Check out => https://github.com/telegraf/telegraf/releases/tag/v4.0.0#:~:text=Remove%20ctx.updateSubTypes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.