Building iOS Chatbot with Dialogflow (API.ai)

Mukesh Thawani
Chatbots Life
Published in
5 min readJun 2, 2020

--

Source

In this article, we will be sharing steps to building iOS chatbot with Dialogflow. All you need to build a sample chatbot using Dialogflow and Kommunicate for an iOS app.

Below is an example of Kommunicate Support Bot developed in iOS using Dialogflow and Kommunicate. We actually use this bot on our website. If you wish to see the bot live in action, click here.

We support both Swift and Objective-C in our iOS SDK, and we have made it very easy to integrate through CocoaPods.

Trending AI Articles:

1. Build a Telegram Bot Scheduler with Python

2. A Conversational UI Maturity Model: a guide to take your bot to the next level

3. Designing a chatbot for an improved customer experience

4. Chatbot, Natural Language Processing (NLP) and Search Services and how to mash them up for a better user experience

The actionable rich messaging powered bot can reply based on whether users are on chat for general queries, technical queries, Just checking out or scheduling a demo.

You can use your existing Dialogflow bot or checkout bot samples to build a qualifying bot of your own. Download the Kommunicate Support Bot from here and import into your Dialogflow account.

Let us know jump into the crux of this post.

Step by Step Guide to Building iOS Chatbot with Dialogflow

Step 1: Set up an account in Kommunicate

This is fairly simple. You can get a free account in Kommunicate. Signup and navigate to the Bot section. Click on Settings in the Dialogflow block.

This is fairly simple. You can get a free account in Kommunicate. Sign up and navigate to the Bot section. Click on Settings in the Dialogflow block.

Upload your Dialogflow provided client keys. In case you are using Dialogflow V1, you can copy and paste your client and dev tokens. Though, we recommend using Dialogflow V2 for the latest capabilities.

Set up your bot’s name and profile picture and choose whether to allow the bot to human handoff for your newly created bot. Click Finish bot integration setup and voilà, your bot is now integrated.

You can check your newly created bot in two places:

Dashboard →Bot Integration → Manage Bots: You can check all your integrated bots here.

Dashboard → Bot Integration: Your Dialogflow icon should be green with the number of bots are you have successfully integrated.

Once you create a bot then you set it as a default bot in the conversation routing section as shown below. Click on Settings –> Conversation rules –> Then click on bot like below and select your bot.

Now, this bot will reply in all the conversations.

Step 2: Install and setup Dialogflow integrated iOS Chatbot SDK into your app

In this step, you need to add Kommunicate iOS SDK to your app. Installing Kommunicate SDK it comes with pre-configured Dialogflow integration. Follow the below instructions to add iOS SDK in your app:

Initialize CocoaPods:

Kommunicate is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Kommunicate'

This is how pod file looks like finally:

target 'MyTargetName' do
use_frameworks!
pod 'Kommunicate'
end

Run pod install in your project terminal folder:

pod install

After finishing the installation, you can initialize the SDK by calling the below method:

Kommunicate.setup(applicationId:<Your App ID>)

You can get your unique Application ID in the Installation Section. If in any file, you’d like to use Kommunicate, don’t forget to import the framework with import Kommunicate.Login user to Kommunicate:You need to register the user using below Kommunicate.registerUser method before starting chatting and pass the userId and email of the user.

let kmUser = KMUser()
kmUser.userId = <userId>
kmUser.displayName = <displayName>
// Use this same API for login
Kommunicate.registerUser(kmUser, completion: {
response, error in
guard error == nil else {return}
print("login success") // Now, you can launch the chat screen
})

Step 3: Send and receive Information

Now, you can send the payload data to Dialogflow through chat screen and get a text response from Dialogflow Agent. Kommunicate provides a ready to use Chat UI so only launching the chat screen is required in this step.

// Pass an instance of the current UIViewController in the 'from' argument.
Kommunicate.createAndShowConversation(from: self) { error in
guard error == nil else {
print("Conversation error: \(error.debugDescription)")
return
}
// Success
}

You can refer the more documentation for conversation section here. Run the iOS project and chat with the Dialogflow bot. You can easily integrate Dialogflow in iOS apps in a few simple steps. In case you need more information, you can check out the Kommunicate iOS documentation.

Kommunicate Sample application: Download the sample app from here which includes ready to use Kommunicate iOS SDK.

Dialogflow iOS SDK Client:

Dialogflow provides iOS Client SDK that makes it easy to integrate speech recognition with API.ai natural language processing API on Apple devices.

If you are looking to develop your own chat implementation and directly you can integrate Dialogflow into your iOS app without Kommunicate SDK, then integrate with the following SDK from GitHub: Dialogflow iOS Client SDK.

Liked the story? Hit that clap button and follow me on Medium. Thanks for reading! This article was originally published on Kommunicate blog.

Don’t forget to give us your 👏 !

--

--