-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (38 loc) · 1.13 KB
/
index.js
File metadata and controls
44 lines (38 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require(`dotenv`).config();
const { Telegraf } = require(`telegraf`);
const bot = new Telegraf(process.env.BOT_TOKEN);
bot.catch(console.log);
bot.command([`start`, `help`], ctx => {
if (ctx.chat.type !== `private`) {
return;
}
ctx.reply(
`Hi, I'm a bot to unpin messages in your group when you post on the connected channel.`,
);
});
bot.on(`message`, async ctx => {
if (ctx.message.sender_chat?.type === `channel`) {
try {
await ctx.unpinChatMessage(ctx.message.message_id);
} catch (error) {
console.error(error);
}
}
});
if (process.env.PORT && process.env.WEBHOOK_URL) {
bot.launch({
webhook: {
domain: process.env.WEBHOOK_URL,
port: process.env.PORT,
},
}).then(() =>
console.log(
`Bot is Online 🚀\nDOMAIN: ${process.env.WEBHOOK_URL}\nPORT: ${process.env.PORT}`,
),
);
} else {
bot.launch().then(() => console.log('Bot is Online 🚀'));
}
// Enable graceful stop
process.once('SIGINT', () => bot.stop('SIGINT'));
process.once('SIGTERM', () => bot.stop('SIGTERM'));