Skip to content

fsm/emitable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

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