vslack

package module
v0.0.0-...-5e3b6ad Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

VSlack - Go

Version 1.4.0

Send messages to slack using a slack incoming web hook in Go.

Import

import "github.com/taylorwiebe/vslack-go"

Examples

synchronous
func synchronous() {
	s := vslack.NewVSlack(incomingWebHook)
	err := s.SetChannel("#random").
		SetIconEmoji(":laughing:").
		SetUsername("VSlack").
		SetMessage("Test message").
		Send()
	if err != nil {
		panic(err)
	}
}
Concurrent Example
func concurrent(c chan error) {
	s := vslack.NewVSlack(incomingWebHook)
	err := s.SetChannel("#random").
		SetIconEmoji(":laughing:").
		SetUsername("VSlack").
		SetMessage("Test message").
		Send()

	c <- err
}

func main() {
	c := make(chan error)
	go concurrent(c)
	if err := <-c; err != nil {
		panic(err)
	}
}
Attachments
func attach() {
	s := vslack.NewVSlack(incomingWebHook)
	err := s.SetChannel("#general").
		SetIconEmoji(":laughing:").
		SetUsername("VSlack").
		SetAttachments(
			vslack.NewVSlackAttachment().
				SetText("*test*").
				SetTitle("title").
				SetMarkdownIn(
					vslack.Text(),
					vslack.Fields(),
					vslack.Pretext())).
		Send()

	if err != nil {
		panic(err)
	}
}
@-tagging Users
func tagging() {
	s := vslack.NewVSlack(incomingWebHook)
	err := s.SetChannel("#random").
		SetIconEmoji(":laughing:").
		SetUsername("VSlack").
		SetMessage("With great power comes great responsibility, @channel").
        SetLinkNames(true).
		Send()
	if err != nil {
		panic(err)
	}
}

Change Log

1.4.0
  • Add LinkNames parameter, for enabling @-tagging of users without having to know their slack userid.
1.3.0
  • Add mocks to Interface and AttachmentInterface
1.2.0
  • Fix name in Interface of SetIncomingWebhookURI
1.1.0
  • Add implementation for SendAsync
1.0.0
  • Initial Release

Copyright 2017 Vendasta Technologies Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Title      string   `json:"title"`
	TitleLink  string   `json:"title_link"`
	Text       string   `json:"text"`
	Fallback   string   `json:"fallback"`
	Markdown   bool     `json:"mrkdwn"`
	MarkdownIn []string `json:"mrkdwn_in,omitempty"`
	Color      string   `json:"color"`
	Fields     []Field  `json:"fields"`
}

Attachment is a slack attachment

func NewVSlackAttachment

func NewVSlackAttachment() Attachment

NewVSlackAttachment returns an instance of a new VSlack attachment

func (Attachment) SetColor

func (a Attachment) SetColor(c string) Attachment

SetColor sets the message colour

func (Attachment) SetFields

func (a Attachment) SetFields(f ...Field) Attachment

SetFields is the list of attachment fields

func (Attachment) SetMarkdown

func (a Attachment) SetMarkdown(m bool) Attachment

SetMarkdown sets whether or not to use markdown in a message

func (Attachment) SetMarkdownIn

func (a Attachment) SetMarkdownIn(opts ...MarkdownOption) Attachment

SetMarkdownIn takes in supported markdown types

func (Attachment) SetText

func (a Attachment) SetText(t string) Attachment

SetText is an attachments text

func (Attachment) SetTitle

func (a Attachment) SetTitle(t string) Attachment

SetTitle of the message

func (a Attachment) SetTitleLink(l string) Attachment

SetTitleLink of the message

type AttachmentInterface

type AttachmentInterface interface {
	SetText(t string) Attachment
	SetColor(c string) Attachment
	SetTitle(t string) Attachment
	SetTitleLink(l string) Attachment
	SetFields(f ...Field) Attachment
	SetMarkdown(m bool) Attachment
	SetMarkdownIn(opts ...MarkdownOption) Attachment
}

AttachmentInterface is the interface for an attachment

type Field

type Field struct {
	Title string `json:"title"`
	Value string `json:"value"`
}

Field is an a slack attachment

type Interface

type Interface interface {
	SetIncomingWebhookURI(h string) *VSlack
	SetChannel(c string) *VSlack
	SetUsername(u string) *VSlack
	SetIconEmoji(i string) *VSlack
	SetMessage(m string) *VSlack
	Send() error
	SendAsync(e chan error)
	SetAttachments(a ...Attachment) *VSlack
	SetLinkNames(linkNames bool) *VSlack
	// contains filtered or unexported methods
}

Interface is a VSlack interface

type MarkdownConfiguration

type MarkdownConfiguration struct {
	// contains filtered or unexported fields
}

MarkdownConfiguration are options for message markdown

type MarkdownOption

type MarkdownOption func(m *MarkdownConfiguration)

MarkdownOption is an option for markdown in a slack message

func Fields

func Fields() MarkdownOption

Fields set the fields option

func Pretext

func Pretext() MarkdownOption

Pretext set the pretext option

func Text

func Text() MarkdownOption

Text set the text option

type MockAttachmentInterface

type MockAttachmentInterface struct {
	mock.Mock
}

MockAttachmentInterface is an autogenerated mock type for the AttachmentInterface type

func (*MockAttachmentInterface) SetColor

func (_m *MockAttachmentInterface) SetColor(c string) Attachment

SetColor provides a mock function with given fields: c

func (*MockAttachmentInterface) SetFields

func (_m *MockAttachmentInterface) SetFields(f ...Field) Attachment

SetFields provides a mock function with given fields: f

func (*MockAttachmentInterface) SetMarkdown

func (_m *MockAttachmentInterface) SetMarkdown(m bool) Attachment

SetMarkdown provides a mock function with given fields: m

func (*MockAttachmentInterface) SetMarkdownIn

func (_m *MockAttachmentInterface) SetMarkdownIn(opts ...MarkdownOption) Attachment

SetMarkdownIn provides a mock function with given fields: opts

func (*MockAttachmentInterface) SetText

func (_m *MockAttachmentInterface) SetText(t string) Attachment

SetText provides a mock function with given fields: t

func (*MockAttachmentInterface) SetTitle

func (_m *MockAttachmentInterface) SetTitle(t string) Attachment

SetTitle provides a mock function with given fields: t

func (_m *MockAttachmentInterface) SetTitleLink(l string) Attachment

SetTitleLink provides a mock function with given fields: l

type MockInterface

type MockInterface struct {
	mock.Mock
}

MockInterface is an autogenerated mock type for the Interface type

func (*MockInterface) Send

func (_m *MockInterface) Send() error

Send provides a mock function with given fields:

func (*MockInterface) SendAsync

func (_m *MockInterface) SendAsync(e chan error)

SendAsync provides a mock function with given fields: e

func (*MockInterface) SetAttachments

func (_m *MockInterface) SetAttachments(a ...Attachment) *VSlack

SetAttachments provides a mock function with given fields: a

func (*MockInterface) SetChannel

func (_m *MockInterface) SetChannel(c string) *VSlack

SetChannel provides a mock function with given fields: c

func (*MockInterface) SetIconEmoji

func (_m *MockInterface) SetIconEmoji(i string) *VSlack

SetIconEmoji provides a mock function with given fields: i

func (*MockInterface) SetIncomingWebhookURI

func (_m *MockInterface) SetIncomingWebhookURI(h string) *VSlack

SetIncomingWebhookURI provides a mock function with given fields: h

func (*MockInterface) SetLinkNames

func (_m *MockInterface) SetLinkNames(linkNames bool) *VSlack

SetLinkNames provides a mock function with given fields: linkNames

func (*MockInterface) SetMessage

func (_m *MockInterface) SetMessage(m string) *VSlack

SetMessage provides a mock function with given fields: m

func (*MockInterface) SetUsername

func (_m *MockInterface) SetUsername(u string) *VSlack

SetUsername provides a mock function with given fields: u

type MockMarkdownOption

type MockMarkdownOption struct {
	mock.Mock
}

MockMarkdownOption is an autogenerated mock type for the MarkdownOption type

func (*MockMarkdownOption) Execute

func (_m *MockMarkdownOption) Execute(m *MarkdownConfiguration)

Execute provides a mock function with given fields: m

type VSlack

type VSlack struct {
	IncomingWebhookURI string       `json:"-"`
	Message            string       `json:"text,omitempty"`
	Username           string       `json:"username"`
	IconEmoji          string       `json:"icon_emoji,omitempty"`
	Channel            string       `json:"channel"`
	Attachments        []Attachment `json:"attachments,omitempty"`
	LinkNames          bool         `json:"link_names,omitempty"`
}

VSlack a structure holding data for the slack message

func NewVSlack

func NewVSlack(incomingwebHookURI string) *VSlack

NewVSlack returns a new instance of VSlack

func (*VSlack) Send

func (v *VSlack) Send() error

Send the message

func (*VSlack) SendAsync

func (v *VSlack) SendAsync(e chan error)

SendAsync sends the message asynchronously

func (*VSlack) SetAttachments

func (v *VSlack) SetAttachments(a ...Attachment) *VSlack

SetAttachments takes in attachments

func (*VSlack) SetChannel

func (v *VSlack) SetChannel(c string) *VSlack

SetChannel sets the channel

func (*VSlack) SetIconEmoji

func (v *VSlack) SetIconEmoji(i string) *VSlack

SetIconEmoji sets the emoji for the icon

func (*VSlack) SetIncomingWebhookURI

func (v *VSlack) SetIncomingWebhookURI(h string) *VSlack

SetIncomingwebHookURI sets the incoming web hook

func (*VSlack) SetLinkNames

func (v *VSlack) SetLinkNames(linkNames bool) *VSlack

SetLinkNames takes in attachments

func (*VSlack) SetMessage

func (v *VSlack) SetMessage(m string) *VSlack

SetMessage sets the message

func (*VSlack) SetUsername

func (v *VSlack) SetUsername(u string) *VSlack

SetUsername sets the username

Jump to

Keyboard shortcuts

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