emitable

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2018 License: MIT Imports: 0 Imported by: 8

README

FSM

Emitable

Emitable contains all of the types that all FSM targets are expected to implement in their Emitter.

What Are These?

An Emitter is responsible for sending messages to the user interacting with your conversational interface.

All FSM targets implement a unique Emitter to handle how to send messages to the users for their specific platform.

Emitables are the officially supported definitions of data that can be sent to an Emitter. There's a promise that all FSM targets will handle the interfaces provided in this repository (as long as it makes sense within the context of the target).

In the event that an emitable does not make sense, the target will degrade gracefully in handling it. For example, fsm/alexa does not handle typing, but it degrades gracefully by doing nothing.

Usage

You're going to use these emitables as parameters to the Emitter.Emit function.

Following the philosophies of FSM, Emit should only be called in the EntryAction of a BuildState.

package states

import (
	"github.com/fsm/emitable"
	"github.com/fsm/fsm"
)

func GetSampleState(emitter fsm.Emitter, traverser fsm.Traverser) *fsm.State {
	return &fsm.State{
		EntryAction: func() error {
			emitter.Emit(emitable.Image{URL: "https://i.imgur.com/apvk5n0.gif"})

			emitter.Emit(emitable.Typing{Enabled: true})
			emitter.Emit("Greetings traveler, welcome to my shop!")

			emitter.Emit(emitable.Typing{Enabled: true})
			emitter.Emit("Looks like you want to buy some potions.")

			emitter.Emit(emitable.QuickReply{
				Message:       "How many would you like to buy?",
				RepliesFormat: "I sell in quantities of %v",
				Replies:       []string{"1", "5", "10"},
			})
			return nil
		},
		// ...
	}
}

License

MIT

Documentation

Overview

Package emitable defines all of the types that are recommended for all fsm chatbot targets to implement in their emitter.

All emitters should also handle strings, in addition to what is defined here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Audio

type Audio struct {
	URL string
}

Audio is a struct that represents an audio file to be emitted

type File

type File struct {
	URL string
}

File is a struct that represents a generic file to be emitted

type Image

type Image struct {
	URL string
}

Image is a struct that represents an image to be emitted

type QuickReply

type QuickReply struct {
	Message       string
	Replies       []string
	RepliesFormat string
}

QuickReply is a struct that represents an array of possible responses from a user

type Sleep

type Sleep struct {
	LengthMillis int
}

Sleep is a struct to represent that the bot should pause for some length of time.

type Typing

type Typing struct {
	Enabled bool
}

Typing is a struct to represent that the bot is typing. It is expected to be enabled and disabled

type Video

type Video struct {
	URL string
}

Video is a struct that represents an video to be emitted

Jump to

Keyboard shortcuts

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