Code Monkey home page Code Monkey logo

slack's Introduction

Basic Usage

Build the Plain Text example

package main

func main() {
	text := slack.NewPlainText("This is a plain text section block.").EnableEmoji()
	section := slack.NewSection().SetText(text)
	basic := slack.NewMessage().AddBlock(section)

	fmt.Println(basic)

Outputs:

{
	"blocks": [
		{
			"type": "section",
			"text": {
				"type": "plain_text",
				"text": "This is a plain text section block.",
				"emoji": true
			}
		}
	]
}

This can be condensed

package main

import (
	"fmt"
	"github.com/mresl/slack"
)

func main() {
	text := slack.NewPlainText("This is a plain text section block.").EnableEmoji()
	fmt.Println(slack.NewMessage().AddBlock(text.Section()))
}

Real World Example

Composing the example message:

package main

import (
	"fmt"
	slack "github.com/jeremyforan/go-flocks-of-blocks"
)

func main() {

	// create a new message
	msg := slack.NewMessage()

	// Add a header
	header := slack.NewHeader("Device Summary")
	msg = msg.AddBlock(header)

	// Add some info
	info := slack.NewSection().AddMrkdownField("*IP:* 192.168.0.1").AddMrkdownField("*Area:* basement")
	msg = msg.AddBlock(info)

	// Add some more info but in a single line
	msg = msg.AddBlock(slack.NewSection().AddMrkdownField("*Hardware:* Linksys WRT-54G").AddMrkdownField("*Uptime:* 7 Days, 3 Months"))

	// Add the info message to
	ssid := slack.NewSection().AddMrkdownField("*SSID:* FreshPrinceOfDonair")
	msg = msg.AddBlock(ssid)

	// make a "reset" button
	resetButton := slack.NewButton("Reboot Device", "actionId-0").SetValue("click_me_123")

	// Let's assume we want to add a note based on some arbitrary bool value
	rfIssue := true
	if rfIssue {
		note := slack.NewPlainText("*high levels of RF interference detected consider scan")
		msg = msg.AddBlock(note.Context())

		// We want to add the Danger styleing to the button due to the 'issue'
		resetButton = resetButton.MakeStyleDanger()
	}

	// Add the reset button to the message
	msg = msg.AddBlock(resetButton.Actions())

	// Generate a link that paste the body into the Slack interactive Block Kit Builder for validation
	fmt.Println(msg.GenerateKitBuilderUrl())
}

slack's People

Contributors

mresl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.