Skip to content

Latest commit

 

History

History
46 lines (41 loc) · 1.53 KB

README.md

File metadata and controls

46 lines (41 loc) · 1.53 KB

Build Status

BarnaBot

A local bot written in Swift for awesome user interactions!
Inspired by the Microsoft Bot Framework

Simple declaration

    var botBuilder = BBBuilder("Barnabot")
    var botSession = BBSession.sharedInstance
    botSession.delegate = self

    botBuilder
        .dialog(path: "/", [{(session : BBSession) -> Void in
            if let name = session.getUserData("name") {
                session.next()
            } else {
                session.beginDialog("/profile")
            }
        },
        {(session : BBSession) -> Void in
            if let name = session.getUserData("name") {
                session.send("Hello \(name)!")
            }
            session.endDialog()
        }])
        .dialog(path "/profile", [{(session : BBSession) -> Void in
            session.promptText("What's your name?")
        },{(session : BBSession) -> Void in
            session.saveUserData(value: session.result, forKey: "name").endDialog()
        }])

    botSession.beginConversation()

Intents support

  botBuilder
    .matches("^help$", priority: 0, redir: "/help")
    .matches("^bonjour", priority: 0, [{(session : BBSession) -> Void in
      session.send("I'm glad to see u back")
      session.promptText("How are you today?")
    },{(session : BBSession) -> Void in
      session.saveUserData(value: session.result, forKey: "mood").endDialog()
    }])