2

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")
        }
    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Saad Ullah
  • 103
  • 2
  • 13

3 Answers3

2

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: "test@test.com", 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 ...

Linyx
  • 21
  • 3
  • Thank you for your contribution to the community. This may be a correct answer, but it’d be useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who may not be familiar with the syntax. Further, it can help reduce the need for follow-up questions. Would you mind updating your comment with additional details? – Jeremy Caney May 14 '20 at 00:16
  • Can you explain me more in detail what I am doing wrong here ? If I comment on the above lines you told me then how chat will initiate ? – Saad Ullah May 14 '20 at 13:44
  • 2
    One more thing is I am not getting end chat in any observer. I have updated my question – Saad Ullah May 14 '20 at 14:31
  • Chat is now working sending and receiving messages. Thanks a alot. – Saad Ullah May 14 '20 at 15:17
  • @Linyx do you know how to get the callback when agent left the chat. ? – Saad Ullah May 16 '20 at 16:02
1

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.

Saad Ullah
  • 103
  • 2
  • 13
0

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

Linyx
  • 21
  • 3
  • Cool let me try as well. But I am facing another issue , not getting call back when agent left the chat. Do you know how to get it ? – Saad Ullah May 19 '20 at 13:46