Skip to content

andreyguenov/api-ai-cocoa-swift

This branch is 2 commits ahead of, 3 commits behind dialogflow/api-ai-cocoa-swift:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3249f74 · Apr 16, 2017

History

36 Commits
Feb 7, 2017
Mar 2, 2017
Mar 2, 2017
Mar 2, 2017
Feb 7, 2017
Mar 2, 2017
Jan 18, 2017
Jan 18, 2017
Mar 2, 2017
Nov 13, 2015
Apr 16, 2017

Repository files navigation

Cocoa SDK for api.ai

Build Status Version License Platform Carthage Compatible


Overview

The API.AI iOS SDK makes it easy to integrate natural language processing API on Apple devices. API.AI allows using voice commands and integration with dialog scenarios defined for a particular agent in API.AI.

Prerequsites

Running the Demo app (CocoaPods supports only)

  • Run pod update in the AIDemo project folder.

  • Open AIDemo.xworkspace in Xcode.

  • In AppDelegate insert API key.

    AI.configure("YOUR_CLIENT_ACCESS_TOKEN")
    

    Note: an agent in api.ai should exist. Keys could be obtained on the agent's settings page.

  • Define sample intents in the agent.

  • Run the app in Xcode. Inputs are possible with text and voice (experimental).

Integrating into your app

CocoaPods

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. Installing:

$ [sudo] gem install cocoapods

List "AI" in a text file named Podfile in your Xcode project directory:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'AI', '~> 0.7'
end

Now you can install the dependencies in your project:

$ pod install

Carthage

Carthage is intended to be the simplest way to add frameworks to your Cocoa application.

You can use Homebrew and install the carthage tool on your system simply by running brew update and brew install carthage.

Create a Cartfile with following text:

github "api-ai/AI"

Run carthage update. Drag the built AI.framework into your Xcode project.

Create a bridging header

Create a bridging header by choosing File > New > File > (iOS, watchOS, tvOS, or macOS) > Source > Header File and save the header file in your project root directory.

Paste the following lines in the bridging header file:

#ifndef Header_h
#define Header_h
#import <ApiAI/ApiAI.h>
#endif /* Header_h */

In XCode, click on your project file -> Build Settings -> Swift Compiler - General -> Objective-C Bridging Header. Specify the location of the header file in the field to the right. For example that might look like:

/Users/user/Documents/MyProject/MyProject/Header.h

Init the SDK.

In the AppDelegate.swift, add AI import:

import AI

In the AppDelegate.swift, add

// Define API.AI configuration here.
AI.configure("YOUR_CLIENT_ACCESS_TOKEN")

Perform request.

...
// Request using text (assumes that speech recognition / ASR
// is done using a third-party library, e.g. AT&T)
AI.sharedService.TextRequest("Hello").success { (response) -> Void in
    // Handle success ...
}.failure { (error) -> Void in
    // Handle error ...
}

About

Cocoa Swift library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.9%
  • Ruby 2.2%
  • Objective-C 0.9%