forked from spkesDE/com.spkes.telegramNotifications
-
Notifications
You must be signed in to change notification settings - Fork 0
/
question.ts
82 lines (79 loc) · 2.43 KB
/
question.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
import { Markup } from "telegraf";
import { InlineKeyboardButton } from "telegraf/typings/core/types/typegram";
import { TelegramNotifications } from "./app";
export default class Question {
question: string = "";
UUID: string = "";
buttons: string[] = [];
keepButtons: boolean = false;
disable_notification: boolean = false;
columns: number = 2;
static async createMessage(
q: Question,
app: TelegramNotifications,
userId: number,
messageOverride?: string,
customId?: string,
image?: string,
topic?: number
) {
let callbackButtons: InlineKeyboardButton.CallbackButton[] = [];
q.buttons.forEach((value, i) => {
let id = q.UUID + "." + i;
if (customId != undefined && customId.length < 21) id += "." + customId;
callbackButtons.push(Markup.button.callback(value, id));
});
if (image != undefined) {
app.bot?.telegram
.sendPhoto(
userId,
{ filename: "", url: image },
{
caption:
messageOverride == undefined ? q.question : messageOverride,
disable_notification: q.disable_notification ?? false,
message_thread_id: topic ?? undefined,
...Markup.inlineKeyboard(callbackButtons, {
columns: q.columns ?? 2,
}),
}
)
.then((response) => {
if (customId != undefined && customId.length < 21) {
app.customIdMessages.push({
message_id: response.message_id,
chat_id: response.chat.id,
customId: customId,
});
}
})
.catch(app.error);
} else {
app.bot?.telegram
.sendMessage(
userId,
messageOverride == undefined ? q.question : messageOverride,
{
disable_notification: q.disable_notification ?? false,
message_thread_id: topic ?? undefined,
...Markup.inlineKeyboard(callbackButtons, {
columns: q.columns ?? 2,
}),
}
)
.then((response) => {
if (customId != undefined && customId.length < 21) {
app.customIdMessages.push({
message_id: response.message_id,
chat_id: response.chat.id,
customId: customId,
});
}
})
.catch(app.error);
}
}
static getAnswer(q: Question, answerId: number) {
return q.buttons[answerId];
}
}