Public
Script
October 23, 2023
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
import { sendToTelegram } from "https://esm.town/v/pomdtr/sendToTelegram";
import { secretToTelegramChat } from "https://esm.town/v/pomdtr/secretToTelegramChat";
export async function telegramWelcome(req: express.Request, res: express.Response) {
const { message } = req.body;
let secret: string;
// check if the secret is already set
for (
const [key, chatID] of Object.entries(
secretToTelegramChat,
)
) {
if (chatID == message.from.id) {
secret = key;
break;
}
}
if (secret == "") {
const { nanoid } = await import("npm:nanoid");
secret = nanoid();
secretToTelegramChat[secret] = message.from.id;
}
sendToTelegram(
secret,
`Your Secret is ${secret} - Instructions: https://www.val.town/v/pomdtr.telegram`,
);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023