iOS Library for working with the Microsoft QnA Maker Bot Service
Convenience library for working with Microsoft's QnA Maker Service. Microsoft QnA Maker Service lets you create FAQ Bots quickly. The QnABotMaker library enables you to use the QnA Maker Service directly from within your iOS app. Before getting started pleaes check out Microsoft QnA Maker.
Before you get started using this library you will need to create a QnA "Service" using Microsoft's QnA Maker.
Once you have published your QnA Service you will see a Sample HTTP request similar to the one shown below.
POST /knowledgebases/581bd885-5588403d-9935fe3cd325c503/generateAnswer
Host: https://westus.api.cognitive.microsoft.com/qnamaker/v2.0
Ocp-Apim-Subscription-Key: b73f2abc20784927a330c7ad9e354e86
Content-Type: application/json
{"question":"hi"}
The QnABotMaker library needs a few of these parameters in order to connect to the QnA Maker service.
- First we need your knowledgebase identifier or knowledgebaseID, this is the highlighted shown below.
POST /knowledgebases/581bd885-5588403d-9935fe3cd325c503/generateAnswer
- Next we will need your Subscription Key or subscriptionKey, this is the highlighted shown below.
Ocp-Apim-Subscription-Key: b73f2abc20784927a330c7ad9e354e86
- Finally, you will use these parameters when creating an new instance of the QnAService struct as shown in the below example
let bot = QnAService(knowledgebaseID: "581bd885-5588403d-9935fe3cd325c503", subscriptionKey: "b73f2abc20784927a330c7ad9e354e86")
- Xcode 9.1 or newer
- Swift 4.0
- iOS 10 or greater
Cocoapods
QnABotMaker is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "QnABotMaker"
Carthage
github "benbahrenburg/QnABotMaker"
Manually
Copy all *.swift
files contained in QnABotMaker/Classes/
directory into your project.
Swift Package Manager
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler. It is in early development, but Alamofire does support its use on supported platforms.
Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.Package(url: "https://github.com/benbahrenburg/QnABotMaker.git", majorVersion: 1)
]
Using QnABotMaker couldn't be easier. You simply create a new instance of the library and provide the askQuestion function with a question. The completion hander, completionHandler, will provide the QnA answers or an error if necessary.
The following shows the library inaction.
let bot = QnAService(knowledgebaseID: "YOUR-KB-ID", subscriptionKey: "YOUR-SUBSCRIPTION-KEY")
bot.askQuestion("hello", completionHandler: {(answers, error) in
if let error = error {
return print("error: \(error)")
}
if let answers = answers {
print(answers)
}
})
Ben Bahrenburg, @bencoding
QnABotMaker is available under the MIT license. See the LICENSE file for more info.