Search code examples
iosswiftzendeskzendesk-apichatsdk

Using ChatSDK with Zendesk iOS Swift


I am updating ZDCChat to ChatSDK. I am facing an issue right now.

Every time I come to chat screen Chat.accountProvider?.observeAccount this observer tells me that No Agent Available. But agent is available with me on my browser.

Second thing is when I enter a message and hit send , it's not showing on my chat screen.

Here is the code. This is in AppDelegate:

 let chatConfiguration = ChatConfiguration()
    chatConfiguration.isPreChatFormEnabled = false

    let chatAPIConfiguration = ChatAPIConfiguration()
    chatAPIConfiguration.department = "Blah"
    chatAPIConfiguration.visitorInfo = VisitorInfo(name: "BlahUser", email: "test@test.com", phoneNumber: "")
    Chat.instance?.configuration = chatAPIConfiguration;

    Chat.initialize(accountKey: "------my key------", queue: .main)

This is how I am starting the chat

 let chatAPIConfiguration = ChatAPIConfiguration()
    chatAPIConfiguration.department = "iOS App"
    chatAPIConfiguration.visitorInfo = VisitorInfo(name: nameField.text!, email: emailField.text!, phoneNumber: "")
    Chat.instance?.configuration = chatAPIConfiguration;

do {
      let chatEngine = try ChatEngine.engine()
      let viewController = try Messaging.instance.buildUI(engines: [chatEngine], configs: [])
        viewController.view.backgroundColor = Constants.bgColor
      self.navigationController?.pushViewController(viewController, animated: true)
    } catch {

      // handle error
        print("error initaiting chat")
    }

End chat is also not working, I am keep getting the Session Started.

 let stateToken = Chat.chatProvider?.observeChatState { (state) in
        // Handle logs, agent events, queue position changes and other events
        print("My Session status: ", state.chatSessionStatus)
        switch state.chatSessionStatus {
        case .configuring:
            print("COnfiguring")
        case .ended:
            print("Ended")
        case .ending:
            print("Ending")
        case .initializing:
            print("initializing")
        case .started:
            print("started")
        default:
            print("Default Case")
        }
    }

Solution

  • If any of you find this and stuck in the issue then do contact me, We'll solve the issue together.

    So, After so many struggle.

    Found out that we don't need these lines of code :

    let chatAPIConfiguration = ChatAPIConfiguration()
    chatAPIConfiguration.department = "iOS App"
    chatAPIConfiguration.visitorInfo = VisitorInfo(name: nameField.text!, email: emailField.text!, phoneNumber: "")
    Chat.instance?.configuration = chatAPIConfiguration;
    
    chatConfiguration.preChatFormConfiguration = formConfiguration
    

    After I removed this code, the app is working fine then. I am still working in finding how to customize the UI.

    Special Thanks to @Linyx. Thanks for helping me finding the solution.