Skip to content

spider-pigs/slackmsg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slackmsg

Build Status Go Report Card GoDoc

A simple golang library to send a slack message.

Install

import "github.com/spider-pigs/slackmsg"

Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/spider-pigs/slackmsg"
)

func main() {
	// create message
	msg := slackmsg.New()
	msg.Text = "I am a test message!"
	attachment := slackmsg.Attachment{
		Text: "And here’s an attachment!",
	}
	msg.AddAttachment(attachment)

	// dump JSON to verify?
	fmt.Println(msg.ToJSON())

	// send message
	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	webhook := "https://hooks.slack.com/services/..."
	err := msg.Send(ctx, webhook)
	if err != nil {
		fmt.Println("failed to send message:", err)
		return
	}
	fmt.Println("successfully sent message")
}