Documentation ¶
Overview ¶
Ninchat API connection library.
Index ¶
- Variables
- type Action
- type Caller
- type Event
- func (e *Event) Array(param string) (v []interface{}, ok bool)
- func (e *Event) Bool(param string) (v bool)
- func (e *Event) Float64(param string) (v float64, ok bool)
- func (e *Event) Int(param string) (v int, ok bool)
- func (e *Event) Int64(param string) (v int64, ok bool)
- func (e *Event) Map(param string) (v map[string]interface{}, ok bool)
- func (e *Event) Str(param string) (v string, ok bool)
- func (e *Event) String() (s string)
- type Frame
- type Session
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { Params map[string]interface{} Payload []Frame OnReply func(*Event) // contains filtered or unexported fields }
Action
type Caller ¶
type Caller struct { // Header fields to be added to HTTP requests. The keys must be in // canonical format (see https://golang.org/pkg/net/http/#CanonicalHeaderKey). Header map[string][]string Address string }
type Event ¶
Event
func Call ¶
Call the sessionless API.
If the action's OnReply callback is set, it will be called with the result events, unless an error occurs.
func (*Event) Bool ¶
Bool looks up a boolean parameter. A boolean parameter is considered false when it is nil or not set.
type Session ¶
type Session struct { // OnSessionEvent is the session creation handler. It will be invoked with // a "session_created" or an "error" event. // // If another "session_created" event is received, it means that the previous // session was lost, and a new one was established automatically. // // If an "error" event is received, it means that a new session can't be // established without intervention. The client code must call SetParams to // supply new credentials, unless it decides to Close. // OnSessionEvent func(*Event) // OnEvent is the handler for in-session events. // // "error" events received via this callback are not fatal. // OnEvent func(*Event) // OnClose is an optional session closure handler. It will be invoked // after a Close call has been fully processed. It won't be invoked if an // "error" event is received via OnSessionEvent (unless SetParams is called // again). // OnClose func() // OnConnState is an optional connection state change monitor. It will be // called with one of the following strings: // // - "connecting" // - "connected" // - "disconnected" // OnConnState func(state string) // OnConnActive is an optional connection activity monitor. It will be // called (approximately) when data is received on the underlying network // connection. OnConnActive func() // OnLog is an optional message logger. OnLog func(fragments ...interface{}) // Header fields to be added to HTTP requests. The keys must be in // canonical format (see https://golang.org/pkg/net/http/#CanonicalHeaderKey). Header map[string][]string Address string DisableLongPoll bool // contains filtered or unexported fields }
Session hides the details of API connection management. It needs to be initialized by setting at least OnSessionEvent and OnEvent, and calling SetParams. After that the Open method is used to make a connection to the server. Finally, the Close method disconnects from the server.
func (*Session) Send ¶
Send an action.
To send an action without an "action_id" parameter, specify it as nil. Otherwise an "action_id" is generated automatically.
If "action_id" is used and the action's OnReply callback is set, it will be called when a reply event is received. If the Session object is closed before a reply is received, OnReply will be called with a nil argument.
With specific actions that cause multiple reply events, the OnReply callback will be called for each event until the final event. Only the last event will have the LastReply member set.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Wrappers for Ninchat API actions, events and attributes.
|
Wrappers for Ninchat API actions, events and attributes. |
Standard Ninchat message data structures.
|
Standard Ninchat message data structures. |
See https://github.com/ninchat/ninchat-go/blob/master/webhook/example/processor.go for an example.
|
See https://github.com/ninchat/ninchat-go/blob/master/webhook/example/processor.go for an example. |