forked from Txio-labs/txio-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.ts
More file actions
33 lines (29 loc) 路 1.09 KB
/
Copy pathclient.ts
File metadata and controls
33 lines (29 loc) 路 1.09 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
import { Bot } from "grammy";
import { config } from "../config.js";
import { escapeHtml } from "../utils/html.js";
export const bot = new Bot(config.telegramBotToken);
bot.on("message:new_chat_members", async (ctx) => {
for (const member of ctx.message.new_chat_members) {
if (member.id === ctx.me.id) continue; // the bot itself being added to the group
const name = escapeHtml(member.username ? `@${member.username}` : member.first_name);
await ctx.reply(
`馃憢 Welcome to Txio, ${name}! Feel free to introduce yourself. ` +
`Issue, PR, CI, and deploy updates for the project get posted here automatically.`,
{ parse_mode: "HTML" },
);
}
});
export async function sendMessage(
chatId: string | number,
html: string,
threadId?: number,
): Promise<void> {
await bot.api.sendMessage(chatId, html, {
parse_mode: "HTML",
link_preview_options: { is_disabled: true },
message_thread_id: threadId,
});
}
export async function notifyChannel(html: string, threadId?: number): Promise<void> {
return sendMessage(config.telegramChatId, html, threadId);
}