Deep Linking into Brand Messenger in Mobile Apps

Learn about deep linking in iOS apps with Brand Messenger

Deep linking is an excellent way to bring the end users into brand messenger in your mobile application. You can also transfer information from the link to the resulting message sent by the user. So for example, if you send a link to messaging in your mobile app in response to a user on another channel - Facebook Messenger, Twitter DM, or other Messaging channel, you can move the conversation into a channel you own in your app.

At a minimum, we recommend including the conversation ID and agent ID into the app deep link URL.

To deep link into your app, you'll create the URL and then add code in the app to read the data passed and send it along as metadata. (We'll show an example of this later on.)

A deep link URL uses a format like the following where PROVIDER is the name you have set for the host application provider, such as abc for Apple Business Chat or fb for Facebook Messenger and the key/value pairs include whatever data you want to parse from the provider to Brand Messenger.

{YOUR_APP_URL_SCHEME}://PROVIDER?parameter_key={parameter_value}&....

📘

Your Implementation Advisor can help with the initial configuration of the URL scheme on the web portal and walk you through how the template can be sent as part of the response.

This example deep link URL passes the conversation ID and agent ID.

rocksnropes://abc?conversationDisplayId={conversation.id}&conversationAssignedAgentId={agent.uuid}

When the end user taps on the deep link, your brand app opens and shows the conversation view controller.

In order to read all the values and send it to the backend as metadata, add the following:

func application(_ app: UIApplication, open url: URL,
                 options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        
     // Determine who sent the URL.
     let sendingAppID = options[.sourceApplication]
     // Process the URL.
     guard let components = NSURLComponents(url: url, 
                                            resolvingAgainstBaseURL: true),
         let params = components.queryItems else {
             print("Invalid URL or album path missing")
             return false
     }
       
     if let conversationId = params.first(where: { 
                                      $0.name == "conversationDisplayId" })?.value,
        let ownerId = params.first(where: { 
                                      $0.name == "conversationAssignedAgentId" })?.value {

            KBMUser.current()?.addProperties([
                "conversationDisplayId": conversationId,
                "conversationAssignedAgentId": ownerId
                ])
            BrandMessenger.show()
            return true
        } else {
            print("conversational info missing")
            return false
        }
    }

Did this page help you?