Telegraf Join-Left Chat Handler

mail@pastecode.io avatar
unknown
typescript
a year ago
656 B
22
Indexable
Never
import { Telegraf } from "telegraf";

const app = new Telegraf("");

app.on("chat_member", async (ctx) => {
  const oldChatMember = ctx.chatMember.old_chat_member;
  const newChatMember = ctx.chatMember.new_chat_member;
  const oldChatJoinStatuses = ["left", "kicked"];
  const oldChatLeftStatuses = ["member", "restricted"];

  if (newChatMember.status === "member" && oldChatJoinStatuses.includes(oldChatMember.status)) {
    // member join
  } else if (newChatMember.status === "left" && oldChatLeftStatuses.includes(oldChatMember.status)) {
    // member left
  }
});
const allowedUpdates = ["message", "chat_member"];

app.launch({ allowedUpdates });