Skip to main content
Version: Latest

with Playchat

related files
  • ChatbotSampleViewController.swift

AI Human + PlayChat is a conversational AI service provided by DeepBrain AI.
When you enter the screen, the AI gives you a greeting. After that, you can communicate with the AI.
In the sample, the chatbot can respond to only a few limited conversations, but with more advanced PlayChat chatbot settings, it can be applied in a variety of situations, such as ordering at a restaurant or making a reservation.

Creating a PlayChat chatbot

func makeChatbot() {
chatbot = MBPlayChat(botId: "blank_user0_1608025226460", delegate: self)
}

Getting started PlayChat If you are connected after PlayChat is created, you can start chatting.

func didConnect() {
chatbot.start()
}

CallBack

You can check the connection states and errors of PlayChat, as well as messages received from the chatbot.

extension ChatbotSampleViewController: MBPlayChatDelegate {
func didConnect() {
...
}

func didDisconnect() {
...
}

func onError(error: Error?) {
...
}

func onReceive(event: ChatbotEvent) {
self.event = event
if event.name == "onMessage" {
let text = event.text
if let img = event.image {
self.chattingView.addChatWithImage(text: text, imgUrl: img.urlString, isLeft: true)
}else {
self.chattingView.addChat(text: text, isLeft: true)
}
}
}
}

Send message to PlayChat

func sendToServer(text: String) {
chatbot.send(event: "userInput", parameters: ["text" : text])
}