0

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"

1 Answers1

0

I'm not a Flask expert but it seems you try to send relative URLs back in your functions. Try to send absolute URLs instead.

IObert
  • 2,118
  • 1
  • 10
  • 17
  • I just searched relative and absolute urls, and from what I understand, I do send absolute urls, i just deleted the urls. Since I’m using ngrok I’m constantly switching urls every time I work on my project – Relativity Mar 29 '23 at 01:56
  • I think it would be better if you pasted the original source code in your question. You can use [`request.base_url`](https://stackoverflow.com/questions/15974730/how-do-i-get-the-different-parts-of-a-flask-requests-url) to avoid changing it every time ngrok changes the URL. – IObert Mar 29 '23 at 19:30
  • Noted I updated my post including the URL that I most recently used. As well as using request.base_url that will be very helpful and save me a lot of time thank you for that – Relativity Mar 30 '23 at 03:51