-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebhook.js
More file actions
48 lines (38 loc) · 1.42 KB
/
Copy pathwebhook.js
File metadata and controls
48 lines (38 loc) · 1.42 KB
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
var properties = PropertiesService.getScriptProperties();
var bot = MaxBot.create(properties.getProperty("MAX_BOT_TOKEN"), {
apiVersion: "v1",
webhookSecret: properties.getProperty("MAX_WEBHOOK_SECRET"),
parseMode: "markdown",
});
function welcome(ctx) {
return ctx.reply("Здравствуйте!", {
keyboard: bot.keyboard
.callback("Помощь", "help")
.link("Открыть MAX", "https://max.ru")
.build(),
});
}
bot
.on("bot_started", welcome)
.command("start", welcome);
bot.hears(/привет/i, function (ctx) {
return ctx.reply("Привет!");
});
bot.action("help", function (ctx) {
return ctx.answerCallback({ notification: "Команды: /start" });
});
function doPost(e) { return bot.handleWebhook(e); }
function setupBot() {
bot.setMyCommands([{ name: "start", description: "Запустить бота" }]);
var url = "https://script.google.com/macros/s/<DEPLOYMENT_ID>/exec?secret=" +
encodeURIComponent(properties.getProperty("MAX_WEBHOOK_SECRET"));
return bot.subscribe(url, {
updateTypes: ["bot_started", "message_created", "message_callback"],
});
}
function removeCommands() { return bot.deleteMyCommands(); }
function removeWebhook() { return bot.unsubscribe(getWebhookUrl_()); }
function getWebhookUrl_() {
return "https://script.google.com/macros/s/<DEPLOYMENT_ID>/exec?secret=" +
encodeURIComponent(properties.getProperty("MAX_WEBHOOK_SECRET"));
}