Javascript Interfaces in SDK
SDK exposes Javascript Interfaces to support functionalities that uses WebView.
Hybrid Engagement
SDK lets you start a native Chat from a Business Rule running within a WKWebView. SDK handles all the necessary communication between JavaScript and Native.
Nuance Business Rule engine loaded within a WebView page executes the Business Rule for that page upon page load. C2C button is displayed on the page if BR engine finds a match.
If user decides to click the C2C button, Nuance BR engine redirects the engagment request to Native Nuance SDK.
Public Methods
You must call the below NuanMessaging public method to enable this bridge between javascript and Native SDK.
-
-(NSString *)getWebViewInterfaceName
You must call the this method to retrieve the Interface Name which is need by the javascript to send message to native code, add this interface name as an item to the WKUserContentController instance.
-
-(Engage *)handleWebviewRequest:(NSString *)body andNewEngagementHandler:(void (^)(NSDictionary *params,NSDictionary *datapass))completionBlock andEvaluateJSHandler:(void (^)(NSString *jsstring))jsBlock
Call this method when ever application receives a message from Nuance Business Rule engine running within a WebView. Pass the body of the message as an argument to this method.
andNewEngagementHandler: The given callback will be invoked when ever user requested for a new engagement session.
andEvaluateJSHandler: This callback will be invoked when ever SDK needs to execute javascript command within the webview.
andPendingMsgHandler: This callback will be invoked when there is a pending message from agent.
Conversation in Play
If there is a pending message from agent pendingMsgHandler will be called with a c2c id. Application should be displaying a restore button. Upon user clicking the restore button applciation should call below API
Public Methods
You must call the below NuanMessaging public method when user clicks restore button.
let contentController = WKUserContentController()
contentController.add(
self,
name: NuanMessaging.getInstance().getWKWebViewInterfaceName()
)
func userContentController(_ userContentController:WKUserContentController, didReceive message: WKScriptMessage) {
if(message.name == NuanMessaging.getInstance().getWKWebViewInterfaceName()) {
NuanMessaging.getInstance().handleWebviewRequest(message.body as! String, andNewEngagementHandler: { (params, datapass) in
var vc:NuanceMessagingViewController;
vc = launchMessagingViewControllerForHybrid(paramsDict: (params as? Dictionary)!,dataPass: (datapass as? Dictionary)!, webview: self.webView)
self.setupMessagingUIProps(vc: vc)
DispatchQueue.main.async {
self.present(vc, animated: false, completion: nil)
}
}, andEvaluateJSHandler: { (js) in
self.webView.evaluateJavaScript(js!, completionHandler: nil)
}, andPendingMsgHandler: { (c2cidx) in
});
}
}
Nina WebView SDK
Nuance SDK lets Application to use Nina WebView SDK within Nuance Messaging SDK. Nuance Messaging SDK uses Nina WebView SDK to render rich html transcript contents returned from Nina Virtual Assitant.
Nina WebView SDK is not preloaded inside the SDK. It must be added by the application. Assets are provided as part of SDK deliverable
Configuring Nina WebView SDK
Properties to customize Nina SDK is exposed from MessagingViewProperties class.
Name
type
default
description
isNinaWebRequired
boolean
false
Set this property to enable Nina WebView SDK
htmlFileUrlPathForTranscript
URL
nil
Pass the url to the Nina WebView asset. Bundle.main.url(forResource: "index", withExtension: "html")
Name | type | default | description |
---|---|---|---|
isNinaWebRequired | boolean | false | Set this property to enable Nina WebView SDK |
htmlFileUrlPathForTranscript | URL | nil | Pass the url to the Nina WebView asset. Bundle.main.url(forResource: "index", withExtension: "html") |