0
votes

Hello guys im treyng to implement a new call foward ivr system for my twilio number but i been having a problem with one of my function and i hope you guys cam help in some way.

So Im trying to record all the calls that i receive and on top of that have a voicemail option. Here is how im going.

On twiml i crate an action to go to reddirect to voicemail after time out, Than i use recordingStatusCallback to record the call tha dont go to voicemail and both work perfectly but when i receive the record from the function that i execute on recordingStatusCallback the email doesnt show the callFrom and Callto (come back ans undefined) and i did my research anf find out thar recordingStatusCallback parameter results dont have the callFrom and callTo parameters. Im wondering if is a way to store that result temporarlly from when i receive the call so i have on my email or get the results from other functions. Please see part of the code below. This is the twiml dial and number parameters.

const dial = twiml.dial({
timeout: 20,
method: 'GET',
action: 'voicemail',
record: 'record-from-answer',
recordingStatusCallback: 'recording',
callerId: context.TWILIO_PHONE_NUMBER,
});

dial.number({url: 'whisper',}, context.MY_PHONE_NUMBER);

This is the sfunction to send a copu of the recorded conversation.

        //Initialize SendGrid Mail Client
const sgMail = require('@sendgrid/mail');

// Define Handler function required for all Twilio Functions
exports.handler = function(context, event, callback) {

// Build SG mail request
sgMail.setApiKey(context.SENDGRID_API_SECRET);
// Define message params
const msg = {
to: context.TO_EMAIL_ADDRESS,
from: context.FROM_EMAIL_ADDRESS,
subject: 'New Call Received',

      html: `Hi ${context.LEADGEN_NAME},<br> 
      <p><strong>This is a friendly notification that you received the follwing call:</strong></p>
      <p><strong>Call From (Client): </strong></p>${event.Caller}<br>
      <p><strong>Call to: </strong></p>${event.To}<br>
      <p>You are receiving this email because you are subscribed to email alerts for ${context.LEADGEN_NAME} tracking numbers.</p>
      <p>Thanks, </p>
      <p><strong>Recorded link </strong></p>${event.RecordingUrl}<br>
      <p><strong>Fuel Marketing Solutions </strong></p>`,
   };
    // Send message
    sgMail.send(msg)
    .then(response => {
        console.log("Neat.")
        callback();
    })
    .catch(err => {
        console.log("Not neat.")
        callback(err);
    });

1

1 Answers

0
votes

You can fix this by adding parameters in the recordingStatusCallback url.

let actionUrl = `https://${DOMAIN_NAME}/${URL_PATH}?callTo=${callTo}&callFrom=${callFrom}`;

const dial = twiml.dial({
timeout: 20,
method: 'GET',
action: 'voicemail',
record: 'record-from-answer',
recordingStatusCallback: actionUrl,
callerId: context.TWILIO_PHONE_NUMBER,
});