Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twilio as a proxy for one-to-many SMS conversations

Tags:

twilio

I'm building a small SMS service for a consultant. He wants his clients to be able to send SMSs to a single Twilio number, and have them forward to his own phone number. When he responds, he wants the responses to appear to be from the Twilio number (so as to conceal his personal number), and ultimately maintain multiple conversations with a single Twilio number proxying the SMS communication. I imagine I can do this using sessions, but I'm not entirely sure how to implement it?

Any thoughts on a good approach?

like image 780
dougiebuckets Avatar asked Mar 24 '14 20:03

dougiebuckets


1 Answers

Twilio Evangelist here.

This is actually a little tricky, but you have a few options. The main problem is that you need to send the SMS messages from the Twilio number to the consultant, but that may contain multiple conversations. Twilio will keep the session/cookies etc, but only unique to two numbers. As SMS doesn't have anything that allows you to add any extra metadata, so you need to look at a few work-arounds.

The main problem here is really UX - if the consultant receives the SMS from the customer's actual number and replies by SMS, the SMS will go to the customer, not Twilio. At this point, the consultant 'leaked' their direct mobile number.

Let's go through a message flow with a single customer:

The customer sends an SMS to the Twilio proxy number:

Customer -> Twilio Number -> Consultant

Then the consultant replies to the Twilio Number, and it is forwarded on:

Consultant -> Twilio Number -> Customer

This is fine. The conversation can be threaded on the consultants phone by the Twilio number. When the consultant replies, your app simply acts as a proxy, and forward the message to the customer.

When you add a second customer, it's really hard for the consultant to know who the message is from. Because they both come from the same Twilio Number from the consultant's perspective!

Customer1 -> Twilio Number -> Consultant
Customer2 -> Twilio Number -> Consultant

Then to reply:

Consultant -> Twilio Number -> ??

When the consultant replies, which customer do you send the message to? And which conversation is he responding to? There are a couple of options:

1 Multiple numbers

Use a single number for the customer to SMS the consultant, but multiple different numbers as the from number when sending on the customer. So the customers only ever have one number, but the consultant has many different ones, one for each customer. This could get a little pricey if the consultant has hundreds of clients, even at $1 month/each!

2 Pin Codes

Prefix each SMS with a pin number that identifies the client. So <ID> <Message>. Then when the consultant responds, they specify the <ID> of the conversation they are replying to. It's not the best user experience though, and would make following a message thread a little tricky.

3 App

This is my favourite solution, but requires a little more work. Build a web or mobile native app for them that uses push notifications to join between the device and Twilio. This allows you to thread the conversations seamlessly on the original From/To number, rather than having to add extra data to proxy the conversation. It also allows the consultant to save the numbers of customers, as he may be given a business card with a mobile number on it, and the SMS message may assume he's added that number to his phone. It also means he could potentially access these SMS messages from anywhere, he's no longer tied to his own phone! It could work on a tablet/laptop/desktop/whatever!

This is quite a tricky problem to work with, simply because SMS is stateless. Twilio does preserve state, but that is only unique to each pair of numbers, a single pair (from/to) cannot have multiple session states.

I hope this helps!

like image 128
xmjw Avatar answered Nov 07 '22 08:11

xmjw