giaggi
giaggi

Reputation: 572

Django+Twilio: How can I display inside my django app the sms I sent/received using twilio? (Architecture question)

I have a high level architecture question:

I have a django app where users can send out sms to their contacts (telephone numbers, not users of my app). I am trying to implement a system where if someone replies to a specific text, such reply is forwarded to the user that started the thread.

I implemented an inbound webhooks to receive sms but I am now facing a problem: how do I know which text is a reply replying to? I can't seem to find any type of id in the sms inbound request and I am now starting to fear that this is just impossible.

Any idea? Should I try to use "Conversations"? Would that solve my problem and if so, how should I go about it?

Any suggestion?

Upvotes: 0

Views: 118

Answers (1)

philnash
philnash

Reputation: 73029

Twilio developer evangelist here.

You cannot get the message that a user is replying to, because that doesn't exist in SMS. SMS messages are simply chronological. To test for yourself, open your SMS app and try to reply to the second to last message from someone.

You have a few options to try to tie a reply to a specific message:

  • Only ever send one message to be replied to at a time. Once you receive a reply to one message (or there's a timeout of some sort), send the next one.
  • Have the user enter a message identifier in their message. You can then parse the identifier out and associate the reply. This is not very user friendly and they may forget or get the wrong identifier in the message
  • Use multiple numbers to send the messages. So, if you have an active message you are waiting for a reply to, use a different number to send out the next message. You can then associate the reply based on the number the user replies to.

The last option is my preference since it doesn't affect the messages you can send at any time and doesn't require extra work on behalf of the user. It does require extra work to build a number pool and do the work to associate messages with sending numbers.

Upvotes: 1

Related Questions