-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsell.ts
62 lines (53 loc) · 1.47 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
import { Markup, Scenes, Context } from "telegraf";
import { MyContext } from "./types";
type TDictionary = Record<string, string>;
const dictionary: TDictionary = {
coat: "Плащ",
jacket: "Пуховик",
blazer: "Пиджак",
pants: "Брюки",
vest: "Жилет",
shirt: "Сорочка",
bag: "Сумка",
suitcase: "Чемодан",
shoes: "Обувь",
other: "Прочее",
};
const button = (name: string) => {
const text = dictionary[name as string];
return Markup.button.callback(text, name);
};
const keyboard = () => {
const arr = Object.keys(dictionary);
const splitter = (arr: any[], chunkSize: number) => {
const res: any[] = [];
for (let i = 0; i < arr.length; i += chunkSize) {
const chunk = arr.slice(i, i + chunkSize);
if (chunk) {
res.push(chunk);
}
}
return res;
};
return splitter(
arr.map((key) => {
return button(key);
}),
2
);
};
export const sellScene = new Scenes.BaseScene<MyContext>("sellScene");
sellScene.enter((ctx) => {
ctx.reply(
"Что будем продавать? ",
// keyboard()
Markup.inlineKeyboard(keyboard())
);
});
sellScene.on("callback_query", (ctx) => {
if (ctx?.update?.callback_query?.data) {
const name: string = ctx?.update?.callback_query?.data;
const text = dictionary[name];
ctx.editMessageText(`Отлично, ты выбрал ${text}\nТеперь пришли фотку`); //Empty markup
}
});