Link Interception
No link opens inside the chat. When someone taps an http, https, mailto, tel or sms link, the SDK opens it outside the app: in the browser, or in the app that handles the scheme, such as Mail, Phone or Messages. Links with any other scheme are blocked. To handle some links in your app instead, set a link delegate
Set a delegate
final class ChatLinks: KindlyWebViewClientDelegate {
func shouldHandleLink(url: URL) async -> Bool {
guard url.host == "myapp.example" else { return true }
await MainActor.run {
// open it in your app
}
return false
}
}
let chatLinks = ChatLinks()
KindlyWebViewSDK.delegate = chatLinksThe SDK holds the delegate weakly, so keep a reference to it. The method is async, and a synchronous implementation satisfies the protocol too. Do UI work on the main actor, as above
Return true to let the SDK open the link, or false to handle it yourself. The delegate stays set across start and kill
Timeouts
The SDK waits 5 seconds for an answer, and no answer counts as true. The Flutter and React Native packages stop waiting for your callback after 4 seconds (KindlyWebViewSDK.linkCallbackTimeout in Flutter, KindlyWebViewSDK.linkCallbackTimeoutMs in React Native), so their answer always reaches the native SDK in time. On Android, React Native pauses JavaScript timers while the chat screen is in front, so the native 5 seconds apply there, see Authentication
Which links reach the delegate
The SDK asks the delegate only about links it would open, so the rules below apply first:
- Links open only while the chat is displayed
- A custom scheme, such as myapp://orders, is blocked and never reaches the delegate. To route a bot link into your app, link to an https address on your domain and intercept it here
- The SDK opens at most three links in 10 seconds and ignores a second tap on the same link within 1.5 seconds
The SDK cancels the web view's navigation before it asks, so a slow answer never holds the chat