Chameleon SMS

What is privacy for you? Take a moment to think before answering that question. I like to define privacy as the right to share personal information with certain people at a certain time. A lot of people these days think that since they’ve got “nothing to hide”, they don’t need to care about privacy. Well let me tell you why you should. A practical reason for caring about your privacy is because your information in the wrong hands can become dangerous which is why ride-sharing services like to use something called masked communication which creates a safe space for conversations between the rider and the driver without compromising on privacy.

Masked communication application

I found the idea of masked communication quite interesting so as a developer my first instinct was to build an application around the concept of masked communication. The way a masked communication application works is if two parties would like to start a conversation, the application assigns a dedicated number (a number that allows you to send and receive messages from the same number every time) to the conversation and then both the parties will start communicating with each other via that dedicated number.

During the requirements gathering stage, I decided the major building blocks of the application were:

  1. Number provisioning: Having the ability to dynamically assign unallocated numbers to conversations
  2. Managing concurrency: Being able to detect that a number is already allocated and not having conversation merges taking place where a number is allocated for more than one conversation
  3. Facilitating conversations: Having the ability to track and monitor all conversation to ensure the conversations stay on the platform and there are no revenue leaks

I realised that if the application were to keep track of all the messages sent and received for an individual conversation then I’d have to store it in a database. For a small application, this shouldn’t be an issue but for an enterprise-level application this can mean A LOT of data. For instance, if a food delivery service is processing a thousand orders a day, then you will end up with a thousand conversation threads that you’ll need to store every day. Cloud computing can easily host all of that data and maintenance shouldn’t be as tedious but why go through the trouble of setting that up when you can have a cleaner and more efficient approach to maintaining data? So, I decided to build a databaseless masked communication application.

Metadata and Chameleon SMS

The MessageMedia Messages API allows you to attach additional data to your messages in the form of metadata. Metadata sits on top of your messages and is not visible to the end-user, but you can send it as part of your message and receive it back when someone replies to your message. I decided to implement metadata in my masked communication application which turned it into a purely databaseless application and that’s how Chameleon SMS was born.

The way metadata was integrated into Chameleon SMS was by specifying the details of the conversation in the metadata. Here’s a code example of what it looked like:

{
       "content":"Hi Ibrahim, you can contact your driver using this number.",
       "source_number":+61491570156,
       "destination_number":+61491570159,
       "metadata": {
            "conversation_id":55,
            "line":+61491570156,
            "name":Ibrahim,
            "recipient":+61491570158,
            "recipient_name":Ben,
            "expiry":1538999543759,
            "type":"reply"
       },
       "callback_url":"https://mycallback.com"
}

As you can see the metadata object holds the contact information for both the parties so each time a message goes through the application, it reads the contents of the metadata of each message and forwards the text message to the recipient. But what about conversation tracking? The conversation ID specified in the metadata can be used as a filter when running reports using our Reporting API. You can then perform analysis and generate new insights for your business.

Leveraging metadata dramatically reduced the development effort and time that was required to build the application. Since all the conversation data is persisted as part of the metadata and there is no client data being stored on your end, you can build a stateless application or even take it a step further and deploy it to Lambda and run it as a serverless application. Sounds a lot better than the database approach, doesn’t it? It gets even better.

Chameleon SMS is an open-source project and you can find it on Github. It’s a basic Node.js application running Express.js as the back-end framework. You can tweak the project, make improvements to it and add other cool functionalities. Currently the Chameleon SMS application relies on the following MessageMedia services:

  1. Dedicated number
    Each conversation needs a dedicated number
  2. Messaging API
    Messages are sent to the two parties using the Messaging API
  3. Metadata
    Metadata is the engine that powers Chameleon SMS. This powerful feature allowed me to create a databaseless application
  4. Reporting API
    You can track and facilitate conversations by running reports on messages based on the conversation id using the Reporting API
  5. Enterprise Webhooks
    Enterprise Webhooks verifies all the Webhooks returned to your application and ensures they are all coming from MessageMedia

Metadata is quite powerful and opens the doors to a lot of possibilities. Chameleon SMS is an example of an application that you can build using metadata. You can find the open-source Chameleon SMS project hosted in this repository. Have a go at the code and find out what other changes and improvements can be made to it. Happy coding!


Continue reading...

Everything you missed at DevDay
Natalie Byrgiotis
October 30, 2018
MessageMedia x Auth0
Ibrahim Tareq
October 25, 2018