I’m constructing an iOS app utilizing TwilioVoiceSDK to make PSTN calls. Right here’s the circulation I’m making an attempt to attain:
- The app initiates the decision by way of TwilioVoiceSDK.join().
- The Twilio webhook (twiml_response) routes the decision to a PSTN quantity.
- The audio connection from the app ought to cross sound to the PSTN recipient.
Right here’s the difficulty:
- After I use TwilioVoiceSDK.join(), it first reveals an inbound name
within the logs, after which the twiml_response endpoint routes it to the
PSTN quantity, inflicting confusion. - The sound doesn’t appear to switch accurately between my app and the
PSTN recipient.
Right here’s my present code:
iOS (Swift):
func performVoiceCall(uuid: UUID, phoneNumber: String, token: String, completionHandler: @escaping (Bool) -> Void) {
let connectOptions = ConnectOptions(accessToken: token) { builder in
builder.params = ["To": phoneNumber] // PSTN quantity
builder.uuid = uuid
}
let name = TwilioVoiceSDK.join(choices: connectOptions, delegate: self)
completionHandler(true)
}
TwiML Endpoint:
@https_fn.on_request()
def twiml_response(req: https_fn.Request) -> https_fn.Response:
response = VoiceResponse()
to_param = req.type.get("To")
if to_param.startswith("+"): # PSTN
dial = Dial(caller_id="+162xxxxxxxx") # Verified Twilio quantity
dial.quantity(to_param)
response.append(dial)
else:
response.say("Invalid vacation spot.", voice="alice")
return https_fn.Response(str(response), standing=200, mimetype="utility/xml")
The error I’m encountering:
- Inbound calls logged earlier than routing to the PSTN.
What’s the correct option to set up this name circulation whereas making certain the audio path is accurately set between the app and the PSTN recipient? Any steering on tips on how to streamline the method can be appreciated!