In the previous post, we presented you with a simple and effective guide to integrating dialog flow bot in a website and Android. 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 the languages Swift and Objective C in our iOS SDK and we have made it very easy to add using CocoaPod.   

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: Setup 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.

building ios chatbot with dialogflow - Kommunicate

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

To complete the setup, click on Next and setup Bot Profile. You can check your newly created bot in two places:
Dashboard →Bot Integration → Integrated 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:

Setup App id:

   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 // Pass userId here NOTE : +,*,? are not allowed chars in userId.
kmUser.email = emailId // Optional

// Use this same API for login
Kommunicate.registerUser(kmUser, completion: {
    response, error in
    guard error == nil else {return}
    print(" login Success ") // You can launch the chat screen on success of login
})

NOTE: Before login user to Kommunicate, you need to use the Kommunicate.setup(applicationId:<Your App ID>) so that applicationId will be set up in starting phase

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.

      let agentId = ["agent@yourdomain.com"] // Pass your agent id here
        let botId = ["bot"] //enter your integrated bot Id

        Kommunicate.createConversation(
            userId: "",
            agentIds: agentId,
            botIds: botId,
            useLastConversation: true,
            completion: { response in
                guard !response.isEmpty else {return}
                Kommunicate.showConversationWith(groupId: response, from: self, completionHandler: { success in
                })
        })

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.

Here are some sample chat screens of the iOS app with Dialogflow and Kommunicate

Are you considering chatbots for your business? Download the Complete Beginner's Guide to Chatbots 
for a more detailed explanation on chatbots' capabilities, industry use-cases and a step-by-step guide 
on how to build one.

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.

Related Posts:

1. Build Android Chatbot with Dialogflow (API.ai)

2. Integrate Dialogflow (Api.ai) Bot into Website


Subscribe here to get the good stuff — we solemnly swear to deliver top of the line, out of the box and super beneficial content to you once a week.

At Kommunicate, we are envisioning a world-beating customer support solution to empower the new era of customer support. We would love to have you on board to have a first-hand experience of Kommunicate. You can signup for free and start delighting your customers right away.

Author