-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
contact.ts
61 lines (56 loc) · 1.36 KB
/
contact.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
import type { APIRoute } from 'astro';
export const prerender = false;
export const POST: APIRoute = async ({ request }) => {
const data = await request.formData();
const name = data.get('name');
const email = data.get('email');
const message = data.get('message');
// Validate the data - you'll probably want to do more than this
if (!name || !email || !message) {
return new Response(
JSON.stringify({
message: 'Missing required fields'
}),
{ status: 400 }
);
}
await fetch(import.meta.env.SLACK_WEBHOOK, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*Name:* ${name}`
}
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*Email:* ${email}`
}
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: `*Message:* ${message}`
}
}
]
})
});
// Do something with the data, then return a success response
return new Response(
JSON.stringify({
message: `Thanks for contacting us! We'll be in touch soon.`
}),
{ status: 200 }
);
};