Handling Deep Links in Chat
Certain chat flows may present buttons that are deep links to another part of your app. To react to taps on these buttons, implement the ASAPPDeepLinkHandler interface:
ASAPP.instance.deepLinkHandler = object : ASAPPDeepLinkHandler {
override fun handleASAPPDeepLink(deepLink: String, data: JSONObject?, activity: Activity) {
// Handle deep link.
}
}
ASAPP provides an Activity instance for convenience, in case you need to start a new activity. Please ask your Implementation Manager if you have questions regarding deep link names and data.
Example: Parsing and Opening Deep Links in Your Activity
If your app receives deep links through an Intent, you can extract the parameters and forward them to the ASAPP SDK when reopening a chat.
object AppDeepLinkHelper {
fun getASAPPDeepLinkDataIfAny(context: Context, intent: Intent): Map<String, Any>? {
val uri = intent.data ?: return null
if (context.getString(R.string.app_deep_link_host) != uri.host) return null
val map = mutableMapOf<String, Any>()
uri.queryParameterNames
.map { key ->
val value = uri.getQueryParameter(key)
val name = if (key == "intentKey") "Code" else key
if (value != null) map[name] = value
}
return map
}
}
Then handle it in your activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
handleIntent(intent) // Handle deep link if app is cold-started
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
handleIntent(intent) // Handle deep link if activity is reused
}
private fun handleIntent(intent: Intent) {
val deepLinkData = AppDeepLinkHelper.getASAPPDeepLinkDataIfAny(this, intent)
if (!deepLinkData.isNullOrEmpty()) {
APP.instance.openChat(this, asappIntent = deepLinkData)
} else {
openChatIfNotificationIntent(intent)
}
}
✅ Tip: This approach ensures your app only responds to deep links from the expected host, and safely maps query parameters into a format that openChat() can consume.
Handling Web Links in Chat
Certain chat flows may present buttons that are web links. To react to taps on these buttons, implement the ASAPPWebLinkHandler interface:
ASAPP.instance.webLinkHandler = object : ASAPPWebLinkHandler {
override fun handleASAPPWebLink(webLink: String, activity: Activity) {
// Handle web link.
}
}
If you don’t implement the handler (see above), the ASAPP SDK will open the link utilizing the system default with Intent.ACTION_VIEW.
Implementing Deep Links into Chat
Getting Started
Please see the Android documentation on Handling Android App Links.
Connecting the Pieces
Once you set up a custom URL scheme for your app and handle deep links into your application, you can start chat to pass any data payload extracted from the link:
ASAPP.instance.openChat(context, asappIntent= mapOf("Code": "EXAMPLE_INTENT"))