skip to Main Content

Hey guys I was hoping I could come here to ask for input on how to approach sending a user a text message and then waiting for a reply using twilio, flask, and redis rq. In my research, I’ve found that the process requires using a background worker to either continuously check for a reply or, if designed properly, check a database field for a certain status for example.

My question is, with the tools I mentioned before, what is the best way of achieving this functionality? As someone who hasn’t done asynchronous task management, I’m having trouble understanding where does a task scheduler like redis rq come into the equation of waiting for a user’s response to a sms text.

2

Answers


  1. I work at Twilio and also code in Python. I never used redis queue but I’ve used Redis Pub/Sub in the past and this seems like a good approach in my opinion. I’ve found this blog post from last year showing how to create a simple sms micro service with flask, redis pub/sub and twilio. Let me know if this is helpful or if redis queue is mandatory so I can help you better.

    Login or Signup to reply.
  2. I personally wouldn’t use a queue approach here, a database approach, e.g. a key/value store for quick lookup (I’ve used DynamoDB for this quite a lot but normal Redis works too), would make more sense in my eyes.

    The flow would be similar to this:

    • Use Twilio’s REST API to send out a text message to a user.
    • Store that the text message was sent out in the database (and any additional information you might want to record, e.g. timestamp), the phone number you’ve sent it to becomes the key in the database.
    • Wait for a reply from the user using Twilio Programmable SMS, i.e. essentially this is an endpoint in your Flask app which you connect to the webhook of your number in Twilio (there’s an example in the documentation).
    • When a text message is received first look up the user in database using the phone number and then process accordingly if found or not.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search