I'm using Twilio and Telegram to make a call bot, but I want to add variables that are input into my Telegram bot to add more customization to the script, but when I try to pass the "Fname" and "Lname" variables from my "send" function to my "sent" function, the sent function doesn't receive it. My Flask
Code:
@app.route('/send', methods=['POST'])
def send():
Fname = request.args.get('Fname')
Lname = request.args.get('Lname')
response = VoiceResponse()
response.say(f'Hello your first name is {Fname}')
gather = Gather(num_digits=1, action=f'https://6013-71-84-89-51.ngrok.io/gather?Fname={Fname}')
gather.say('Press 1 to hear the last name')
response.append(gather)
response.redirect(f'https://6013-71-84-89-51.ngrok.io/sent?Fname={Fname}&Lname={Lname}')
return str(response)
@app.route('/sent', methods=['POST'])
def sent():
Fname = request.form.get('Fname')
Lname = request.form.get('Lname')
response = VoiceResponse()
response.say(f'Your last name is {Lname}')
gather = Gather(num_digits=1, action=f'https://6013-71-84-89-51.ngrok.io/G6?Lname={Lname}')
gather.say('Press 1 to end the call')
response.append(gather)
response.redirect(f'https://6013-71-84-89-51.ngrok.io/sent?Fname={Fname}&Lname={Lname}')
return str(response)
Send call code:
phone_number = update.message.text.split()[1]
Fname = update.message.text.split()[2]
Lname= update.message.text.split()[3]
numbers = random.choice(from_number)
account_sid = os.environ['TWILIO_ACCOUNT_SID']
auth_token = os.environ['TWILIO_AUTH_TOKEN']
client = Client(account_sid, auth_token)
call = client.calls.create(
url= f'https://6013-71-84-89-51.ngrok.io/Fname={Fname}&Lname={Lname}',
to= phone_number,
from_= from_number,
)
print(call.sid)
-I've added print statements to both just to check that they both received the "Lname" variable (send function received both)
-I also changed the "request.form" in the sent function to "request.args"