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 Channel
- type Incoming
- type IncomingAttachment
- type IncomingAttachmentImage
- 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 RTMCurrentTeamService
- type RTMIncoming
- type RTMLoop
- type RTMLoopState
- type RTMMessage
- type RTMMessageType
- type RTMUserService
- type Team
- 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" )
const (
DEFAULT_RTM_API_BASE = "https://rtm.bearychat.com"
)
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
}
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 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()
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 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 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) IsFromMe ¶
func (m RTMMessage) IsFromMe(u User) bool
func (RTMMessage) IsP2P ¶
func (m RTMMessage) IsP2P() bool
func (RTMMessage) Reply ¶
func (m RTMMessage) Reply(text string) RTMMessage
Reply a message (with copying type, vchannel_id)
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 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
command
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
command
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. |