Twilio 录音和语音信箱功能

问题描述

大家好,我正在为我的 twilio 号码实施一个新的呼叫转发 ivr 系统,但我的一个功能遇到了问题,我希望你们能以某种方式提供帮助。

所以我试图记录我收到的所有电话,此外还有一个语音邮件选项。这是我的方式。

在 twiml 上,我创建了一个操作,以便在超时后转到 reddirect 到语音邮件,而不是我使用 RecordingStatusCallback 来录制不转到语音邮件的呼叫,并且两者都可以完美运行,但是当我从在 RecordingStatusCallback 上执行的函数中收到记录时电子邮件没有显示 callFrom 和 Callto(回来并没有定义),我做了我的研究,发现 thar recordingStatusCallback 参数结果没有 callFrom 和 callTo 参数。我想知道是否有一种方法可以从我接到电话时临时存储该结果,以便我在电子邮件中保存或从其他功能获取结果。请参阅下面的部分代码。 这是 twiml 拨号和号码参数。

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);

这是发送录制对话的副本的功能

        //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);
    });

解决方法

您可以通过在 loggingStatusCallback 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,});