github.com/annwntech/go-micro/v2@v2.9.5/agent/input/input.go (about) 1 // Package input is an interface for bot inputs 2 package input 3 4 import ( 5 "github.com/micro/cli/v2" 6 ) 7 8 type EventType string 9 10 const ( 11 TextEvent EventType = "text" 12 ) 13 14 var ( 15 // Inputs keyed by name 16 // Example slack or hipchat 17 Inputs = map[string]Input{} 18 ) 19 20 // Event is the unit sent and received 21 type Event struct { 22 Type EventType 23 From string 24 To string 25 Data []byte 26 Meta map[string]interface{} 27 } 28 29 // Input is an interface for sources which 30 // provide a way to communicate with the bot. 31 // Slack, HipChat, XMPP, etc. 32 type Input interface { 33 // Provide cli flags 34 Flags() []cli.Flag 35 // Initialise input using cli context 36 Init(*cli.Context) error 37 // Stream events from the input 38 Stream() (Conn, error) 39 // Start the input 40 Start() error 41 // Stop the input 42 Stop() error 43 // name of the input 44 String() string 45 } 46 47 // Conn interface provides a way to 48 // send and receive events. Send and 49 // Recv both block until succeeding 50 // or failing. 51 type Conn interface { 52 Close() error 53 Recv(*Event) error 54 Send(*Event) error 55 }