slack

package
v0.0.0-...-ca57207 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Functions

func GetBotMessageForTesting

func GetBotMessageForTesting() string

GetBotMessageForTesting returns a mock bot message (JSON).

func GetTokenFromTeamId

func GetTokenFromTeamId(a *App, teamID string) string

func IsBotMessage

func IsBotMessage(event EventMessage) bool

IsBotMessage returns true if event is created by a bot.

func ParseEvent

func ParseEvent(data []byte) (interface{}, error)

ParseEvent will try parsing slack events and return the first matching struct

Possible event types - EventChallenge

It will return map[string]interface{} if no type is matched

func SendMessage

func SendMessage(postMessage ChatPostMessage)

SendMessage sends to slack

Documentation: https://api.slack.com/methods/chat.postMessage

Types

type App

type App struct {
	HttpClient  HttpClient
	MongoClient *mongo.Client
	// contains filtered or unexported fields
}

App manages Global Application State

func ProvideSlackApp

func ProvideSlackApp(config *config.Config, httpClient HttpClient, mongoClient *mongo.Client, verifier SlackRequestVerifier) *App

func ProvideTestApp

func ProvideTestApp(httpClient HttpClient, mongoClient *mongo.Client) *App

func (*App) CommandHandler

func (app *App) CommandHandler(w http.ResponseWriter, r *http.Request)

CommandHandler handles slack slash command

ENDPOINT /api/slack/command

Example Usage /time 2018-12-31 21:40 PST => 2019-01-01 14:40 KST

func (*App) EventHandler

func (app *App) EventHandler(w http.ResponseWriter, r *http.Request)

EventHandler responds to the Slack Event.

When Slack is first connected, it sends "Challenge". We need to return the challenge code right away to be connected.

func (*App) GetOauthCollection

func (app *App) GetOauthCollection() *mongo.Collection

func (*App) OauthHandler

func (app *App) OauthHandler(writer http.ResponseWriter, request *http.Request)

type BotProfile

type BotProfile struct {
	ID      string `json:"id"`
	Deleted bool   `json:"deleted"`
	Name    string `json:"name"`
	Updated int    `json:"updated"`
	AppID   string `json:"app_id"`
	Icons   struct {
		Image36 string `json:"image_36"`
		Image48 string `json:"image_48"`
		Image72 string `json:"image_72"`
	} `json:"icons"`
	TeamID string `json:"team_id"`
}

type ChatPostMessage

type ChatPostMessage struct {
	Token   string `json:"token"`
	Channel string `json:"channel"`
	Text    string `json:"text"`

	Attachments []interface{} `json:"attchments,omitempty"`
	ThreadTs    string        `json:"thread_ts,omitempty"`
	Mrkdown     bool          `json:"mrkdown,omitempty"`
	AsUser      bool          `json:"as_user,omitempty"`
}

ChatPostMessage is a struct sent to Slack

type EventChallenge

type EventChallenge struct {
	Token     string `json:"token"`
	Challenge string `json:"challenge"`
	Type      string `json:"type"`
}

EventChallenge is the first event sent when registering the app

The app should return challenge right away

type EventMessage

type EventMessage struct {
	Token       string           `json:"token"`
	TeamID      string           `json:"team_id"`
	APIAppID    string           `json:"api_app_id"`
	Event       EventMessageType `json:"event"`
	Type        string           `json:"type"`
	EventID     string           `json:"event_id"`
	EventTime   int              `json:"event_time"`
	AuthedUsers []string         `json:"authed_users"`
}

EventMessage is a struct sent by Slack

type EventMessageType

type EventMessageType struct {
	ClientMsgID string `json:"client_msg_id"`
	Type        string `json:"type"`

	Text string `json:"text"`
	User string `json:"user"`
	Ts   string `json:"ts"`
	Team string `json:"team"`

	// Only filled when the message is from a bot.
	BotID      string      `json:"bot_id"`
	BotProfile *BotProfile `json:"bot_profile,omitempty"`

	// (optional) if this field exists, then it's a thread reply
	ThreadTs string `json:"thread_ts,omitempty"`

	// (optional) if this field exists, then it's a thread reply
	ParentUserID string `json:"parent_user_id,omitempty"`
	Channel      string `json:"channel"`
	EventTs      string `json:"event_ts"`
	ChannelType  string `json:"channel_type"`
}

EventMessageType holds the information of message type

type HttpClient

type HttpClient interface {
	Do(*http.Request) (*http.Response, error)
}

type Response

type Response struct {
	Text         string       `json:"text"`
	ResponseType ResponseType `json:"response_type,omitempty"`
}

Response is a Slack Response struct

type ResponseType

type ResponseType string

ResponseType is a type of slack message type

const (
	// InChannel = everyone in the channel can view the message
	InChannel ResponseType = "in_channel"
	// Ephemeral = only the person who triggered the command can view the message
	Ephemeral ResponseType = "ephemeral"
)

type SlackRequestVerifier

type SlackRequestVerifier interface {
	Verify(r *http.Request) bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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