我正在使用 twilio voice-quickstart-ios。目前我正在尝试使用 twilio REST API 从子帐户进行调用。这是我的 makeCall 端点
exports.handler = function(context, event, callback) {
console.log("event :" + JSON.stringify(event));
var to = event.to;
var from = event.from;
let subaccountSid = event.sid;
let subaccountAuthToken = event.token;
const accountSid = context.ACCOUNT_SID;
const authToken = context.AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken, {
accountSid: subaccountSid
});
client.calls
.create({
url: 'http://twimlets.com/message?Message%5B0%5D=Hello%20from%20your%20subaccount',
to: to,
from: from
}, function(err, call) {
if (err) {
console.log("err : " + err);
callback(null, JSON.stringify(err));
} else {
console.log("call Sid " + call.sid);
callback(null, call);
}
});
};
下面是从我的应用程序执行语音呼叫的代码。
func performVoiceCall(uuid: UUID, client: String?, completionHandler: @escaping (Bool) -> Swift.Void) {
guard let accessToken = fetchAccessToken() else {
completionHandler(false)
return
}
let dictionary = userdefaults.getSelectedNumbersSidAndAuth()
let sid = dictionary["sid"]!
let token = dictionary["token"]!
let from = self.dialView.selectedNumberInDropdown
let connectOptions: TVOConnectOptions = TVOConnectOptions(accessToken: accessToken) { (builder) in
builder.params = [twimlParamTo : self.outgoingValue!, "sid" : sid, "from" : from, "token": token]
builder.uuid = uuid
}
let call = TwilioVoice.connect(with: connectOptions, delegate: self)
self.activeCall = call
self.activeCalls[call.uuid.uuidString] = call
self.callKitCompletionCallback = completionHandler
}
现在的问题是没有调用 twilio 的回调函数。(例如:如果被呼叫者或呼叫者断开呼叫,则不会呼叫代表)。如果我使用Twml从主帐户调用一切正常。但我必须从子帐户调用。我怎样才能解决这个问题?我需要从 performVoiceCall 函数调用 makeCall 端点吗?如果是这样,我怎么称呼它?请告诉我。