Building Repliable SMS For Coaches And Athletes: CoachUp Scales With Twilio (and Stephen Curry)

September 25, 2015
Written by

stephen-curry

Steph Curry is a champion, and MVP. Here in the Bay Area, he’s more like a demi-god. In a 2009 draft report, a scout lambasted Steph’s abilities saying that he would never lead a team at the highest level. Then, in 2015, Steph led The Golden State Warriors to world championship.

The difference maker for Steph, aside from ignoring critics, was coaching. One on one coaching changed his game, and now he’s investing in a company that helps coaches and players work together, CoachUp.

Typically, booking, paying, and communicating with a coach takes place over multiple platforms and devices. CoachUp takes all of that, simplifies it, and puts it on a platform. Using CoachUp’s platform, coaches can communicate with clients (and vice versa) using Twilio powered text messaging. Neither party has to reveal their “real” number, they’re all assigned Twilio numbers they can use from the app.

CoachUp found out what happens when one coach is almost too good at their job — they get a ton of replies from athletes. The problem is there’s a limit on how many conversations coaches can have – 50. It seemed like CoachUp had two options: cap the coaches’ conversations, or buy more Twilio numbers. They got creative, wrote some great code and made a third option: recycle the numbers.

Let’s Recycle Some Numbers – And Use A Stephen Curry Hypothetical

Let’s say in an alternate (and awesome) universe Steph Curry was your coach. When Steph Curry sends a text message to his pupils from the CoachUp platform, he’s going to get a ton of replies. He’s Steph Curry. To allow Steph to text all his all star students via Twilio, CoachUp recycles numbers so he can have conversations with all his students, 50 at a time.

CoachUp developer Ji Jiapeng explained how the team designed the feature. “Our product manager, Justin actually came up with the idea of recycling allocated phone numbers for the recipient of a repliable SMS” said Ji. “A popular coach could easily exhaust the phone number pool cap when a lot of athletes are contacting him or her. However, not all of the conversations from the athletes are going to be indefinitely ongoing. So to ensure the popular coach, is still able to receive repliable SMS, after the cap for the coach is reached, we will use a preemptive approach to dis-associate (recycle) numbers of a conversation that has been inactive for a while (3 months was the number we picked).”

You can read CoachUp’s rundown on how they built repliable SMS right here.

Here’s how two of the core pieces of code powering repliable SMS work, as explained by Jiapeng.

In code, to find a set of candidate repliable phone numbers, would look something like:

domain_of_repliable_numbers = PhoneNumberDirectory.repliable_phone_numbers

john = User.where(id: john_user_id)
allen = User.where(id: allen_user_id)

in_use_numbers = Conversations.
  for_user('coach_user_id = ? OR client_user_id = ?', john, allen).
  pluck(:repliable_phone_number).
  compact

available_numbers = domain_of_repliable_numbers - in_use_numbers

The reply endpoint can use the SMS’s from_number and the to_number. It can then retrieve the appropriate conversation based on the assigned repliable number and saved phone numbers associated with our users. In code, this looks like:

from_number = params['From']
to_number = params['To']

conversation = Conversation.
  for_repliable_sms_phone_number(to_number).
  coach_or_client_user_with_phone_number(from_number).
  first

Putting Numbers On The Board

After shipping the feature, CoachUp saw a sizeable uptick in use. They saw 1.7k uses of the feature in the first five days. Since the feature launched and August, the use has steadily increased. They’re putting numbers on the board. No wonder Steph Curry joined their team.