I am new to Twilio's API, and for that matter, Twilio as a whole.
I'm using python to make an automated system in which, when an event happens, a call is placed to a particular number. Below is what I'm running (in Python):
from twilio.rest import Client
account_sid = 'ACxx...'
auth_token = 'xx...'
client = Client(account_sid, auth_token)
call = client.calls.create(
url='my/twilio/function'
to="+11111111111",
from="+12222222222",
)
print(call)
And the following is my function in my Twilio account:
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
twiml.say("A call was placed on the following extension.");
callback(null, twiml);
};
This will successfully make the call to my test number, and plays the message "A call was placed on the following extension". However, what I would like is to be able to pass parameters to say on which extension the call was made, e.g., "A call was placed on extension 100". How do I accomplish passing this custom parameter?
Any query parameters or POST body parameters sent to your Function's URL should be available in the event
argument to your Function. From your Python code, consider adding a query parameter to your Function URL with the data your Function will need (the extension dialed, it sounds like?). So instead of /my/function
it would be /my/function?extension=100
, which should then be available in your Function code as event.extension
.