Latest 1.0-alpha.2
Homepage https://github.com/gonzalezreal/DirectLine
License MIT
Platforms ios 8.0, osx 10.10, tvos 9.0
Dependencies RxSwift, Starscream
Frameworks Foundation
Authors

CocoaPods
Carthage Compatible
Platforms
Twitter: @gonzalezreal

DirectLine is a client library for the Microsoft Bot Framework Direct Line protocol.

Loosely based on the official Javascript DirectLine client, it enables communication between your bot and your iOS app using a simple ReactiveX based interface.

Examples

To create a DirectLine object, you must provide either the secret for your bot or a temporary token obtained via the Generate Token API:

import DirectLine

let directLine = DirectLine(token: "f1STR0.p3c4D0r") 

The DirectLine object manages token renewal and web socket connection under the hood, so you don’t have to worry about them.

Post activities to the bot:

let myAccount = ChannelAccount(id: "myUserID", name: "Guille")

directLine
  .post(activity: Activity(from: myAccount, text: "What is my current balance?"))
  .subscribe(
    onNext: { print("Posted activity, assigned ID (($0.id)") },
    onError: { print("Error posting activity ($0)") }
  )

Listen to activities sent and received from the bot:

directLine.activities
  .subscribe(onNext: { activity in
    print("Received activity (activity)")
  })

You can leverage Rx operators on the incoming activities. For instance, to see only message activities:

directLine.activities
  .filter { $0.type == .message }
  .subscribe(onNext: { activity in
    print("Received message (activity)")
  })

The activities stream includes those sent to the bot, so a typical pattern is to filter them out using the from property:

directLine.activities
  .filter { $0.type == .message  && $0.from.id == "yourBotHandle" }
  .subscribe(onNext: { activity in
    print("Received message from the bot (activity)")
  })

Installation

Using CocoaPods

Add pod DirectLine to your Podfile

Using Carthage

Add git "gonzalezreal/DirectLine" to your Cartfile

Using the Swift Package Manager

Add Package(url: "https://github.com/gonzalezreal/DirectLine.git", majorVersion: 1) to your Package.swift file.

Help & Feedback

  • Open an issue if you need help, if you found a bug, or if you want to discuss a feature request.
  • Open a PR if you want to make some change to DirectLine.
  • Contact @gonzalezreal on Twitter.

Latest podspec

{
    "name": "DirectLine",
    "version": "1.0-alpha.2",
    "summary": "Swift client library for Microsoft Bot Framework's Direct Line protocol",
    "description": "Loosely based on the official Javascript DirectLine client, it enables communicationnbetween your bot and your iOS app using a simple ReactiveX based interface.",
    "homepage": "https://github.com/gonzalezreal/DirectLine",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Guille Gonzalez": "[email protected]"
    },
    "social_media_url": "https://twitter.com/gonzalezreal",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/gonzalezreal/DirectLine.git",
        "tag": "1.0-alpha.2"
    },
    "source_files": "Sources/**/*",
    "frameworks": "Foundation",
    "dependencies": {
        "RxSwift": [
            "4.0.0-alpha.1"
        ],
        "Starscream": [
            "2.1.1"
        ]
    },
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This