router.post('/webhook', securityMiddleware, async (req: Request, res: Response) => {
const payload: WebhookPayload = req.body as WebhookPayload;
if (payload.type === "call") {
const data: Call = payload.data as Call;
if (data.recording_wav) {
// convert base64 string to a buffer
const recordingBuffer = Buffer.from(data.recording_wav, "base64");
const fileName = `RECORDING-${Date.now()}.wav`;
// write the file locally or upload to cloud
await fs.writeFile(fileName, recordingBuffer);
// await uploadFileToS3('recordings', fileName, recordingBuffer);
}
}
});