How can I fill Twilio Voice url parameter from a predefined variable?

Solution 1:

In order to have that string input from your function be part of the returning TwiML you would need to use string interpolation. If you're using Python 3.6 or higher you should be able to use the string interpolation function like this:

twiml=f'<Response><Say>{string}</Say></Response>',

For mor information on string interpolation and how it works you can take a look here: Python Literal String Interpolation