2014-09-26 60 views
0

我有objc代碼調用PFCloud函數(parse.com雲代碼),通過twilio api啓動出站呼叫。該部分運作良好。 twilio發出的外撥電話會播放mp3音頻消息,mp3網址會在我的parse.com雲代碼中硬編碼。如何使mp3成爲變量,並在設置twilio的GET url時傳遞它?以下是我的代碼,評論線是我已經嘗試/無法傳遞fileName(mp3文件url)數據的方式。謝謝。twilio,parse.com雲代碼傳遞參數/數據

目標C代碼

-(void)makeCallViaTwilio { 
    NSMutableDictionary * params = [[NSMutableDictionary alloc] init]; 
    params[@"to"] = @"+12319818818"; 
    params[@"fileName"] = @"https://s3.amazonaws.com/shuang/voiceMessageTest.mp3"; 
    [PFCloud callFunctionInBackground:@"makeCall" withParameters:params block:^(id object, NSError *error) { 
     if (!error) { 
      // succeeded 
     } 
    }]; 

} 

parse.com雲代碼來撥打電話

// Use Parse's RPC functionality to make an outbound call 
Parse.Cloud.define('makeCall', function(request, response) { 
    // Create a Twilio REST API client - get your account SID and 
    // auth token at https://www.twilio.com/user/account 
    var client = new twilio.RestClient(
     'number...', // Account SID 
     'number...' // auth token 
    ); 

var getUrl = "https://easedrop.parseapp.com/hello?fileName="; 
var messageUrl = "request.params.fileName"; 
var getUrlWithFileName = getUrl.concat(messageUrl); 

    // Place an outbound call 
    client.makeCall({ 
     to: request.params.to, // the number you wish to call 
     from: '+12318288183', // a valid Twilio number you own 
//  url: 'https://easedrop.parseapp.com/hello' 
     url: getUrlWithFileName, // TwiML URL 
     method: 'GET' // HTTP method with which to fetch the TwiML 
//  params: {@"fileName": request.params.fileName} 
    }, function(error, data) { 
     // Handle the result of placing the outbound call 
     if (error) { 
      response.error('there was a problem :('); 
     } else { 
      response.success('call incoming!'); 
     } 
    }); 
}); 

TwiML代碼

// Create a route that will respond to am HTTP GET request with some 
    // simple TwiML instructions 
    app.get('/hello', function(request, response) { 
     // Create a TwiML response generator object 
     var twiml = new twilio.TwimlResponse(); 

    // twiml.record; 

     // twiml.play('https://s3.amazonaws.com/shuang/voiceMessageTest.mp3'); 
     twiml.play(request.params.fileName); 
     // twiml.play(request); 
     // twiml.play(fileName); 


      twiml.say('To send, reply or ease drop on voice messages, download Easedrop from the app store.', { 
      voice:'woman' 
      }); 

    twiml.say('E', { 
     voice:'woman' 
     }); 
    twiml.pause(); 

    twiml.say('Ay', { 
     voice:'woman' 
     }); 
    twiml.pause(); 

    twiml.say('S', { 
     voice:'woman' 
     }); 
    twiml.pause(); 

    twiml.say('E', { 
     voice:'woman' 
     }); 
    twiml.pause(); 

    twiml.say('D R O P', { 
     voice:'woman' 
     }); 
    twiml.pause(); 

    twiml.say('ease drop', { 
     voice:'woman' 
     }); 
    twiml.pause(); 

    twiml.say('Good day.', { 
     voice:'woman' 
     }); 


    // Render the TwiML XML document 
    response.type('text/xml'); 
    response.send(twiml.toString()); 
}); 

// Start the Express app 
app.listen(); 

回答

0

同事固定的代碼,我在這裏發帖的情況下,其他人有類似的問題。需要以下幾行來使原始問題的main.js代碼工作 - >

var getUrl = "https://easedrop.parseapp.com/hello?fileName=" + request.params.fileName; 

url: getUrl, // TwiML URL 

twiml.play(request.query.fileName); 
+0

sarvesh,系統說我需要等待18個小時才能接受我的答案。只要系統允許,我會盡快接受。 – tmr 2014-09-27 22:50:16