README
¶
GoCryptoTrader package Slack

This slack package is part of the GoCryptoTrader codebase.
This is still in active development
You can track ideas, planned features and what's in progress on our GoCryptoTrader Kanban board.
Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack
Slack Communications package
What is Slack?
- Slack is a code-centric collaboration hub that allows users to connect via an app and share different types of data
- Please visit: Slack for more information and account setup
Current Features
- Basic communication to your slack channel information includes:
- Working status of bot
How to enable
-
Individual package example below:
import (
"github.com/thrasher-corp/gocryptotrader/communications/slack"
"github.com/thrasher-corp/gocryptotrader/config"
)
s := new(slack.Slack)
// Define slack configuration
commsConfig := config.CommunicationsConfig{SlackConfig: config.SlackConfig{
Name: "Slack",
Enabled: true,
Verbose: false,
TargetChannel: "targetChan",
VerificationToken: "slackGeneratedToken",
}}
s.Setup(commsConfig)
err := s.Connect
// Handle error
Once the bot has started you can interact with the bot using these commands via Slack:
!status - Displays current working status of bot
!help - Displays help text
!settings - Displays current settings
Please click GoDocs chevron above to view current GoDoc information for this package
Contribution
Please feel free to submit any pull requests or suggest any desired features to be added.
When submitting a PR, please abide by our coding guidelines:
- Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
- Code must be documented adhering to the official Go commentary guidelines.
- Code must adhere to our coding style.
- Pull requests need to be based on and opened against the
master
branch.
Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:
bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc
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 // contains filtered or unexported fields }
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