Initial commit

This commit is contained in:
2023-05-09 22:08:39 +03:00
commit a341d01f0c
6 changed files with 245 additions and 0 deletions

30
index.ts Normal file
View File

@@ -0,0 +1,30 @@
const BOT_TOKEN = process.env.BOT_TOKEN as string
const CHAT_ID = process.env.CHAT_ID as string
const server = Bun.serve({
port: 3000,
async fetch(req) {
if (!req.body) {
throw new Error("woops!");
}
const submittedData: { email: unknown, where: unknown } = await req.json();
const text = encodeURIComponent(`
*Новое письмо с flexpatrol.ru*
\`\`\`
email: ${submittedData.email}
на че наклеешь: ${submittedData.where}
\`\`\`
`)
await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${CHAT_ID}&text=${text}&parse_mode=markdown`)
return new Response('success', {
headers: {
'Access-Control-Allow-Origin': '*'
}
});
},
});
console.log(`Listening on http://localhost:${server.port}...`);