slack

package
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 12 Imported by: 3

Documentation

Index

Constants

View Source
const (
	ParamNamePayload = "payload"
)

Variables

View Source
var (
	WebhookBaseURL = "https://hooks.slack.com/services/"
)

Functions

func ConvertMarkdownSlack

func ConvertMarkdownSlack(markdown string) string

func ExampleMessageAttachmentURLValues added in v0.2.2

func ExampleMessageAttachmentURLValues() url.Values

func WebhookInBodySlackToCc

func WebhookInBodySlackToCc(slMsg Message) cc.Message

Types

type Attachment

type Attachment struct {
	AuthorIcon   string   `json:"author_icon,omitempty"`
	AuthorLink   string   `json:"author_link,omitempty"`
	AuthorName   string   `json:"author_name,omitempty"`
	Color        string   `json:"color,omitempty"`
	Fallback     string   `json:"fallback,omitempty"`
	Fields       []Field  `json:"fields,omitempty"`
	MarkdownIn   []string `json:"mrkdwn_in,omitempty"`
	Pretext      string   `json:"pretext,omitempty"`
	Text         string   `json:"text,omitempty"`
	ThumbnailURL string   `json:"thumbnail_url,omitempty"`
	Title        string   `json:"title,omitempty"`
}

func ConvertAttachmentSlack

func ConvertAttachmentSlack(commonAttachment cc.Attachment) Attachment

func ConvertAttachmentsSlack

func ConvertAttachmentsSlack(commonAttachments []cc.Attachment) []Attachment

type ClientType

type ClientType int
const (
	HTTP ClientType = iota
	FastHTTP
)

type CommonPost

type CommonPost struct {
	Channel     string       `json:"channel,omitempty"`
	Username    string       `json:"username,omitempty"`
	IconEmoji   string       `json:"icon_emoji,omitempty"`
	LinkNames   int          `json:"link_names,omitempty"`
	Text        string       `json:"text,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
}

type CreatePostRequest

type CreatePostRequest struct {
	CommonPost
	AsUser         bool    `json:"as_user,omitempty"`
	IconURL        string  `json:"icon_url,omitempty"`
	LinkNames      bool    `json:"link_names,omitempty"`
	Parse          bool    `json:"parse,omitempty"`
	ReplyBroadcast bool    `json:"reply_broadcast,omitempty"`
	UnfurlLinks    bool    `json:"unfurl_links,omitempty"`
	UnfurlMedia    bool    `json:"unfurl_media,omitempty"`
	ThreadTS       float64 `json:"thread_ts,omitempty"`
}

type Field

type Field struct {
	Title string          `json:"title,omitempty"`
	Value jsonutil.String `json:"value,omitempty"`
	Short bool            `json:"short,omitempty"`
}

func ConvertFieldSlack

func ConvertFieldSlack(commonField cc.Field) Field

func ConvertFieldsSlack

func ConvertFieldsSlack(commonFields []cc.Field) []Field

type Message

type Message struct {
	Attachments []Attachment `json:"attachments,omitempty"`
	IconEmoji   string       `json:"icon_emoji,omitempty"`
	IconURL     string       `json:"icon_url,omitempty"`
	Mrkdwn      bool         `json:"mrkdwn,omitempty"`
	Text        string       `json:"text,omitempty"`
	Username    string       `json:"username,omitempty"`
}

func ConvertCommonMessage

func ConvertCommonMessage(ccMsg cc.Message) Message

func ExampleMessageAttachment added in v0.2.2

func ExampleMessageAttachment() Message

func ParseMessageAny added in v0.1.6

func ParseMessageAny(data []byte) (Message, error)

func ParseMessageJSON added in v0.1.5

func ParseMessageJSON(bytes []byte) (Message, error)

func ParseMessageURLEncoded added in v0.1.6

func ParseMessageURLEncoded(data []byte) (Message, error)

func ParseMessageURLValues added in v0.1.9

func ParseMessageURLValues(qry url.Values) (Message, error)

type SlackAdapter

type SlackAdapter struct {
	SlackClient     SlackWebhookClient
	EmojiURLFormat  string
	WebhookURLOrUID string
}

func NewSlackAdapter

func NewSlackAdapter(webhookURLOrUID string) (*SlackAdapter, error)

func (*SlackAdapter) SendMessage

func (adapter *SlackAdapter) SendMessage(message commonchat.Message, slackmsg interface{}, opts map[string]interface{}) (*fasthttp.Request, *fasthttp.Response, error)

func (*SlackAdapter) SendWebhook

func (adapter *SlackAdapter) SendWebhook(urlOrUID string, ccMsg commonchat.Message, slackmsg interface{}, opts map[string]interface{}) (*fasthttp.Request, *fasthttp.Response, error)

func (*SlackAdapter) WebhookUID

func (adapter *SlackAdapter) WebhookUID(ctx *fasthttp.RequestCtx) (string, error)

type SlackWebhookClient

type SlackWebhookClient struct {
	HTTPClient *http.Client
	FastClient *fasthttp.Client
	WebhookURL string
	URLPrefix  *regexp.Regexp
}

func NewSlackWebhookClient

func NewSlackWebhookClient(urlOrUID string, clientType ClientType) (SlackWebhookClient, error)

func (*SlackWebhookClient) BuildWebhookURL

func (client *SlackWebhookClient) BuildWebhookURL(urlOrUID string) string

func (*SlackWebhookClient) PostWebhookFast

func (client *SlackWebhookClient) PostWebhookFast(url string, message Message) (*fasthttp.Request, *fasthttp.Response, error)

func (*SlackWebhookClient) PostWebhookGUIDFast

func (client *SlackWebhookClient) PostWebhookGUIDFast(urlOrUID string, message Message) (*fasthttp.Request, *fasthttp.Response, error)

type WebhookRequest

type WebhookRequest struct {
	CommonPost
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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