ubahn

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2019 License: MIT Imports: 3 Imported by: 0

README

Ubahn for Golang

Golang implementation of the conversation structuring framework Ubahn. See the whitepaper for generic information on Ubahn.

Build Status Build status Maintainability Go Report Card GoDoc

Installation and usage

The import path for the package is gopkg.in/ubahn/ubahn-go.v1.

To install it, run:

go get gopkg.in/ubahn/ubahn-go.v1

Example

Conversation definition in weather-report.yml:

version: 1

sequence:
  - welcome
  - weather-report

triggers:
  - i-user-welcome

fallback: clarification

outputs:
  welcome:
    expectedInputs:
      i-yes: next
      i-no: bye
    fallback: welcome-clarification

Business logic:

// inputFactory should be specific to your app and produce instances of ubahn.IInput.
// Of course you may produce them in a different way.
// Ubahn doesn’t provide input factory interface because it doesn’t want to assume input format.
inputFactory = NewInputFactory()

// outputFactory should implement ubahn.IOutputFactory
// interface and be specific to your app.
outputFactory = NewOutputFactory()

// This can be initialized once. Conversation object is stateless.
conversation := ubahn.NewConversation("weather-report.yml")

// For the sake of simplicity in this example we define user input as an array
// and just loop through it. Of course in your app you’ll receive it properly from
// real users.
userInputs := []string{"Hi", "Yes"}

// We store previous output, because conversation object is stateless.
// ubahn.BlankOutputName indicates the beginning of the conversation.
prevOutputName := ubahn.BlankOutputName

for i := 0; i < len(userInputs); i++ {
  input := inputFactory.Create(userInputs[i])
  outputName := conversation.Continue(prevOutputName, input)
  output := outputFactory.Create(outputName)
  output.Send()
  prevOutputName = outputName
}

Here’s a checklist of what you should implement on your app’s side in order to use Ubahn:

  • Definition of conversations in YAML format.
  • Something that produces instances of ubahn.IInput based on user input (like a factory).
  • Specific output factory that implements ubahn.IOutputFactory.
  • Specific outputs that implement ubahn.IOutput.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConversation

func NewConversation(conversationFilePath string) (core.IConversation, error)

NewConversation creates a new instance of a conversation, initialized from the given YAML file. If initialization filed, a null object is returned along with an error.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL