Swiftpack.co - Package - benbahrenburg/QnABotMaker

QnA Bot Maker

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.

Getting Started

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://testbot.azurewebsites.net/qnamaker
Authorization: EndpointKey aa000344-9998-4d3b-9df3-52bf7c4f7ffd
Content-Type: application/json
{"question":"hi"}

The QnABotMaker library needs a few of these parameters in order to connect to the QnA Maker service.

  1. First we need to know your host value. This is the url provided with the host key. An example of this is the highlighted shown below.

Host: https://testbot.azurewebsites.net/qnamaker

  1. Next we need your knowledgebase identifier or knowledgebaseID, this is the highlighted shown below.

POST /knowledgebases/581bd885-5588403d-9935fe3cd325c503/generateAnswer

  1. The last configuration element we need is your endpoint key value, this is the highlighted shown below.

Authorization: EndpointKey aa000344-9998-4d3b-9df3-52bf7c4f7ffd

  1. Finally, you will use these parameters when creating an new instance of the QnAService struct as shown in the below example

let bot = QnAService(host: "https://testbot.azurewebsites.net/qnamaker", knowledgebaseID: "5581bd885-5588403d-9935fe3cd325c503", endpointKey: "aa000344-9998-4d3b-9df3-52bf7c4f7ffd")


Requirements

  • Xcode 9.1 or newer
  • Swift 4.1
  • iOS 10 or greater

Installation

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

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(host: "YOUR-HOST-URL", knowledgebaseID: "YOUR-KB-ID", endpointKey: "YOUR-ENDPOINT-KEY")

bot.askQuestion("hello", completionHandler: {(answers, error) in
    if let error = error {
        return print("error: \(error)")
    }
    if let answers = answers {
       print(answers)
    }
})

Author

Ben Bahrenburg, @bencoding

License

QnABotMaker is available under the MIT license. See the LICENSE file for more info.

Github

link
Stars: 1
Help us keep the lights on

Dependencies

Used By

Total: 0