Created
November 24, 2020 23:36
-
-
Save ambiorixg12/b72756e7d4a3a03ccdf8c9dd4497af22 to your computer and use it in GitHub Desktop.
twilio voice to email trnascripted
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ////// email function | |
| //Initialize SendGrid Mail Client | |
| const sgMail = require('@sendgrid/mail'); | |
| // Define Handler function required for all Twilio Functions | |
| exports.handler = function(context, event, callback) { | |
| let twiml = new Twilio.twiml.VoiceResponse(); | |
| // Build SG mail request | |
| sgMail.setApiKey(context.SENDGRID_API_KEY); | |
| // Define message params | |
| const msg = { | |
| to: context.TO_EMAIL_ADDRESS, | |
| from: context.FROM_EMAIL_ADDRESS, | |
| text: `Body : ${event.TranscriptionText} \n Recording URL is: ${event.RecordingUrl}`, | |
| subject: `New Voicemail from: ${event.From}`, | |
| }; | |
| // Send message | |
| sgMail.send(msg) | |
| .then(response => { | |
| console.log(`TranscriptionText ${event.TranscriptionText} `) | |
| console.log(`Recording URL is: ${event.CallSid} ${event.RecordingUrl} ${context.FROM_EMAIL_ADDRESS}`) | |
| callback(); | |
| }) | |
| .catch(err => { | |
| console.log("Not neat.") | |
| callback(err); | |
| }); | |
| }; | |
| /////////////////////////////// | |
| //hangup function | |
| exports.handler = function(context, event, callback) { | |
| let twiml = new Twilio.twiml.VoiceResponse(); | |
| twiml.hangup(); | |
| callback(null, twiml); | |
| }; | |
| /////////////////// | |
| Twiml voicemail | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <Response> | |
| <Play> | |
| https://www.norcal-roofing.com/audio/norcal-roofing-voicemail-pro.mp3 | |
| </Play> | |
| <Record | |
| maxLength="120" | |
| finishOnKey="*" | |
| action="https://peach-kudu-6968.twil.io/hangup" | |
| transcribeCallback="https://peach-kudu-6968.twil.io/vm" | |
| /> | |
| <Hangup/> | |
| <Say> | |
| Goodbye. | |
| </Say> | |
| <Hangup /> | |
| </Response> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment