Git Product home page Git Product logo

goflow's Introduction

Goflow Build Status codecov Go Report Card

Specification

See https://nyaruka.github.io/goflow/ for the complete specification docs.

Basic Usage

import (
    "github.com/nyaruka/goflow/assets/static"
    "github.com/nyaruka/goflow/flows"
    "github.com/nyaruka/goflow/flows/engine"
    "github.com/nyaruka/goflow/utils"
)

source, _ := static.LoadSource("myassets.json")
assets, _ := engine.NewSessionAssets(source, nil)
contact := flows.NewContact(assets, ...)
env := envs.NewBuilder().Build()
trigger := triggers.NewManual(env, contact, flow.Reference(), nil, nil, time.Now())
eng := engine.NewBuilder().Build()
session, sprint, err := eng.NewSession(assets, trigger)

Sessions

Sessions can easily be persisted between waits by calling json.Marshal on the Session instance to marshal it as JSON. You can inspect this JSON at https://sessions.temba.io/.

Utilities

Flow Runner

Provides a command line interface for stepping through a given flow.

% go install github.com/nyaruka/goflow/cmd/flowrunner
% $GOPATH/bin/flowrunner test/testdata/runner/two_questions.json 615b8a0f-588c-4d20-a05f-363b0b4ce6f4
Starting flow 'U-Report Registration Flow'....
---------------------------------------
๐Ÿ’ฌ "Hi Ben Haggerty! What is your favorite color? (red/blue) Your number is (206) 555-1212"
โณ waiting for message....

By default it will use a manual trigger to create a session, but the -msg flag can be used to start the session with a message trigger:

% $GOPATH/bin/flowrunner -msg "hi there" cmd/flowrunner/testdata/two_questions.json 615b8a0f-588c-4d20-a05f-363b0b4ce6f4

If the -repro flag is set, it will dump the triggers and resumes it used which can be used to reproduce the session in a test:

% $GOPATH/bin/flowrunner -repro cmd/flowrunner/testdata/two_questions.json 615b8a0f-588c-4d20-a05f-363b0b4ce6f4

Flow Migrator

Takes a legacy flow definition as piped input and outputs the migrated definition:

% go install github.com/nyaruka/goflow/cmd/flowmigrate
% cat legacy_flow.json | $GOPATH/bin/flowmigrate
% cat legacy_export.json | jq '.flows[0]' | $GOPATH/bin/flowmigrate

Expression Tester

Provides a quick way to test evaluation of expressions which can be used in flows:

% go install github.com/nyaruka/goflow/cmd/exptester
% $GOPATH/bin/exptester '@(10 / 5 >= 2)'
% $GOPATH/bin/exptester '@(TITLE("foo"))'

Development

You can run all the tests with:

% go test github.com/nyaruka/goflow/...

If you've made changes to the flow engine output, regenerate the test files with:

% go test github.com/nyaruka/goflow/test -write

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.