slack

package
v2.31.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 3 Imported by: 0

README

Perkakas Slack Library

This library helps you to send message to slack via simple webhook

How To Send Message

slackMsg := NewWebhook("https://hooks.slack.com/services/your-webhook-url-path")
slackMsg.AddField("Name", "Mau tau aja")
slackMsg.AddField("Phonenumber", "081211113333")
slackMsg.AddField("Email", "qwe@testing.com")
slackMsg.AddText("Hello from Tuman-app staging")
slackMsg.SetChannelMention(true)

err := slackMsg.Send()
if err != nil {
    fmt.Println(err.Error())
}

The code will produce this kind of message:

sample message img

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WebHook

type WebHook struct {
	URL              string
	IsChannelMention bool
	Attachment       []slack.Attachment
	Text             string
}

WebHook defines simple webhook instance

func NewWebhook

func NewWebhook(url string) WebHook

NewWebhook will create simple webhook instance

func (*WebHook) AddField

func (w *WebHook) AddField(title, value string)

AddField will new field to slack attachment

func (*WebHook) AddText

func (w *WebHook) AddText(message string)

AddText will add text to slack message

func (*WebHook) Send

func (w *WebHook) Send() error

Send will send slack notification using webhook

func (*WebHook) SetChannelMention

func (w *WebHook) SetChannelMention(flag bool)

SetChannelMention will set whether @channel is mentioned or not

func (*WebHook) SetColor

func (w *WebHook) SetColor(color string)

SetColor will set attachment color in #FFFFFF hex representation

Jump to

Keyboard shortcuts

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