-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.ts
33 lines (23 loc) · 803 Bytes
/
bot.ts
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, session } from "grammy";
import { DenoKVAdapter } from "grammy/storage";
import { AppContext } from "./domain/index.ts";
import AppModule from "./modules/index.ts";
import { initialStorage } from "./utils/initial-storage.ts";
import { COMMAND_DESCRIPTION } from "./utils/command-description.ts";
if (Deno.env.get("MODE") !== "production") {
await import("deno:dotenv/load");
}
const BOT_TOKEN = Deno.env.get("BOT_TOKEN");
if (!BOT_TOKEN) throw new Error("Missing BOT_TOKEN env");
const bot = new Bot<AppContext>(BOT_TOKEN);
const kv = await Deno.openKv();
bot.use(
session({
initial: initialStorage,
storage: new DenoKVAdapter(kv),
}),
);
bot.use(AppModule);
bot.api.setMyCommands(COMMAND_DESCRIPTION);
bot.catch((err) => console.error(err.error));
export { bot };