0
votes

Twilio Stuido does not provide a native way to email a recording therefore this needs to be coded. In this example, a voicemail has been taken of a users call. Now that we have the recording a Twilio Function is created (NodeJS) to send this recording to email.

In the sample code below the function is failing however there is no available debug tool inside the Twilio Console for dealing with functions. NodeJS is fairly new to us so this maybe easy for someone to spot.

Possible other errors may be however:

  1. Incorrect gmail authentication (although the details are correct in terms of username and password, perhaps this is not how you configure google apps to send the email)
  2. Inability to import or incorrectly importation of the nodemailer dependency into Twilio
  3. Bad NodeJS skills

The input variables are:

attachment {{widgets.Voicemail_Recording.RecordingUrl}} - which contains the URL to the voicemail recording.

lang - the language of the caller (based on IVR choices earlier).

phone_number {{trigger.call.From}}

NodeJS Twilio Function

var mailer = require('nodemailer');
mailer.SMTP = {
    host: 'smtp.gmail.com', 
    port:587,
    use_authentication: true, 
    user: '[email protected]',
    pass: '*********'
};

exports.handler = function(context, event, callback) {

    mailer.send_mail({       
        sender: event.phone_number + '<[email protected]>',
        to: '[email protected]',
        subject: 'Voicemail (' + event.lang + ')',
        body: 'mail content...',
        attachments: [{'filename': event.attachment, 'content': data}]
    }), function(err, success) {
        if (err) {

        }

    }
};
1
Have you added nodemailer as a dependency in the Twilio Functions config?philnash
Did you ever get this working? If so, can you share your solution.Kevin Green

1 Answers

3
votes

Sam here from Twilio's support team - I just released a blog post that should help with this. It shows how to forward voicemails with Studio, Functions, and SendGrid. Check it out here: https://www.twilio.com/blog/forward-voicemail-recordings-to-email