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

  1. Get the iOS framework that contains a latest version of SDK and extract the zip file.
  2. Drag DGChatSDK.xcframework into your project.
  3. Make sure "Copy items if needed" is selected and click Finish.
  4. 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

See for more details.

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:

  1. Use ReactNativePublicDemo/dgchatsdk folder as a root.
  2. Add prebuilt framework (.xcframework file) of DGChatSDK for ios into ./dgchatsdk/ios
  3. In ./dgchatsdk folder run: npm install.
  4. After that, run: cd ios && pod install && cd ..
  5. Open dgchatsdk.xcworkspace in ./ios folder to use from Xcode.
  6. Build&run project.
  7. Modify App.tsx file if needed in ./dgchatsdk folder
  8. Module DGChatModule has 3 functions and JS emiters for chat actions callbacks.
  9. 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.