I am trying to route a connecting Twilio call to a relative URL. I have tried formatting this URL in many ways but all get an error that the URL is malformed. Twilio's documentation explicitly stated that this attribute can be relative. Below is the TwiML that I am trying.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Connect>
<Stream url="./call_data">
</Stream>
</Connect>
</Response>
How are you accessing that TwiML? I assume it's via HTTP and that would explain the problem. Your relative URL would then also use the HTTP protocol whereas the docs state WSS
is required:
What you can do to mimic a relative URL, is to build it based on the host parameter you receive from the incoming request.
app.post("/", (req, res) => {
res.set("Content-Type", "text/xml");
res.send(`
<Response>
<Start>
<Stream url="wss://${req.headers.host}/"/>
</Start>
<Say>I will stream the next 60 seconds of audio through your websocket</Say>
<Pause length="60" />
</Response>
`);
});