Initializing the SDK

This method initializes the SDK.

LPABCSDK.initialize() // default minimumLogLevel will be .info and enableLog will be true

LPABCSDK.initialize(minimumLogLevel: .trace, enableLog: false)

Update the SDK with Incoming CIM

Upon an agent sending a Custom Interactive Message (CIM) to the consumer, this method will update the SDK with a payload that will enable SDE reporting to LiveEngage.

lpabcsdk.update(with: conversation)

lpabcsdk.update(with: conversation, message: message)

Should be implemented from both override functions:

  • didBecomeActive(with conversation: MSConversation)
  • didReceive(_ message: MSMessage, conversation: MSConversation)

in the iMessage extension MSMessagesAppViewController

See step 6 of Installation for more.

Create SDEs

When you create one or more SDEs, they get added to a Stack that the framework manages for you.

The createSDE function generates and calls back an SDEBase object with a template of the relevant SDE type as its property, which then needs to implement a 'setup' function.

Pass in the SDE type that you want, and it will return an SDEBase object containing an instantiated property of the relevant SDE template object.

All dependant schema objects could be initiated and passed in as arguments to the SDE setup

Inside of the completion callback, on the sde setup method, it is required to define the relevant params to initiate the sde.

Example 1:

lpabcsdk.createSDE(sdeType: .visitorError) { (sdeBase) in
    sdeBase.visitorError?.setup(
        contextId: "<CONTEXID>",
        message: "<MESSAGE>",
        code: "<CODE>",
        level: 0,
        resolved: true
    )
}

Example 2:

lpabcsdk.createSDE(sdeType: .cartUpdate) { (sdeBase) in
    //Create a product:
    let product = SDEProduct.init(
        name: "<>", 
        category: "<>", 
        sku: "<>", 
        price: 100, 
        quantity: 3
    )
    
    //Setup the sde:
    sdeBase.cartUpdate?.setup(
        total: 100, 
        currency: "<>", 
        numItems: 1, 
        products: [product]
    )
}

The SDE setup call could also be created using 'LPUnifiedLooseSDEProtocol', as json string or Dictionary object:

Example:

sdeBase.setupWithJson("{\"type\":\"ctmrinfo\"}")
sdeBase.setupWithJson(["type":"cart"])

Auto Send Aggregated Stack

The optional aggregate parameter, when set to true, will add the sde to the aggregateStack which will get sent automatically once the aggregation stack timeout is met. Default is 5 sec but could be anything between 1-15 sec. See setAggregatedInterval(interval:)

Example:

lpabcsdk.createSDE(sdeType: .customerInfo, aggregate: true) { (sdeBase) in
    sdeBase.customerInfo?.setup(
        cstatus: "<cstatus>",
        ctype: "<ctype>",
        balance: 10,
        currency: "<currency>",
        socialId: "<socialId>",
        imei: "<imei>",
        userName: "<userName>",
        companySize: 30,
        companyBranch: "<companyBranch>",
        accountName: "<accountName>",
        role: "<role>",
        loginStatus: 0,
        storeZipCode: "<storeZipCode>",
        storeNumber: "<storeNumber>",
        lastPaymentDate: SDEDate.init(
            day: 23, 
            month: 4, 	
            year: 2019
        ),
        registrationDate: nil
    )
}

Sending SDE

In order to manually send the SDE Stack, use the following:

lpabcsdk.sendSDEStack()

// or using completion callbacks:
lpabcsdk.sendSDEStack(onSuccess: { (success) in
    // success closure
}) { (error) in
    // error closure
}

Aggregated SDE Stack Timeout

This will setup a timeout interval for auto sending the aggregated SDE stack (optional). Default is 5 seconds and Max is 15.

lpabcsdk.setAggregatedInterval(interval:15)

See the Auto Send aggregated optional parameter in Create SDEs.

Aggregated SDE Stack Send Completion Closure

If you want to execute code whenever the Aggregated SDE Stack auto send completes, implement the aggregatedSDEStackCompletion closure:

lpabcsdk.aggregatedSDEStackCompletion = {  completion, error in
    // debug code
}

Implicit Event Callback

Some consumer actions can trigger an implicit SDE flow (eg. a new conversation starts). If you would like to send an SDE upon one of these events triggering, you can do so by implenting the implicitEventClosure method.

lpabcsdk.implicitEventClosure = { implicitEventType in 
    // implement 
}
  • ImplicitEventType - Indicates the type of implicit event that is being called back from the implicitSDEClosure.

  • implicitEventClosure - Invoked when a qualifying event is met, and callback the type of that event

You can set the desired SDEs to express your custom reporting for the event triggered.

Supported Event Types: - newConversation - Receiving an incoming (agent to consumer), new first time CIM - per conversation.

Example:

lpabcsdk.implicitEventClosure = { implicitType in 
    switch implicitType {
        case .newConversation:
            // Create and send desired SDE
    }
}

Reply CIM from Consumer to Agent

An agent can recieve back from the consumer a Custom Interactive Message with contextual text. This text can be displayed to the agent in the LiveEngage workspace.

For example, if the consumer selects a product inside of your iMessage app, the Agent can see which product they selected via the textContent of this method.

// create MSMessage object

lpabcsdk.appendReplayMessagePayload(message: MSMessage, textContext: String)

// send MSMessage object

Pass in the initiated MSMessage object, and the desired textual String.

Synchronize SDK (Host app target feature)

When called, the SDK will explicitly sync with the latest cache version.

The best practice will be to add this to your AppDelegate/ applicationWillEnterForeground, in order to use the monitoring ability when the host app enters the foreground.

An iMesssage extension target will have no effect calling this function.

func applicationWillEnterForeground(_ application: UIApplication) {
    LPABCSDK.synchronize()
}