February 22, 2024
-
2
Min Read

How to develop a chat app with built-in moderation

See how easy it is to develop a chat app with Momento Topics, Cache, and Webhooks
Anita Ruangrotsakun
Headshot of the blog author
by
Anita Ruangrotsakun
,
,
by
Anita Ruangrotsakun
by
green squirrel logo for momento
Anita Ruangrotsakun
,
,
Event-Driven Architecture

With so many client platforms and frameworks in the app development ecosystem these days, it’s hard to know what tech stack to use to minimize development costs while maximizing end user flexibility. Momento simplifies that decision by supporting Momento Topics and Cache in a variety of client SDKs

Let’s walk through an example: developing a chat app with built-in moderation! This cross-platform chat app filters out profane messages and images and allows users to communicate in different languages. 

screenshot of a conversation on MoChat

Adding a moderated chat API

At the core of this example is the moderated chat API that centralizes the main work used by all the client applications. 

Upon launching, each client app asks the user to provide a username to log in. The client makes a request to the API, which vends a Momento auth token to allow the specified user to publish and receive messages on specific topics using Momento Topics and Cache.

The API also processes images and text messages that are published by the client apps. Messages are published to a topic named “chat-publish”, which triggers a webhook to process the message like so: 

  • Filter out profane language using the bad-words library
  • Filter out profane images using Amazon Rekognition
  • Translate text into each of the supported languages using Amazon Translate 
  • Publish translated text to language-specific topics that client applications can subscribe to and update chat message history using Momento Cache

This step-by-step guide details how to create a language translation workflow using Momento Topics and webhooks. The moderated chat app uses the translation API as the foundation but adds additional workflows for image filtering and vending auth tokens. Learn more about how the API works by checking out this video!

Cross-platform, single-instance chat

cross-platform app diagram

Cross-platform apps are generally set up with a common backend that various client applications can use, which is what we did here. This way, supporting another client platform requires only client-side updates.

Users can join the single-instance chat room from a number of Momento-supported client platforms. Check out each of the examples below:

For each moderated chat client app, you’ll find examples of how to:

  • Make POST requests to get Momento auth tokens 
  • Instantiate Momento Cache and Topics clients
  • Subscribe to a topic based on the user’s selected language
  • Display received messages
  • Post new images and messages in the chat room

Almost no server code!

If you haven’t noticed yet, the only server code required here is all contained in the Lambda function with the token vending machine and the webhook. There’s no need to mess around with WebSockets to set up this cross-platform chat session. Additionally, using Momento across all of these clients minimizes the number of dependencies and overall development effort as the same pattern can be used across these platforms.

All of the code for the moderated chat API can be found in this GitHub repo.

Join us on Discord, share your creations, and let us know what you think! 
Anita Ruangrotsakun
by
Anita Ruangrotsakun
,
,
by
Anita Ruangrotsakun
by
green squirrel logo for momento
by
Anita Ruangrotsakun
,
,
Author
Anita Ruangrotsakun

Anita is a software engineer on the Developer Ecosystem team at Momento, working to provide an excellent developer experience and help people build serverless applications. When she’s not working, Anita enjoys reading, building dynasties in the Sims 3, and finding new foodie spots in the PNW.

Author
Author
Open