Initial commit
This commit is contained in:
30
index.ts
Normal file
30
index.ts
Normal 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}...`);
|
||||
Reference in New Issue
Block a user