go-sarah: github.com/oklahomer/go-sarah/gitter Index | Files

package gitter

import "github.com/oklahomer/go-sarah/gitter"

Package gitter provides sarah.Adapter implementation for gitter.

Index

Package Files

adapter.go config.go connection.go doc.go payload.go rest.go streaming.go

Constants

const (
    // GITTER is a dedicated BotType for gitter implementation.
    GITTER sarah.BotType = "gitter"
)
const (
    // RestAPIEndpoint defines base url of gitter REST API.
    RestAPIEndpoint = "https://api.gitter.im/"
)
const (
    // StreamingAPIEndpointFormat defines basic url format of gitter streaming API.
    StreamingAPIEndpointFormat = "https://stream.gitter.im/%s/rooms/%s/chatMessages"
)
const (
    // TimeFormat defines gitter-styled timestamp format.
    // https://golang.org/pkg/time/#Time.Format
    TimeFormat = "2006-01-02T15:04:05.999Z"
)

Variables

var (
    // ErrEmptyPayload is an error that represents empty payload.
    ErrEmptyPayload = errors.New("empty payload was given")
)

func NewResponse Uses

func NewResponse(content string, options ...RespOption) (*sarah.CommandResponse, error)

NewResponse creates *sarah.CommandResponse with given arguments.

type APIClient Uses

type APIClient interface {
    Rooms(context.Context) (*Rooms, error)
    PostMessage(context.Context, *Room, string) (*Message, error)
}

APIClient is an interface that Rest API client must satisfy. This is mainly defined to ease tests.

type Adapter Uses

type Adapter struct {
    // contains filtered or unexported fields
}

Adapter stores REST/Streaming API clients' instances to let users interact with gitter.

func NewAdapter Uses

func NewAdapter(config *Config, options ...AdapterOption) (*Adapter, error)

NewAdapter creates and returns new Adapter instance.

func (*Adapter) BotType Uses

func (adapter *Adapter) BotType() sarah.BotType

BotType returns gitter designated BotType.

func (*Adapter) Run Uses

func (adapter *Adapter) Run(ctx context.Context, enqueueInput func(sarah.Input) error, notifyErr func(error))

Run fetches all belonging Room and connects to them.

func (*Adapter) SendMessage Uses

func (adapter *Adapter) SendMessage(ctx context.Context, output sarah.Output)

SendMessage let Bot send message to gitter.

type AdapterOption Uses

type AdapterOption func(adapter *Adapter)

AdapterOption defines function signature that Adapter's functional option must satisfy.

type Config Uses

type Config struct {
    Token       string        `json:"token" yaml:"token"`
    RetryPolicy *retry.Policy `json:"retry_policy" yaml:"retry_policy"`
}

Config contains some configuration variables for gitter Adapter.

func NewConfig Uses

func NewConfig() *Config

NewConfig returns initialized Config struct with default settings. Token is empty at this point. Token can be set by feeding this instance to json.Unmarshal/yaml.Unmarshal, or direct assignment.

type Connection Uses

type Connection interface {
    MessageReceiver
    io.Closer
}

Connection defines an interface that satisfies both MessageReceiver and io.Closer.

type Issue Uses

type Issue struct {
    Number uint `json:"number"`
}

Issue represents issue number mentioned in a message.

type MalformedPayloadError Uses

type MalformedPayloadError struct {
    Err string
}

MalformedPayloadError represents an error that given JSON payload is not properly formatted. e.g. required fields are not given, or payload is not a valid JSON string.

func NewMalformedPayloadError Uses

func NewMalformedPayloadError(str string) *MalformedPayloadError

NewMalformedPayloadError creates new MalformedPayloadError instance with given arguments.

func (*MalformedPayloadError) Error Uses

func (e *MalformedPayloadError) Error() string

Error returns its error string.

type Mention Uses

type Mention struct {
    ScreenName string `json:"screenName"`
    UserID     string `json:"userId"`
}

Mention represents mention in the message.

type Message Uses

type Message struct {
    ID            string    `json:"id"`
    Text          string    `json:"text"`
    HTML          string    `json:"html"`
    SendTimeStamp TimeStamp `json:"sent"`
    EditTimeStamp TimeStamp `json:"editedAt"`
    FromUser      User      `json:"fromUser"`
    Unread        bool      `json:"unread"`
    ReadBy        uint      `json:"readBy"`
    URLs          []string  `json:"urls"`
    Mentions      []Mention `json:"mentions"`
    Issues        []Issue   `json:"issues"`
    Meta          []Meta    `json:"meta"` // Reserved, but not in use
    Version       uint      `json:"v"`
}

Message represents gitter message resource. https://developer.gitter.im/docs/messages-resource

type MessageReceiver Uses

type MessageReceiver interface {
    Receive() (*RoomMessage, error)
}

MessageReceiver defines an interface that receives RoomMessage.

type Meta Uses

type Meta struct {
}

Meta is reserved, but is not used so far. https://developer.gitter.im/docs/messages-resource

type PostingMessage Uses

type PostingMessage struct {
    Text string `json:"text"`
}

PostingMessage represents the sending message. This can be marshaled and sent as JSON-styled payload.

type RespOption Uses

type RespOption func(*respOptions)

RespOption defines function signature that NewResponse's functional option must satisfy.

func RespWithNext Uses

func RespWithNext(fnc sarah.ContextualFunc) RespOption

RespWithNext sets given fnc as part of the response's *sarah.UserContext. The next input from the same user will be passed to this fnc. See sarah.UserContextStorage must be present or otherwise, fnc will be ignored.

func RespWithNextSerializable Uses

func RespWithNextSerializable(arg *sarah.SerializableArgument) RespOption

RespWithNextSerializable sets given arg as part of the response's *sarah.UserContext. The next input from the same user will be passed to the function defined in the arg. See sarah.UserContextStorage must be present or otherwise, arg will be ignored.

type RestAPIClient Uses

type RestAPIClient struct {
    // contains filtered or unexported fields
}

RestAPIClient utilizes gitter REST API.

func NewRestAPIClient Uses

func NewRestAPIClient(token string) *RestAPIClient

NewRestAPIClient creates and returns API client instance. Version is fixed to v1.

func NewVersionSpecificRestAPIClient Uses

func NewVersionSpecificRestAPIClient(token string, apiVersion string) *RestAPIClient

NewVersionSpecificRestAPIClient creates API client instance with given API version.

func (*RestAPIClient) Get Uses

func (client *RestAPIClient) Get(ctx context.Context, resourceFragments []string, intf interface{}) error

Get sends GET request with given path and parameters.

func (*RestAPIClient) Post Uses

func (client *RestAPIClient) Post(ctx context.Context, resourceFragments []string, sendingPayload interface{}, responsePayload interface{}) error

Post sends POST requests to gitter with given parameters.

func (*RestAPIClient) PostMessage Uses

func (client *RestAPIClient) PostMessage(ctx context.Context, room *Room, text string) (*Message, error)

PostMessage sends message to gitter.

func (*RestAPIClient) Rooms Uses

func (client *RestAPIClient) Rooms(ctx context.Context) (*Rooms, error)

Rooms fetches belonging rooms information.

type Room Uses

type Room struct {
    ID             string    `json:"id"`
    Name           string    `json:"name"`
    Topic          string    `json:"topic"`
    URI            string    `json:"uri"`
    OneToOne       bool      `json:"oneToOne"`
    Users          []*User   `json:"users"`
    UnreadItems    uint      `json:"unreadItems"`
    Mentions       uint      `json:"mentions"`
    LastAccessTime TimeStamp `json:"lastAccessTime"`
    Favourite      uint      `json:"favourite"`
    Lurk           bool      `json:"lurk"`
    URL            string    `json:"url"`        // path
    GitHubType     string    `json:"githubType"` // TODO type
    Tags           []string  `json:"tags"`
    Version        uint      `json:"v"`
}

Room represents gitter room resource. https://developer.gitter.im/docs/rooms-resource

type RoomMessage Uses

type RoomMessage struct {
    Room            *Room
    ReceivedMessage *Message
}

RoomMessage stashes received Message and additional Room information.

func NewRoomMessage Uses

func NewRoomMessage(room *Room, message *Message) *RoomMessage

NewRoomMessage creates and returns new RoomMessage instance.

func (*RoomMessage) Message Uses

func (message *RoomMessage) Message() string

Message returns received text.

func (*RoomMessage) ReplyTo Uses

func (message *RoomMessage) ReplyTo() sarah.OutputDestination

ReplyTo returns Room that message was being delivered.

func (*RoomMessage) SenderKey Uses

func (message *RoomMessage) SenderKey() string

SenderKey returns message sending user's ID.

func (*RoomMessage) SentAt Uses

func (message *RoomMessage) SentAt() time.Time

SentAt returns when the message is sent.

type Rooms Uses

type Rooms []*Room

Rooms is a group of Room

type RoomsFetcher Uses

type RoomsFetcher interface {
    Rooms(context.Context) (*Rooms, error)
}

RoomsFetcher defines interface that fetch gitter rooms.

type StreamConnector Uses

type StreamConnector interface {
    Connect(context.Context, *Room) (Connection, error)
}

StreamConnector defines an interface that connects to given gitter room

type StreamingAPIClient Uses

type StreamingAPIClient struct {
    // contains filtered or unexported fields
}

StreamingAPIClient utilizes gitter streaming API.

func NewStreamingAPIClient Uses

func NewStreamingAPIClient(token string) *StreamingAPIClient

NewStreamingAPIClient creates and returns API client instance. API version is fixed to v1.

func NewVersionSpecificStreamingAPIClient Uses

func NewVersionSpecificStreamingAPIClient(apiVersion string, token string) *StreamingAPIClient

NewVersionSpecificStreamingAPIClient creates and returns API client instance.

func (*StreamingAPIClient) Connect Uses

func (client *StreamingAPIClient) Connect(ctx context.Context, room *Room) (Connection, error)

Connect initiates request to streaming API and returns established connection.

type StreamingClient Uses

type StreamingClient interface {
    Connect(context.Context, *Room) (Connection, error)
}

StreamingClient is an interface that HTTP Streaming client must satisfy. This is mainly defined to ease tests.

type TimeStamp Uses

type TimeStamp struct {
    Time          time.Time
    OriginalValue string // e.g. "2014-03-24T15:41:18.991Z"
}

TimeStamp represents gitter timestamp.

func (*TimeStamp) MarshalText Uses

func (timeStamp *TimeStamp) MarshalText() ([]byte, error)

MarshalText marshals TimeStamp to gitter-styled one.

func (*TimeStamp) String Uses

func (timeStamp *TimeStamp) String() string

String returns original gitter-styled timestamp value.

func (*TimeStamp) UnmarshalText Uses

func (timeStamp *TimeStamp) UnmarshalText(b []byte) error

UnmarshalText unmarshals given gitter-styled timestamp to TimeStamp

type User Uses

type User struct {
    ID              string `json:"id"`
    UserName        string `json:"username"`
    DisplayName     string `json:"displayName"`
    URL             string `json:"url"` // path
    AvatarURLSmall  string `json:"avatarUrlSmall"`
    AvatarURLMedium string `json:"avatarUrlMedium"`
}

User represents gitter user resource. https://developer.gitter.im/docs/user-resource

Package gitter imports 15 packages (graph). Updated 2020-09-26. Refresh now. Tools for package owners.