我有objc代码调用PFCloud函数(到parse.com云代码),通过twilio api启动出站呼叫。那部分效果很好。 twilio发出的外拨电话播放mp3音频消息,mp3网址在我的parse.com云代码中硬编码。如何让mp3成为一个变量,并在我为twilio设置GET url时传递它?以下是我的代码,注释行是我尝试/未能传递fileName(mp3文件URL)数据的方式。谢谢。
目标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 :(得分:0)
一位同事修好了这段代码,我发帖在这里以防其他人有类似的问题。需要以下几行来制作原始问题的main.js代码 - >
var getUrl = "https://easedrop.parseapp.com/hello?fileName=" + request.params.fileName;
url: getUrl, // TwiML URL
twiml.play(request.query.fileName);