Great, this makes good sense and of course, a reason to avoid going down the global variable rabbit hole with these endpoints. The data table solution seems doable. I already have a list of messages there that I want to send, given the user choosing the outgoing message in the client side. These are going to be Twilio calls with the customized message. However it seems that I can either create a new table called “calls” and store the user_id and the message chosen there. Kind of like a log of calls. the end point would just load the latest row of these calls table and it should contain the chosen message. However if this had multiple requests coming in simultaneously, this would not work.
I was interested in doing what is show in this page:
for example, adding a parameter to the endpoint so we would know what message to load:
@anvil.server.http_endpoint("/call-connected/:msg_id")
def call_connected(msg_id, **kwargs):
# get the msg from the data table by msg_id
return "<Response><Say>{msg}</Say><Response>"
The problem is that in my server function that is called from the client, I can’t build the request URL with the added parameter. I’m not sure if it’s Twilio or Anvil that throws the error.
@anvil.server.callable
def make_call(number, msg_id):
twilio_acct_id = anvil.secrets.get_secret('twilio_id')
twilio_auth_token = anvil.secrets.get_secret('twilio_auth_token')
twilio_from_number = anvil.secrets.get_secret('twilio_phone_number')
anvil.http.request(
f"https://api.twilio.com/2010-04-01/Accounts/{twilio_acct_id}/Calls.json",
data={
"Url": f"{anvil.server.get_api_origin()}/call-connected/",
"From" : twilio_from_number,
"To": number,
},
method = "POST",
username = twilio_acct_id,
password = twilio_auth_token
)
adding "Url": f"{anvil.server.get_api_origin()}/call-connected/{msg_id}"
doesn’t work.
any ideas? and thanks for your support. I should say, I’m actually trying to build lesson plans around this for a program for high school students. so you are not just helping me, but potentially lots of kids who will get their chance to make full stack apps with python! so excited.