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.
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.
cd netlify/functions/audio-message
npm i
or
cd netlify/functions/audio-message
yarn
You need to have the Netlify CLI installed in order to run the function on your local machine.
netlify dev
Run from base directory.
netlify deploy --prod
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
.
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
Thanks for the article by Jabali Ndungu on dev.to
regarding "Handling CORS with Netlify POST Requests".
MIT license