import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
import process from "node:process";
export const slackReplyToMessage = async (req: Request) => {
const body = await req.json();
if (body.token !== process.env.slackVerificationToken) {
return new Response(undefined, { status: 401 });
}
if (body.challenge) {
return Response.json({ challenge: body.challenge });
}
if (body.event.type === "app_mention") {
const result = await fetchJSON(
"https://slack.com/api/chat.postMessage",
{
headers: {
"Authorization": `Bearer ${process.env.slackToken}`,
},
method: "POST",
body: JSON.stringify({
channel: body.event.channel,
thread_ts: body.event.ts,
text: "Hello, ~World~ from Val Town!",
}),
},
);
console.log(result);
}
};