slack

package
v0.0.0-...-069e140 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2021 License: MIT Imports: 12 Imported by: 0

README

GoCryptoTrader package Slack

Build Status Software License GoDoc Coverage Status Go Report Card

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 this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

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
import (
"github.com/yurulab/gocryptotrader/communications/slack"
"github.com/yurulab/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

View Source
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

type PresenceChange struct {
	Presence string `json:"presence"`
	User     string `json:"user"`
}

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) BuildURL

func (s *Slack) BuildURL(token string) string

BuildURL returns an appended token string with the SlackURL

func (*Slack) Connect

func (s *Slack) Connect() error

Connect connects to the service

func (*Slack) GetChannelIDByName

func (s *Slack) GetChannelIDByName(channel string) (string, error)

GetChannelIDByName returns a channel ID by its corresponding name

func (*Slack) GetChannelsString

func (s *Slack) GetChannelsString() []string

GetChannelsString returns a list of all channels on the slack workspace

func (*Slack) GetGroupIDByName

func (s *Slack) GetGroupIDByName(group string) (string, error)

GetGroupIDByName returns a groupID by group name

func (*Slack) GetIDByName

func (s *Slack) GetIDByName(userName string) (string, error)

GetIDByName returns either a group ID or Channel ID

func (*Slack) GetUsernameByID

func (s *Slack) GetUsernameByID(id string) string

GetUsernameByID returns a users name by ID

func (*Slack) GetUsersInGroup

func (s *Slack) GetUsersInGroup(group string) []string

GetUsersInGroup returns a list of users currently in a group

func (*Slack) HandleMessage

func (s *Slack) HandleMessage(msg *Message) error

HandleMessage handles incoming messages and/or commands from slack

func (*Slack) IsConnected

func (s *Slack) IsConnected() bool

IsConnected returns whether or not the connection is connected

func (*Slack) NewConnection

func (s *Slack) NewConnection() error

NewConnection connects the bot to a slack workgroup using a verification token and a channel

func (*Slack) PushEvent

func (s *Slack) PushEvent(event base.Event) error

PushEvent pushes an event to either a slack channel or specific client

func (*Slack) Setup

func (s *Slack) Setup(cfg *config.CommunicationsConfig)

Setup takes in a slack configuration, sets bots target channel and sets verification token to access workspace

func (*Slack) WebsocketConnect

func (s *Slack) WebsocketConnect() error

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

func (s *Slack) WebsocketSend(eventType, text string) error

WebsocketSend sends a message via the websocket connection

type WebsocketResponse

type WebsocketResponse struct {
	Type    string `json:"type"`
	ReplyTo int    `json:"reply_to"`
	Error   struct {
		Msg  string `json:"msg"`
		Code int    `json:"code"`
	} `json:"error"`
}

WebsocketResponse holds websocket response data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL