Handle Custom URLs in Chat
When an agent sends a standard link to a user in your app, a preview tile appears that the user can tap to view in a browser. However, you can come up with your own URL scheme that displays a custom tile and performs a custom action within your app.
-
Create a custom URL scheme and expression.
Create a URL scheme using the SCSAppEventList class. This class allows you to add URLs either for specific paths (such as action/settings) or using regular expressions (such as action\\/a.*). Patterns are matched in the order that you add them to the SCSAppEventList object. Be sure to add items starting with the most specific and ending with the most generic.
// Create an app event list // TO DO: Replace "servicesdk" with your own unique scheme let eventList = SCSAppEventList(scheme: "servicesdk") // Add a regular expression for a path eventList.addDescription("Tap for regex action", withExpression: "action\\/a.*") // Add a custom path for a specific path eventList.addDescription("Tap for path action", forPath: "action/settings")
-
Add the event list to your SCSChatConfiguration object.
// Create a chat config object let config = SCSChatConfiguration(liveAgentPod: "YOUR_POD_NAME", orgId: "YOUR_ORG_ID", deploymentId: "YOUR_DEPLOYMENT_ID", buttonId: "YOUR_BUTTON_ID") // … Perform other chat configuration setup … // Add event list to chat configuration config.eventList = eventList
-
Implement the SCSChatInterfaceDelegate delegate so that you can handle when the user taps on the URL.
class MyChatDelegate: SCSChatInterfaceDelegate { func interface(_ interface: SCSChatInterface!, didReceiveAppEventWith URL: URL!) // Get path guard let fullPath = (URL as NSURL).resourceSpecifier else { return } // Minimize chat window ServiceCloud.shared().chatUI.minimize() if fullPath.contains("action/settings") { // TO DO: Perform some action for this url return } if fullPath.contains("action/alert") { // TO DO: Perform some action for this url return } // NOTE: You can maximize the chat window using // ServiceCloud.shared().chatUI.maximize() } }
-
Add your delegate to the chat interface.
ServiceCloud.shared().chatUI.delegate = myChatDelegate