service events
telegram sends many changes as updates or service messages: joins, leaves, reactions, pins, payments, forum topic changes, boosts, and chat migrations.
new members
bot.on("message", async (ctx) => {
const members = ctx.message?.new_chat_members;
if (!members?.length) return;
await ctx.reply("welcome " + members.map((u) => u.first_name).join(", "));
});reactions
reaction updates are not part of the default update set. add message_reaction to allowedUpdates when polling.
bot.on("message_reaction", async (ctx) => {
const reaction = ctx.update.message_reaction!;
console.log(reaction.user?.id, reaction.old_reaction, reaction.new_reaction);
});pinned messages
bot.on("message", async (ctx) => {
if (!ctx.message?.pinned_message) return;
await ctx.reply("new pinned message");
});common service fields
| field/update | what it means |
|---|---|
new_chat_members | users joined a group |
left_chat_member | a user left or was removed |
pinned_message | a message was pinned |
successful_payment | a payment completed |
forum_topic_created | a forum topic was created |
message_reaction | a user changed reactions on a message |
service events are normal bot logic. route them, test them with @yaebal/test, and include them in
allowedUpdates when telegram does not send them by default.