Documentation ¶
Index ¶
- Constants
- Variables
- func NewIncomingWebhookClient(webhook string) *webhookClient
- func NewRTMLoop(wsHost string, setters ...rtmLoopSetter) (*rtmLoop, error)
- func WithRTMAPIBase(apiBase string) rtmOptSetter
- func WithRTMHTTPClient(httpClient *http.Client) rtmOptSetter
- func WithRTMLoopBacklog(backlog int) rtmLoopSetter
- type AttachedFile
- type Channel
- type Incoming
- type IncomingAttachment
- type IncomingAttachmentImage
- type MessageFile
- type RTMAPIResponse
- type RTMChannelService
- type RTMClient
- func (c RTMClient) Do(resource, method string, in, result interface{}) (*http.Response, error)
- func (c RTMClient) Get(resource string, result interface{}) (*http.Response, error)
- func (c RTMClient) Incoming(m RTMIncoming) error
- func (c RTMClient) Post(resource string, in, result interface{}) (*http.Response, error)
- func (c RTMClient) Start() (*User, string, error)
- type RTMContext
- type RTMCurrentTeamService
- type RTMIncoming
- type RTMLoop
- type RTMLoopState
- type RTMMessage
- func (m RTMMessage) IsChatMessage() bool
- func (m RTMMessage) IsFromUID(uid string) bool
- func (m RTMMessage) IsFromUser(u User) bool
- func (m RTMMessage) IsP2P() bool
- func (m RTMMessage) ParseAttachedFile() (file AttachedFile, err error)
- func (m RTMMessage) ParseMentionUID(uid string) (bool, string)
- func (m RTMMessage) ParseMentionUser(u User) (bool, string)
- func (m RTMMessage) Refer(text string) RTMMessage
- func (m RTMMessage) Reply(text string) RTMMessage
- func (m RTMMessage) Text() string
- func (m RTMMessage) Type() RTMMessageType
- type RTMMessageType
- type RTMUserService
- type Team
- type UpdateAttachments
- type User
- type WebhookClient
- type WebhookResponse
Examples ¶
Constants ¶
const ( UserRoleOwner = "owner" UserRoleAdmin = "admin" UserRoleNormal = "normal" UserRoleVisitor = "visitor" )
const ( UserTypeNormal = "normal" UserTypeAssistant = "assistant" UserTypeHubot = "hubot" )
const ( RTMMessageTypeUnknown RTMMessageType = "unknown" RTMMessageTypePing = "ping" RTMMessageTypePong = "pong" RTMMessageTypeReply = "reply" RTMMessageTypeOk = "ok" RTMMessageTypeP2PMessage = "message" RTMMessageTypeP2PTyping = "typing" RTMMessageTypeChannelMessage = "channel_message" RTMMessageTypeChannelTyping = "channel_typing" RTMMessageTypeUpdateUserConnection = "update_user_connection" RTMMessageTypeUpdateAttachments = "update_attachments" )
const (
DEFAULT_RTM_API_BASE = "https://rtm.bearychat.com"
)
const JSONRawTag = "go_json_raw_message"
JSONRawTag key for raw message
Variables ¶
var (
ErrRTMLoopClosed = errors.New("rtm loop is closed")
)
Functions ¶
func NewIncomingWebhookClient ¶
func NewIncomingWebhookClient(webhook string) *webhookClient
Creates a new incoming webhook client.
For full documentation, visit https://bearychat.com/integrations/incoming .
Example ¶
m := Incoming{Text: "Hello, BearyChat"} payload, _ := m.Build() resp, _ := NewIncomingWebhookClient("YOUR WEBHOOK URL").Send(payload) if resp.IsOk() { // parse resp result } else { // parse resp error }
Output:
func NewRTMLoop ¶
func WithRTMAPIBase ¶
func WithRTMAPIBase(apiBase string) rtmOptSetter
WithRTMAPIBase can be used to set rtm client's base api.
func WithRTMHTTPClient ¶
WithRTMHTTPClient sets http client.
func WithRTMLoopBacklog ¶
func WithRTMLoopBacklog(backlog int) rtmLoopSetter
Set RTM message chan backlog.
Types ¶
type AttachedFile ¶
type AttachedFile struct { Category string `json:"category"` Created string `json:"created"` Deleted bool `json:"deleted"` Description string `json:"description"` Height int `json:"height"` ID string `json:"id"` // image URL ImageURL string `json:"image_url"` Inactive bool `json:"inactive"` IsPublic bool `json:"is_public"` Key string `json:"key"` // File MIME MIME string `json:"mime"` Name string `json:"name"` Orientation int `json:"orientation"` Original bool `json:"original"` // preview URL PreviewURL string `json:"preview_url"` // File Size in byte Size int `json:"size"` Source string `json:"source"` TeamID string `json:"team_id"` Title string `json:"title"` Type string `json:"type"` UID string `json:"uid"` Updated string `json:"updated"` UploadZone string `json:"upload_zone"` URL string `json:"url"` Width int `json:"width"` }
AttachedFile RTM struct in Attachments
type Channel ¶
type Channel struct { Id string `json:"id"` TeamId string `json:"team_id"` UserId string `json:"uid"` VChannelId string `json:"vchannel_id"` Name string `json:"name"` IsPrivate bool `json:"private"` IsGeneral bool `json:"general"` Topic string `json:"topic"` CreatedAt string `json:"created"` // TODO parse date UpdatedAt string `json:"updated"` // TODO parse date }
Channel information.
type Incoming ¶
type Incoming struct { Text string `json:"text"` Notification string `json:"notification,omitempty"` Markdown bool `json:"markdown,omitempty"` Channel string `json:"channel,omitempty"` User string `json:"user,omitempty"` Attachments []IncomingAttachment `json:"attachments,omitempty"` }
Incoming message builder.
m := Incoming{ Text: "Hello, **BearyChat**", Markdown: true, Notification: "Hello, BearyChat in Notification", } output, _ := m.Build() http.Post("YOUR INCOMING HOOK URI HERE", "application/json", output)
For full documentation, visit https://bearychat.com/integrations/incoming .
Example ¶
m := Incoming{ Text: "Hello, **BearyChat", Notification: "Hello, BearyChat in notification", Markdown: true, Channel: "#所有人", User: "@bearybot", Attachments: []IncomingAttachment{ {Text: "attachment 1", Color: "#cb3f20"}, {Title: "attachment 2", Color: "#ffa500"}, { Text: "愿原力与你同在", Images: []IncomingAttachmentImage{ {URL: "http://img3.douban.com/icon/ul15067564-30.jpg"}, }, }, }, } m.Build()
Output:
type IncomingAttachment ¶
type IncomingAttachment struct { Title string `json:"title,omitempty"` Text string `json:"text,omitempty"` Color string `json:"color,omitempty"` Images []IncomingAttachmentImage `json:"images,omitempty"` }
IncomingAttachment contains incoming attachment fields.
type IncomingAttachmentImage ¶
type IncomingAttachmentImage struct {
URL string `json:"url"`
}
IncomingAttachmentImage contains attachment image fields.
func (IncomingAttachmentImage) Validate ¶
func (i IncomingAttachmentImage) Validate() error
Validate fields.
type MessageFile ¶
type MessageFile struct {
File *AttachedFile `json:"file"`
}
type RTMAPIResponse ¶
type RTMAPIResponse struct { Code int `json:"code"` Result json.RawMessage `json:"result,omitempty"` ErrorReason string `json:"error,omitempty"` }
RTM api request response
func (*RTMAPIResponse) Error ¶
func (r *RTMAPIResponse) Error() string
type RTMChannelService ¶
type RTMChannelService struct {
// contains filtered or unexported fields
}
type RTMClient ¶
type RTMClient struct { // rtm token Token string // rtm api base, defaults to `https://rtm.bearychat.com` APIBase string // services CurrentTeam *RTMCurrentTeamService User *RTMUserService Channel *RTMChannelService // contains filtered or unexported fields }
RTMClient is used to interactive with BearyChat's RTM api and websocket message protocol.
func NewRTMClient ¶
NewRTMClient creates a rtm client.
client, _ := NewRTMClient( "rtm-token", WithRTMAPIBase("https://rtm.bearychat.com"), )
func (RTMClient) Incoming ¶
func (c RTMClient) Incoming(m RTMIncoming) error
Incoming performs rtm.message
type RTMContext ¶
type RTMContext struct { Loop RTMLoop // contains filtered or unexported fields }
func NewRTMContext ¶
func NewRTMContext(token string) (*RTMContext, error)
func (*RTMContext) Run ¶
func (c *RTMContext) Run() (error, chan RTMMessage, chan error)
func (*RTMContext) UID ¶
func (c *RTMContext) UID() string
type RTMCurrentTeamService ¶
type RTMCurrentTeamService struct {
// contains filtered or unexported fields
}
func (*RTMCurrentTeamService) Channels ¶
func (s *RTMCurrentTeamService) Channels() ([]*Channel, error)
Retrieves current team's channels.
func (*RTMCurrentTeamService) Info ¶
func (s *RTMCurrentTeamService) Info() (*Team, error)
Retrieves current team's information.
func (*RTMCurrentTeamService) Members ¶
func (s *RTMCurrentTeamService) Members() ([]*User, error)
Retrieves current team's members.
type RTMIncoming ¶
type RTMIncoming struct { Text string `json:"text"` VChannelId string `json:"vchannel"` Markdown bool `json:"markdown,omitempty"` Attachments []IncomingAttachment `json:"attachments,omitempty"` }
RTMIncoming represents message sent vai `rtm.message` api
type RTMLoop ¶
type RTMLoop interface { // Connect to RTM, returns after connected Start() error // Stop the connection Stop() error // Get current state State() RTMLoopState // Send a ping message Ping() error // Keep connection alive. Closes ticker before return Keepalive(interval *time.Ticker) error // Send a message Send(m RTMMessage) error // Get message receiving channel ReadC() (chan RTMMessage, error) // Get error channel ErrC() chan error }
RTMLoop is used to interactive with BearyChat's RTM websocket message protocol.
type RTMLoopState ¶
type RTMLoopState string
const ( RTMLoopStateClosed RTMLoopState = "closed" RTMLoopStateOpen = "open" )
type RTMMessage ¶
type RTMMessage map[string]interface{}
RTMMessage represents a message entity send over RTM protocol.
func (RTMMessage) IsChatMessage ¶
func (m RTMMessage) IsChatMessage() bool
func (RTMMessage) IsFromUID ¶
func (m RTMMessage) IsFromUID(uid string) bool
func (RTMMessage) IsFromUser ¶
func (m RTMMessage) IsFromUser(u User) bool
func (RTMMessage) IsP2P ¶
func (m RTMMessage) IsP2P() bool
func (RTMMessage) ParseAttachedFile ¶
func (m RTMMessage) ParseAttachedFile() (file AttachedFile, err error)
ParseReferImageURL tries to get first attached file
func (RTMMessage) ParseMentionUID ¶
func (m RTMMessage) ParseMentionUID(uid string) (bool, string)
func (RTMMessage) ParseMentionUser ¶
func (m RTMMessage) ParseMentionUser(u User) (bool, string)
func (RTMMessage) Reply ¶
func (m RTMMessage) Reply(text string) RTMMessage
Reply a message (with copying type, vchannel_id)
func (RTMMessage) Text ¶
func (m RTMMessage) Text() string
func (RTMMessage) Type ¶
func (m RTMMessage) Type() RTMMessageType
type RTMMessageType ¶
type RTMMessageType string
type RTMUserService ¶
type RTMUserService struct {
// contains filtered or unexported fields
}
type Team ¶
type Team struct { Id string `json:"id"` Subdomain string `json:"subdomain"` Name string `json:"name"` UserId string `json:"uid"` Description string `json:"description"` EmailDomain string `json:"email_domain"` Inactive bool `json:"inactive"` CreatedAt string `json:"created"` // TODO parse date UpdatedAt string `json:"updated"` // TODO parse date }
Team information
type UpdateAttachments ¶
type UpdateAttachments struct { // very odd data structure... Data struct { Attachments []struct { File *AttachedFile `json:"file"` ReferText string `json:"refer_text"` ReferTextI18N struct { En string `json:"en"` Zh string `json:"zh-CN"` } `json:"refer_text_i18n"` Subtype string `json:"subtype"` Text string `json:"text"` Type string `json:"type"` UID string `json:"uid"` } `json:"attachments"` Created string `json:"created"` CreatedTs int64 `json:"created_ts"` DisableMarkdown bool `json:"disable_markdown"` Edited bool `json:"edited"` ID string `json:"id"` IsChannel bool `json:"is_channel"` Key string `json:"key"` ReferKey string `json:"refer_key"` Subtype string `json:"subtype"` TeamID string `json:"team_id"` Text string `json:"text"` UID string `json:"uid"` Updated string `json:"updated"` VChannelID string `json:"vchannel_id"` } `json:"data"` Ts int64 `json:"ts"` Type string `json:"type"` }
UpdateAttachments RTM msg UpdateAttachments
type User ¶
type User struct { Id string `json:"id"` TeamId string `json:"team_id"` VChannelId string `json:"vchannel_id"` Name string `json:"name"` FullName string `json:"full_name"` Email string `json:"email"` AvatarUrl string `json:"avatar_url"` Role string `json:"role"` Type string `json:"type"` Conn string `json:"conn"` CreatedAt string `json:"created"` // TODO parse date UpdatedAt string `json:"updated"` // TODO parse date }
User information
type WebhookClient ¶
type WebhookClient interface { // Set webhook webhook. SetWebhook(webhook string) WebhookClient // Set http client. SetHTTPClient(client *http.Client) WebhookClient // Send webhook payload. Send(payload io.Reader) (*WebhookResponse, error) }
WebhookClient represents any webhook client can send message to BearyChat.
type WebhookResponse ¶
type WebhookResponse struct { StatusCode int `json:"-"` Code int `json:"code"` Error string `json:"error,omitempty"` Result *json.RawMessage `json:"result"` }
WebhookResponse represents a response.
func (WebhookResponse) IsOk ¶
func (w WebhookResponse) IsOk() bool
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example
|
|
chaosmonkey
Chaos Monkey will talk to you randomly 🙊 Envvars: - `CM_RTM_TOKEN`: BearyChat RTM token - `CM_VICTIMS`: user ids who will be talk with, separates with comma: `=bw52O,=bw52P`
|
Chaos Monkey will talk to you randomly 🙊 Envvars: - `CM_RTM_TOKEN`: BearyChat RTM token - `CM_VICTIMS`: user ids who will be talk with, separates with comma: `=bw52O,=bw52P` |
rtm
Demo bot built with BearyChat RTM ./rtm -rtmToken <your-BearyChat-RTM-token-here>
|
Demo bot built with BearyChat RTM ./rtm -rtmToken <your-BearyChat-RTM-token-here> |
Package openapi implements BearyChat's OpenAPI methods.
|
Package openapi implements BearyChat's OpenAPI methods. |