iOS SDK
iOS SDK for DigitalGenius Chat.
Overview
This SDK enables the DigitalGenius Chat Widget to be embedded anywhere inside an iOS app. The SDK requires minimal setup. Please see the PublicDemoApp.zip
for an example.
A DigitalGenius Customer Success Manager will provide you with a widgetId
, env
and scriptVersion
before getting started. Please see the Integrating SDK to your project
section for details on how to integrate following settings into an iOS app using the SDK.
Installation
- Get the iOS framework that contains a latest version of SDK and extract the zip file.
- Drag
DGChatSDK.xcframework
into your project. - Make sure "Copy items if needed" is selected and click Finish.
- In the target settings for your app, set the
DGChatSDK.xcframework
to “Embed & Sign”. This can be found in the “Frameworks, Libraries, and Embedded Content” section of the “General” tab.
Basic usage example.
First of all, import DGChatSDK
.
import DGChatSDK
DGChatSDK
uses delegate methods to get its configuration items and provide callbacks about user actions.
final class MyViewController: UIViewController, DGChatDelegate {
override func viewDidLoad() {
super.viewDidLoad()
DGChat.shared.delegate = self
}
}
To make everything work as expected, you'll need to implement a DGChatDelegate
protocol.
The most important and required delegate properties are:
DGChatDelegate.widgetId
- which tells SDK your unique client identifier.
DGChatDelegate.env
- the env in which the widget is running (either eu
or us
).
DGChatDelegate.scriptVersion
- a version of the script, used by your organization.
All of these information is provided by a DigitalGenius Customer Success Manager.
Plase see an example implementation below:
var widgetId: String {
"b5e736c9-1508-41df-827e-212e13f52929"
}
var env: String {
"eu"
}
var scriptVersion: String {
"2.1.2"
}
It is highly important to provide
DGChatDelegate.scriptVersion
as a Semantic versioning three-part version number. Otherwise, you'll encounter runtime error.
Additionally, if your organisation uses Sunco or Gorgias as a crm and your widget will be handing over to agents you will need to add the following:
var crmCredentials: DGChatCRMCredentials? {
DGChatCRMCredentials(platform: "sunco", version: "1.0.0")
}
And finally, just call DGChat/add(to:animated:completion:)
to present a chat button on top of specified ViewController.
Using Widget metadata
You can specify a metadata
, provided by vendor for your particular business needs.
To use that, you just need to implement proper DGChatDelegate
method:
var metadata: String {
"""
"currentPage": "some-random-string",
"currentPageTitle": "another-random-string"
"""
}
Please note: You should stick to the formatting, provided by Vendor, otherwise metadata
will be considered as invalid without explicit errors thrown.
Additional Methods
You can use a set of additional methods to interact directly with Chat Widget. These methods are lised as a part of DGChat.shared
instance.
The sendMessage
method allows the customer to programmatically send a message on the user behalf. This method is not available once the user is handed over to a crm:
public func sendMessage(_ message: String, completion: @escaping (Result<Void, Error>) -> Void)
public func sendMessage(_ message: String) async throws
The launchWidget
method allows the customer to programmatically launch the widget:
public func launchWidget(_ completion: @escaping (Result<Void, Error>) -> Void)
public func launchWidget() async throws
The initProactiveButtons
method allows the customer to programmatically trigger the proactive buttons to display:
public func initProactiveButtons(values: String, completion: @escaping (Result<Void, Error>) -> Void)
public func initProactiveButtons(values: String) async throws
Sample project
The interaction model and example usage can be found in Demo project. Refer to the ViewController.swift
file.
SwiftUI
If you are using SwiftUI for your project, please use GeniusChatView
as listed on the example below:
var body: some View {
VStack {
GeniusChatView(
widgetId: "your_widget_id",
flowURL: "https://flow_server_uri_for_your_company.com",
scriptVersion: "1.1.0")
}
.padding()
}
ReactNative
To use Genius SDK in ReactNative projects, please follow these steps:
- Use
ReactNativePublicDemo/dgchatsdk
folder as a root. - Add prebuilt framework (
.xcframework
file) of DGChatSDK for ios into./dgchatsdk/ios
- In
./dgchatsdk folder
run:npm install
. - After that, run:
cd ios && pod install && cd ..
- Open
dgchatsdk.xcworkspace
in./ios
folder to use from Xcode. - Build&run project.
- Modify
App.tsx
file if needed in./dgchatsdk
folder - Module
DGChatModule
has 3 functions and JS emiters for chat actions callbacks. - Please consult example of usage in
App.tsx
.
Initial setup will look like:
DGChatModule.showDGChatView(
'Place your widgetId here',
'Place your flowURL here',
'Place a version of SDK here',
'{"currentPage": "some-random-string", "currentPageTitle": "another-random-string"}',
);
And a callbacks section:
let onChatMinimizeClickEventListener = eventEmitter.addListener(
'OnChatMinimizeClick',
event => {
DGChatModule.logActionWith('OnChatMinimizeClick');
},
);
let onChatEndClickEventListener = eventEmitter.addListener(
'onChatEndClick',
event => {
DGChatModule.logActionWith('onChatEndClick');
},
);
let onChatLauncherClickEventListener = eventEmitter.addListener(
'onChatLauncherClick',
event => {
DGChatModule.logActionWith('onChatLauncherClick');
},
);
let onChatProactiveButtonClickEventListener = eventEmitter.addListener(
'onChatProactiveButtonClick',
event => {
DGChatModule.logActionWith('onChatProactiveButtonClick');
},
);
For more detailed example, please refer to App.tsx
.
Updated 3 months ago