-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (28 loc) · 862 Bytes
/
index.js
File metadata and controls
32 lines (28 loc) · 862 Bytes
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
import bot, { message } from "./lib/connection.js";
import { requestApi } from "./lib/components.js";
import { printer } from "./lib/logger.js";
bot.command(
"start",
async (ctx) =>
await ctx.reply("*Telegram Chat Bot*\n\nSilahkan mulai percakapan\\.", {
parse_mode: "MarkdownV2",
})
);
bot.on(message(), async (ctx) => {
const message = (ctx.update || ctx).message;
try {
const result = await requestApi(message.text);
await ctx.reply(result);
} catch (error) {
console.log(error);
await ctx.reply("error, please check log");
} finally {
printer(ctx);
}
});
bot.launch({ dropPendingUpdates: true }, async () =>
console.log("logged in as", (await bot.telegram.getMe()).username)
);
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));