tderflinger / audio-tapir-function

Backend serverless function for sending audio data in an email as attachment.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

audio-tapir-function

This is the backend serverless function for the corresponding Vue 3 component vue-audio-tapir.

It is a Netlify function and sends an email using the Sendgrid service to a destination email address. The email contains the recorded audio message as an attachment.

Therefore, in order to use this function, you must register at Netlify. They have a free service level for serverless functions.

Architecture Overview

The developer includes the vue-audio-tapir component in his Vue 3 website. When the user of the website wants to leave a voice message, he records his message and submits it. Vue-audio-tapir contacts the backend server, this Netlify serverless function and uploads the audio data. The serverless backend function sends the audio data to an email address using the email service Sendgrid. Finally the email with the voice message arrives at the destination, probably the email application of the website owner.

Install

cd netlify/functions/audio-message
npm i

or

cd netlify/functions/audio-message
yarn

Develop

You need to have the Netlify CLI installed in order to run the function on your local machine.

netlify dev

Run from base directory.

Deploy

netlify deploy --prod

Environment Variables

The function uses the Sendgrid service, therefore you need to register there and obtain an API key. They have a free service level.

The API key must be in the environment variable SENDGRID_API_KEY.

Other variables are EMAIL_TO, the email address of the destination and EMAIL_FROM, the email address that appears as the sender.

When you deploy the function, these environment variables need to be added manually in the Netlify function dashboard.

You find the environment variables section under Site setting -> Build & Deploy -> Environment.

Decode Attachment

In order to listen to the message once the email arrives, you need to BASE64 decode the attachment file.

For example, run the following command on Linux:

base64 -d audio-message.wav >audio-message-dec.wav

References

Thanks for the article by Jabali Ndungu on dev.to regarding "Handling CORS with Netlify POST Requests".

License

MIT license

About

Backend serverless function for sending audio data in an email as attachment.

License:MIT License


Languages

Language:TypeScript 100.0%