Chime is a communication tool provided by Amazon Web Services that offers various features such as video conferencing, chat, and screen sharing. It provides a reliable infrastructure and robust set of APIs for building real-time messaging and collaboration applications.
For one of our clients we had the need to implement a multi-platform, real-time chat with custom attachments and mentions between users. To accomplish this, the team decided to leverage Chime's APIs and build the chat functionality on top of it.
It's important to clarify that our app had two kinds of users, customers and (customer success) managers, and their chat requirements were different. Customers must have a restricted version of the app and as such, they are only able to communicate with one manager. On the other hand, managers can access every chat and they can contribute between them.
Before we start with the integration details, let's introduce some basic concepts related to Chime. As a starting point we first need to create a Chime user for every person who will participate in a conversation. Conversation happens in what Chime calls a "channel". Each channel has a set of users (members) which are the only ones that are allowed to read and write messages in/into it.
To integrate Chime to our platform, we've created a Chime user for every person in our app, and then created two channels for each manager: one in which they could talk with their assigned customer and the other only for managers, where they would talk about issues related to that customer, privately. Then, we made every manager a member of their own channels. Initially, every manager was a member of every channel in the platform. This quickly became an issue since Chime doesn’t allow batch requests, and we had to add new managers to all existing channels one by one, which took a long time.Then, we decided to add employees to a channel only if they explicitly wanted to join, i.e., they were mentioned there or they manually joined the channel.
In our implementation, we send the messages to our backend, which relays them to Chime’s API. If a received message contains an attachment, we first upload the attachment to AWS S3 bucket, and then store a reference both in the message metadata and in our database. Mentions are handled similarly, we store the mentioned users in the message metadata, and add a mention to the corresponding user.
To make this chat receive messages in real time, we used Chime’s WebSocket, which after being linked to a certain user, it will listen for messages sent to channels its user is a member of. Once it receives a message, we check the metadata for mentions and attachments, and then we display the message in the UI.
By leveraging Chime's APIs, our team was able to quickly build a scalable chat functionality, providing a seamless experience for both customers and managers. During the process we learned (as described here) some limitations of the API, but we were able to overcome them by restructuring the interaction. In a future blog post, we will describe how we implemented video chat functionality on the top of this implementation.