forked from TinyMoscow/BOT_PobedaSale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
72 lines (59 loc) · 1.79 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Telegraf, Markup, Scenes, session, Context } from "telegraf";
import { SessionContext } from "telegraf/typings/session";
import { sellScene } from "./sell";
interface Session {
foo: string;
}
type BaseBotContext = SessionContext<Session>;
interface BotContext extends BaseBotContext {
// session: Session;
}
const bot = new Telegraf<BotContext>(
"5733422116:AAFcCMIk7VejLmEnAlrhI-DHN1CIyprIsAM"
);
const stage = new Scenes.Stage<BotContext>([sellScene]);
bot.use(session()); // to be precise, session is not a must have for Scenes to work, but it sure is lonely without one
bot.use(stage.middleware());
bot.start((ctx: Context) =>
ctx.reply(
"Привет!\nЯ помогу тебе продать или купить форму.\nЖми /go и погнали!"
)
);
bot.help((ctx: Context) => ctx.reply("later"));
bot.command("go", async (ctx: Context) => {
try {
await ctx.replyWithHTML(
"Для начала определимся что нужно сделать...",
Markup.inlineKeyboard([
[
Markup.button.callback("Купить", "buy"),
Markup.button.callback("Продать", "sell"),
],
[Markup.button.callback("Мои товары", "showroom")],
])
);
} catch (e) {
console.error(e);
}
});
bot.action("sell", async (ctx: Context) => {
await ctx.scene.enter("sellScene");
});
bot.action("buy", async (ctx: Context) => {
try {
console.log(ctx);
} catch (e) {
console.error(e);
}
});
bot.action("showroom", async (ctx: Context) => {
try {
await ctx.reply("У вас пока нет товаров =(");
} catch (e) {
console.error(e);
}
});
bot.launch();
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));
process.once("SIGTERM", () => bot.stop("SIGTERM"));