Using ChatSDK with Zendesk iOS Swift

1.2k Views Asked by At

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: "[email protected]", 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")
        }
    }
3

There are 3 best solutions below

0
On BEST ANSWER

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.

5
On

I have the same problem

try comment this line:

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

and

chatConfiguration.preChatFormConfiguration = formConfiguration

and

 let chatConfiguration = ChatConfiguration()
    chatConfiguration.isPreChatFormEnabled = false

    let chatAPIConfiguration = ChatAPIConfiguration()
    chatAPIConfiguration.department = "Blah"
    chatAPIConfiguration.visitorInfo = VisitorInfo(name: "BlahUser", email: "[email protected]", phoneNumber: "")
    Chat.instance?.configuration = chatAPIConfiguration;

UPD:

I have the same problem and I wrote in support. They answer me for a very long time, the correspondence has been going on for almost a week.

I decided to analyze in more detail because of what such an error may be.

I tried to send a picture in the chat - the chat earned.

But if you just write text messages, they are not sent.

I then decided to comment on the information about the user and then everything worked, but in the chat information it is not visible what the user writes ...

1
On

Saad Ullah, im enabled departments in chat setting on website and ios chat now work... Can you check too?

Revert changes in code and try