Initialize the Messaging SDK

  1. Initialize the SDK and all of its components. You can initialize the SDK with or without a brandID.

    public func initialize(_ brandID: String? = nil, monitoringInitParams: LPMonitoringInitParams? = nil) throws
    
  2. Initialize conversationViewParams for show conversation.

    If you do not pass containerViewController in containerViewController, the SDK provides a ViewController called Window Mode. If you pass the containerViewController, the SDK uses it to Host the Conversation Window called ViewController Mode.

    public init(conversationQuery: ConversationParamProtocol,
                    containerViewController: UIViewController? = nil,
                    isViewOnly: Bool = false,
                    conversationHistoryControlParam: LPConversationHistoryControlParam = LPConversationHistoryControlParam(historyConversationsStateToDisplay: .none))
    
  3. Initialize authenticationParams for show conversation.

    Pass authenticationCode for 'Code Flow', pass jwt for Implicit Flow'.

  4. Set authenticationType to .authenticated for Code Flow or Implicit, .unauthenticated for Unauthenticated. If left as nil will default to .signup flow.

    public init(authenticationCode: String? = nil, jwt: String? = nil, redirectURI: String? = nil, certPinningPublicKeys: [String]? = nil, authenticationType: LPAuthenticationType = .signup)
    
  5. Show conversation with two parameters above.

    public func showConversation(_ conversationViewParams: LPConversationViewParams, authenticationParams: LPAuthenticationParams? = nil)
    
  6. Dismiss the Conversation Window from the host ViewController.

    public func removeConversation(conversationQuery: ConversationParamProtocol)
    

    When using Custom View Controller Mode, the Conversation view must be removed when leaving the App. To avoid dismissing the View when CSAT/SecureForms/PhotoSharing View is presented, you should only dismiss the Conversation view if Moving From ParentView, example here.

Initialize the Messaging SDK with Monitoring Params

To get the App key or appInstallationId, a new Conversation Source needs to be added on LiveEngage, for more information about it, contact your Account Team.
  1. Inside viewController add the following imports:

    import LPMessagingSDK
    import LPInfra
    import LPMonitoring
    
  2. Also inside ViewController, under viewDidLoad, add the following code:

    do {
      let monitoringParams = LPMonitoringInitParams(appInstallID: "appInstallationId")
      try LPMessagingSDK.instance.initialize("Your account ID", monitoringInitParams: monitoringParams)
    } catch {
      return
    }
    
  3. Create LPMonitoringParams. The entry points and engagement attributes used here are dummies:

      let entryPoints = ["tel://972737004000",
                        "http://www.liveperson.com",
                        "sec://Sport",
                        "lang://Eng"]
    
      let engagementAttributes = [
        ["type": "purchase", "total": 20.0],
        ["type": "lead",
        "lead": ["topic": "luxury car test drive 2015",
              "value": 22.22,
              "leadId": "xyz123"]]
      ]
    
      let monitoringParams = LPMonitoringParams(entryPoints: entryPoints, engagementAttributes: engagementAttributes)
    
  4. Using the LPMonitoringParams, get the Engagement for the User, which is needed to start a new conversation with a specific campaign.

    LPMonitoringAPI.instance.getEngagement(consumerID: self.consumerID, monitoringParams: monitoringParams, completion: {
          if let first = engagement.engagementDetails?.first {
            let campaign = first.campaignId
            let id = first.engagementId
            let context : String = first.contextId!
            self.campaignInfo = LPCampaignInfo(campaignId: campaign, engagementId: id, contextId: context)
          } else {
            self.campaignInfo = nil
          }
        }) { (error) in
          self.campaignInfo = nil
        }
      }
    
  5. Set up and call the conversation view. You’ll provide your LivePerson account number, a container view controller, and the campaign information.

    let conversationQuery = LPMessagingSDK.instance.getConversationBrandQuery("Your account ID", campaignInfo: campaignInfo)
    let conversationViewParams = LPConversationViewParams(conversationQuery: conversationQuery, isViewOnly: false)
    LPMessagingSDK.instance.showConversation(conversationViewParams, authenticationParams: nil)
    
  6. Remove the conversation view when your container is deallocated:

    let conversationQuery = LPMessagingSDK.instance.getConversationBrandQuery(accountNumber)
    LPMessagingSDK.instance.removeConversation(conversationQuery)
    
    When using Custom View Controller Mode, the Conversation view must be removed when leaving the App. To avoid dismissing the View when CSAT/SecureForms/PhotoSharing View is presented, you should only dismiss the Conversation view if Moving From ParentView, as demonstrated below.
    if (self.conversationQuery != nil && self.isMovingToParentViewController){
      LPMessagingSDK.instance.removeConversation(self.conversationQuery!)
    }
    

Note: When using ViewController Mode, on the Navigation Bar Back Button, you can call LPMessagingSDK.instance.removeConversation(self.conversationQuery!).

Supporting functions:

  1. Get ’filter’ for the conversation screen, determining which of the conversations display in the Conversation Window:

    public func getConversationBrandQuery(_ brandID: String, campaignInfo: LPCampaignInfo? = nil) -> ConversationParamProtocol
    
  2. Get ’filter’ for the conversation screen, determining which of the conversations display in the Conversation Window, using the Consumer ID:

    public func getConversationConsumerQuery(consumerID: String?, brandID: String, agentToken: String) -> ConversationParamProtocol
    
  3. Returns a boolean flag, with Ready when the Brand is connected and conversation can be processed:

    public func isBrandReady(brandID: String) -> Bool