Once your webview has been created with this URL on click of a button or any other action which loads the URL you will invoke the following Javascript in the webview.
// Load the chatbot with MetadataprivatefuncactionButtonJs() ->String {do {var metadataJSON =json(from: self.session.metadata)print("[DeepConverseSDK] Metadata:", metadataJSON)let s =""" setTimeout(function () {var evt = new CustomEvent('botWidgetInit', { detail: \(metadataJSON!) });document.dispatchEvent(evt);}, 100)
document.addEventListener('dc.bot', function(e) { let payload = { action: e.detail.action }; window.webkit.messageHandlers.actionTapped.postMessage(payload); }); """return s; } catch {print("[DeepConverseSDK] Error in Metadata"+ error.localizedDescription);// Fallback to load without metadatalet s =""" setTimeout(function () {var evt = new CustomEvent('botWidgetInit', { detail: {} });document.dispatchEvent(evt);}, 100)
document.addEventListener('dc.bot', function(e) { let payload = { action: e.detail.action }; window.webkit.messageHandlers.actionTapped.postMessage(payload); }); """return s; }}
Here is the example of how to configure the webview and use the above function.