All Ruby on Rails Node JS Android iOS React Native Frontend Flutter QA

Firebase Smart Reply: A Simple Trick That Will Make Your App Smarter

Firebase Smart Reply can be used in any case when a quick reply is needed. The most common use case is a chat application. With Smart Reply, you can easily generate replies that look natural. It speeds up the process of writing or enables you to send a quick reply when you don’t have enough time to respond with a long message. 

Apps that use Smart Reply

There are several apps and websites that provide a Smart Reply functionality. Let’s take a look at the most popular ones:

LinkedIn

https://www.youtube.com/watch?v=BerAiPqouDs

Just to be clear, LinkedIn uses a custom solution, but in the end it provides three replies just like the Firebase Smart Reply service.

Gmail

This is probably the best and the most recognizable example I could think of. When writing an email reply, you will always see those simple replies that you can quickly use. It’s really nice, when you don’t have to type the same message hundreds of times!

Security

Firebase Smart Reply can be configured to use only offline data models. It is not necessary to send private messages to remote servers in order to generate smart replies. So it's a really safe solution and every privacy admirer will be pleased with it!

Limitations

With all the good the Smart Reply feature brings, there are some limitations that we can’t bypass at the moment. They’re not so huge, so Smart Reply functionality is still useful even if it’s a bit limited. Maybe in the future, Google will do away with some of them! Let’s quickly talk about the limitations:

  • Currently, Firebase Smart Reply only supports English language. It automatically detects the language used by the user – when language other than English is used, replies won’t be generated.
  • Firebase Smart Replies can be used for simple conversations only. The model used in Smart Reply won’t be able to generate natural responses for more complex topics.
  • The Firebase Smart Reply model will not provide responses if any of sensitive topics are detected.

Implementation

Implementing Firebase Smart Reply in an empty project is quite simple. You just have to install:

@react-native-firebase/app
and
@react-native-firebase/ml-natural-language modules

then set it up in those few steps:

  1. Create or edit your firebase.json file which should be placed in the root of the project:
    {
        "react-native": {
            "ml_natural_language_language_id_model": true,
            "ml_natural_language_smart_reply_model": true
        }
    }
  2. You can use it in your app like that:
    import {firebase} from '@react-native-firebase/ml-natural-language';
    
    const generateReplies = async (messages, token) => {
      const messagesForML = messages.map((m) => {
        let message = {
          text: m.message,
          isLocalUser: m.user === token,
        };
        if (!message.isLocalUser) {
          message.userId = m.user;
        }
        return message;
      });
      const replies = await firebase
        .naturalLanguage()
        .suggestReplies(messagesForML);
      return replies;
    };
    
    export {generateReplies};
  3. Rebuild your app.

Remember that to make it work, you need to pass to the text messages to the suggestReplies method. That’s the minimal configuration. To make Smart Reply work better, you can pass to the suggestReplies method messages that will include the userId and isLocalUser props. It will enable Smart Reply to identify and understand messages better. If you want to improve the quality of generated replies, you can also add timestamp data to the message.

Time estimation

In an empty project, implementing Firebase Smart Reply for chat should take less than 2 hours. If your project is at an advanced stage, it also shouldn’t be a big deal to implement it. I would say that, in this case, it shouldn’t take you more than 3-4 hours. Of course, I am talking about just the Smart Reply functionality, but you should also consider creating a proper UI for it.

Demo

For a better understanding, you can check out the video of a sample chat app that uses Firebase Smart Reply to generate quick responses. Users can then use them by just tapping on the given answer to send it.

We're building our future. Let's do this right - join us
Looking for new opportunities? Check our offers!
READ ALSO FROM JavaScript
Read also
Need a successful project?
Estimate project or contact us