forked from TinyMoscow/BOT_PobedaSale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsell.ts
89 lines (73 loc) · 2.16 KB
/
sell.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { Markup, Scenes, Context } from "telegraf";
interface SessionData {
heyCounter: number;
}
interface BotContext extends Context {
session?: SessionData;
}
const dictionary = {
coat: "Плащ",
jacket: "Пуховик",
blazer: "Пиджак",
pants: "Брюки",
vest: "Жилет",
shirt: "Сорочка",
bag: "Сумка",
suitcase: "Чемодан",
shoes: "Обувь",
other: "Прочее",
};
const button = (name) => {
let text = dictionary[name];
return Markup.button.callback(text, name);
};
const keyboard = () => {
const arr = Object.keys(dictionary);
const splitter = (arr, chunkSize) => {
const res = [];
for (let i = 0; i < arr.length; i += chunkSize) {
const chunk: any[] = arr.slice(i, i + chunkSize);
res.push(chunk);
}
return res;
};
return splitter(
arr.map((key) => {
return button(key);
}),
2
);
};
export const sellScene = new Scenes.BaseScene("sellScene");
sellScene.enter((ctx) => {
ctx.reply(
"Что будем продавать? ",
// keyboard()
Markup.inlineKeyboard(keyboard())
);
});
sellScene.on("callback_query", (ctx) => {
let type = dictionary[ctx.update.callback_query.data];
ctx.editMessageText(`Отлично, ты выбрал ${type}\nТеперь пришли фотку`); //Empty markup
});
// sellScene.action("coat", (ctx) => {
// // const type = ctx.callbackQuery;
// ctx.reply(`Отлично ты выбрал Плащ`);
// });
// SellScene.action("THEATER_ACTION", (ctx) => {
// ctx.reply("You choose theater");
// ctx.session.myData.preferenceType = "Theater";
// return ctx.scene.enter("SOME_OTHER_SCENE_ID"); // switch to some other scene
// });
// SellScene.action("MOVIE_ACTION", (ctx) => {
// ctx.reply("You choose movie, your loss");
// ctx.session.myData.preferenceType = "Movie";
// return ctx.scene.leave(); // exit global namespace
// });
// SellScene.leave((ctx) => {
// ctx.reply("Thank you for your time!");
// });
// // What to do if user entered a raw message or picked some other option?
// SellScene.use((ctx) =>
// ctx.replyWithMarkdown("Please choose either Movie or Theater")
// );