Documentation ¶
Overview ¶
Package slack is used to connect to the slack network. Slack is a code-centric collaboration hub that allows users to connect via an app and share different types of data
Index ¶
- Constants
- type Message
- type PresenceChange
- type Response
- type SendMessage
- type Slack
- func (s *Slack) BuildURL(token string) string
- func (s *Slack) Connect() error
- func (s *Slack) GetChannelIDByName(channel string) (string, error)
- func (s *Slack) GetChannelsString() []string
- func (s *Slack) GetGroupIDByName(group string) (string, error)
- func (s *Slack) GetIDByName(userName string) (string, error)
- func (s *Slack) GetUsernameByID(id string) string
- func (s *Slack) GetUsersInGroup(group string) []string
- func (s *Slack) HandleMessage(msg *Message) error
- func (s *Slack) IsConnected() bool
- func (s *Slack) NewConnection() error
- func (s *Slack) PushEvent(event base.Event) error
- func (s *Slack) Setup(cfg *base.CommunicationsConfig)
- func (s *Slack) WebsocketConnect() error
- func (s *Slack) WebsocketKeepAlive()
- func (s *Slack) WebsocketReader()
- func (s *Slack) WebsocketSend(eventType, text string) error
- type WebsocketResponse
Constants ¶
const (
SlackURL = "https://slack.com/api/rtm.start"
)
const declares main slack url and commands that will be supported on client side
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Message ¶
type Message struct { Channel string `json:"channel"` User string `json:"user"` Text string `json:"text"` SourceTeam string `json:"source_team"` Timestamp float64 `json:"ts,string"` Team string `json:"team"` }
Message is a response type handling message data
type PresenceChange ¶
PresenceChange holds user presence data
type Response ¶
type Response struct { Channels []struct { ID string `json:"id"` Name string `json:"name"` NameNormalized string `json:"name_normalized"` PreviousNames []string `json:"previous_names"` } `json:"channels"` Groups []struct { ID string `json:"id"` Name string `json:"name"` Members []string `json:"members"` } `json:"groups"` Ok bool `json:"ok"` Error string `json:"error"` Self struct { ID string `json:"id"` Name string `json:"name"` } `json:"self"` Team struct { Domain string `json:"domain"` ID string `json:"id"` Name string `json:"name"` } `json:"team"` URL string `json:"url"` Users []struct { ID string `json:"id"` Name string `json:"name"` TeamID string `json:"team_id"` } `json:"users"` }
Response is a generalised response type
type SendMessage ¶
type SendMessage struct { ID int64 `json:"id"` Type string `json:"type"` Channel string `json:"channel"` Text string `json:"text"` }
SendMessage holds details for message information
type Slack ¶
type Slack struct { base.Base TargetChannel string VerificationToken string TargetChannelID string Details Response ReconnectURL string WebsocketConn *websocket.Conn Connected bool Shutdown bool sync.Mutex }
Slack starts a websocket connection and uses https://api.slack.com/rtm real time messaging
func (*Slack) GetChannelIDByName ¶
GetChannelIDByName returns a channel ID by its corresponding name
func (*Slack) GetChannelsString ¶
GetChannelsString returns a list of all channels on the slack workspace
func (*Slack) GetGroupIDByName ¶
GetGroupIDByName returns a groupID by group name
func (*Slack) GetIDByName ¶
GetIDByName returns either a group ID or Channel ID
func (*Slack) GetUsernameByID ¶
GetUsernameByID returns a users name by ID
func (*Slack) GetUsersInGroup ¶
GetUsersInGroup returns a list of users currently in a group
func (*Slack) HandleMessage ¶
HandleMessage handles incoming messages and/or commands from slack
func (*Slack) IsConnected ¶
IsConnected returns whether or not the connection is connected
func (*Slack) NewConnection ¶
NewConnection connects the bot to a slack workgroup using a verification token and a channel
func (*Slack) Setup ¶
func (s *Slack) Setup(cfg *base.CommunicationsConfig)
Setup takes in a slack configuration, sets bots target channel and sets verification token to access workspace
func (*Slack) WebsocketConnect ¶
WebsocketConnect creates a websocket dialer amd initiates a websocket connection
func (*Slack) WebsocketKeepAlive ¶
func (s *Slack) WebsocketKeepAlive()
WebsocketKeepAlive sends a ping every 5 minutes to keep connection alive
func (*Slack) WebsocketReader ¶
func (s *Slack) WebsocketReader()
WebsocketReader reads incoming events from the websocket connection
func (*Slack) WebsocketSend ¶
WebsocketSend sends a message via the websocket connection