0

Twilio.PHONE_NUMBER is accepting input such as '62047' which is obviously not a valid phone number. I tried writing my own custom validation function but I am unable to count number of times this function is triggered, hence running into an infinite loop(in case phone number given by user is always invalid).

Is their any way to solve this or do we have to settle for Twilio.PHONE_NUMBER?

Himanshu Kumar
  • 89
  • 1
  • 10
  • 2
    Can you elaborate on `hence running into an infinite loop(in case phone number given by user is always invalid)`? Why would an invalid phone number cause an infinite loop..? – obe Jun 08 '21 at 14:39
  • There are 2 functions - A and B. A is taking phone number as an input and redirecting to B. B is checking whether phone number is valid or not. If it's not valid, it's redirecting back to A to ask for phone number again. Can you see why this can lead to an infinite loop? – Himanshu Kumar Jun 08 '21 at 14:41
  • I have been trying to fix this for a while now. I tried using the environment variable as a counter but it's not possible to modify the environment variable in Twilio. Another solution I tried was by using a custom type(which also does not work even after adding multiple values). – Himanshu Kumar Jun 08 '21 at 14:55
  • So any help would be appreciated! – Himanshu Kumar Jun 08 '21 at 14:56
  • tbh i'm still not sure i understand. for me, an "infinite loop" is something like `while (true) { }`. if you're stuck in "infinite until the user types their number correctly" loop then it seems like it should be solved with some extra business logic (e.g. limit number of tries, etc.) – obe Jun 08 '21 at 14:57
  • You are right, I meant "infinite until the user types their number correctly". I tried limiting number of tries but everytime function A or B gets called, all variables gets re-initialized. – Himanshu Kumar Jun 08 '21 at 15:17
  • Ok, so if it's a problem with specific code then I suggest to add it to the question... – obe Jun 08 '21 at 15:19
  • If your problem is that each invocation is separate and there is no way to keep state between invocations then you can look into using some external method to keep state, like a database, memcache, or even with a cookie... – obe Jun 08 '21 at 15:21
  • I am assuming this is part of a `collect` action in Twilio Autopilot? Can you share how you are validating this (the validate property in the action and the function you are using)? – philnash Jun 09 '21 at 07:02
  • @obe I was able to solve the problem using sync API provided by twilio. – Himanshu Kumar Jun 09 '21 at 10:36
  • @philnash like this - "type": "Twilio.PHONE_NUMBER". Although, I don't think there's issue with the syntax. – Himanshu Kumar Jun 09 '21 at 10:37

1 Answers1

0

I was able to solve this problem by maintaining a common state between two functions using the sync API.

You can read about it here: https://www.twilio.com/sync/api

Himanshu Kumar
  • 89
  • 1
  • 10