Updates: Check the release notes for new features and product updates.

How to deep link to apps from your RBM agent

In mobile apps, deep linking lets users go directly to content within an app. Without deep linking, if you share a shirt you found in a retail store app with your friend, then a link you send them would either take them to their browser or take them to the Play Store, where they would need to install or open the app and then search for the content. Neither situation is a great user experience. With deep linking, the link takes your friend to the exact shirt that you found within the retail app.

In this article, you'll learn how to use deep links to create rich and engaging experiences for your RBM users.

Taking an RBM user into an app

A deep link is just a link into an app. Your RBM agent can open an app that's installed on someone's phone by using a OpenUrlAction where the URL is a deep link configured for the app you want to invoke. You can read more in Create Deep Links to App Content.

Let's look at a specific example.To open the Google Cloud podcast within the Google Podcast app, an OpenUrlAction can be created with the URI:

https://www.google.com/podcasts?feed=aHR0cDovL2ZlZWRzLmZlZWRidXJuZXIuY29tL0dvb2dsZUNsb3VkUGxhdGZvcm1Qb2RjYXN0

Many Google products are configured to support deep links that also work as web URLs, including Youtube and Google Maps.

To trigger any of these apps from an agent, we need to specify this value as the URL in an OpenUrlAction. In the sample JSON below, an RBM rich card is specified with three open URL actions, each deep linking into a different app.

{
    "contentMessage":{
        "richCard":{
            "standaloneCard":{
                "cardOrientation":"VERTICAL",
                "cardContent":{
                    "title":"Did you know that you can open apps from an RBM agent?",
                    "description":"",
                    "suggestions":[
                        {
                            "action":{
                                "text":"Google Cloud Podcast",
                                "postbackData":"podcast_tap",
                                "openUrlAction":{
                                    "url":"https://www.google.com/podcasts?feed=aHR0cDovL2ZlZWRzLmZlZWRidXJuZXIuY29tL1JvYkNlc3Rlcm5pbm8&nord=0"
                                }
                            }
                        },
                        {
                            "action":{
                                "text":"YouTube Video",
                                "postbackData":"youtube_tap",
                                "openUrlAction":{
                                    "url":"https://www.youtube.com/embed/xSE9Qk9wkig"
                                }
                            }
                        },
                        {
                            "action":{
                                "text":"Google Maps",
                                "postbackData":"maps_tap",
                                "openUrlAction":{
                                    "url":"https://goo.gl/maps/ToMSdr4PYX62"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

When this JSON payload renders within a user's RCS client, the icon of the suggested action matches the deep linked app. Tapping on any of the suggested actions launches the corresponding app directly into the content encoded in the URL.

Suggested URLs with app icons

Why would you want this?

There are several reasons why you may want to deep link into an app.

Authentication

If your agent deals with potentially sensitive information, one way to help secure your agent is to deep link into your app to help authenticate the user via fingerprint, login, or some other means. Once the user successfully authenticates, you can track the authentication server-side and bring the user back to the agent by triggering a new RBM message. If you send any potentially sensitive follow-up messages, you can check server-side to make sure the user is authenticated. If they aren't, you can send them back to the app to renew their authentication token.

Complex use case support

RBM agents are great for conversational interactions, but apps can better serve some use cases. For example, if you have a furniture company and you've created an augmented reality experience so users can try out furniture in their homes (see image below), your use case can only be supported by an app.

In these situations, it makes sense for you to direct your RBM users to your app to carry out some functionality. Your app can always bring the user back to the RBM conversation by triggering a new agent message.

Deep link into app Deep-linked app

Facilitating payment

You can support payments with a third party app with deep linking.

For example, let's assume you want to support money transfers through the fictitious payment company AcmePay. By investigating online, you discovered that AcmePay supports deep linking using its own unique URI structure that lets you pass in values for recipients, the amount, and a note via querystring parameters.

Armed with this knowledge, your agent simply needs to create a OpenUrlAction with the parameterized AcmePay URI specified for the url part of the suggested action.

acmepay://paycharge?recipients=Jane+Smith&amount=10&note=Money+For+You!

Once the recipient of the RBM message taps on the suggested action, the AcmePay app launches directly into the transaction screen with the passed-in values already filled out.

What happens if the app isn't installed?

If an app isn't installed on a user's device, deep linking behavior depends on the structure of the URI passed to the OpenUrlAction. If the URI can be recognized by at least one app on the device, for example Chrome recognizes URLs beginning with "http://", then the suggested action displays as normal in that app. When the user taps the action, the URI opens in whichever app recognizes the URI structure.

If you're the app developer, it's advantageous to deep link with URIs starting with "http://" and pointing to a domain you own because Chrome can take the user to a webpage as a fallback action. On the webpage, you can direct the user to download the app or direct them as you see fit for your use case.

In the situation where the URI uses a custom structure that isn't recognized by any app on the device, then the suggested action will not render in your RBM message.

To make sure your suggested actions always appear, you can use a URL you own and have the webpage attempt to redirect the browser to a custom URI that launches the app. If the app exists on the device, it launches as expected, if not, the user stays on the webpage, where you can direct them as needed for your use case.

Below is an example of how to do this with JavaScript. The script attempts to redirect the user to the AcmePay app, but if that app isn't installed, the script redirects the user to the Google Play store to download the app.

<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0, maximum-scale=1.0" />
    <title>Acme Pay</title>

    <script type="text/javascript">
    window.onload = function() {
       // Launch Acme Pay app for existing users
       window.location = 'acmepay://paycharge?recipients=Jane+Smith&amount=10&note=Money+For+You!';

       // Redirect to Acme Pay app download for new users
       setTimeout("window.location = 'https://play.google.com/store/apps/details?id=com.acmepay.android';", 1000);
    }
    </script>
</head>
<body>
    <h1>Redirecting…</h1>
</body>
</html>

Wrap-up & TL;DR

You can use the OpenUrlAction suggested action to deep link into apps you own or apps you want to trigger to help engage your users. By deep linking, you can provide an enriched and engaging experience for your users or more enhanced security for sharing sensitive content.

Good luck and happy coding!