Handling Recording Format

Recordings will be sent to your webhooks in the key recording_wav as base64 string buffers.

Use Buffer.from to convert the base64 string into a writable buffer, like so:

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);
    }
  }
});

Extra Server Middleware

Make sure to use the express.json({ limit: '1gb' }) middleware on your server to allow incoming large payloads.