TokenTextView

Chris Lee
Turo Engineering
Published in
3 min readNov 28, 2022

--

A lightweight class for managing tokenized text templates.

The process of booking and using a car on Turo usually adopts the following general pattern: A guest books a trip. They can have the car delivered or they can pick it up from their host. Hosts and guests can message each other using Turo messaging for common trip details such as parking. During this process, and over the course of multiple trips, hosts often notice that they send the same messages to guests. After a while, these repetitive messages become a burden on a host’s time.

At Turo, we recently launched a long desired feature called Scheduled Templated Messages to help hosts with this problem. This feature allows hosts to create templates of commonly sent messages and automate them to be delivered at specific points throughout a trip. As a result, hosts save a tremendous amount of time that they would normally spend writing and sending these messages.

A cornerstone of this feature is the ability for hosts to draft & save message templates. Message templates are messages with “tokens” in them, and these tokens represent important information relevant to the guest and trip. Tokens can represent information such as the guest’s name, the host’s name, contact information or the start and end times of a reservation. By drafting a message template and scheduling them in advance, hosts can redirect their time to other efforts while knowing that the messages they’re automating are personalized and relevant to each guest and trip.

Drafting a templated message

In order to provide hosts with this capability, we developed a custom solution called TokenTextView for Turo’s iOS app. This library is a subclass of UITextView and allows for the insertion of stylized tokens within plain text. TokenTextView can also take plain text templates (the default is mustache syntax) and render them into a user-friendly stylized version, and vice versa.

Cut/copy & paste

We wanted to preserve the conventional use of UITextView, so we left the delegate methods untouched. Token styling can be customized, and the token indicators for plain text templates can be specified if the default mustache syntax isn’t desired. TokenTextView also supports copying & pasting tokens! Because we couldn’t find an existing solution that met all of our requirements when starting this project, we thought it would be great to put TokenTextView out for others to use too. Feel free to check it out on our GitHub!

--

--