feat: POST /send-spotify

This commit is contained in:
Saahil 2024-10-26 17:46:28 -04:00 committed by GitHub
parent 4c2510aa80
commit 9fbc022f7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,6 +60,58 @@ export const app = new App({
);
},
},
{
path: "/send-spotify",
method: ["POST"],
async handler(req, res) {
const authHeader = req.headers["authorization"];
if (authHeader !== process.env.AUTH) {
res.writeHead(401).end();
return;
}
// pray this works
console.log(
require("body-parser").json()(req, res, async () => {
//@ts-ignore
console.log(req.body, 1);
//@ts-ignore
if (!req.body || Object.keys(req.body) == 0) {
res.writeHead(400).end();
return;
}
try {
await app.client.chat
.postMessage({
channel: "C07RE4N7S4B",
//@ts-expect-error
text: `:new_spotify: New Song: ${req.body.songurl} - added by <@${req.body.user}>`
})
.then((d) => {
app.client.chat.postMessage({
channel: "C07RE4N7S4B",
thread_ts: d.ts,
text: `:thread: Responses about new song here please!`,
}).then(() => {
//@ts-ignore
if (!req.body.noping) {
app.client.chat.postMessage({
channel: "C07RE4N7S4B",
text: `<!subteam^S07RGTY93J8>`,
})
}
res.writeHead(200);
res.end(JSON.stringify(d));
})
});
} catch (e: any) {
res.writeHead(500);
res.end(e.stack);
}
}),
);
},
},
],
});
export default app as ModifiedApp;