workplace

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 7 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Workplace Logo

 

made-with-Go GoDoc Test Maintainability Codacy Badge codecov GoReportCard

👍 Workplace

An extremely simple Facebook Workplace client for sending transmissions to threads via Go.

Install

go get -u github.com/ainsleyclark/workplace

Quick Start

See below for a quick start to create a new Workplace client and sending off a transmission. For more details please see Go Doc which includes information on all types.

func Example() error {
	// Create as new Workplace client.
	wp, err := workplace.New(workplace.Config{Token: "my-token"})
	if err != nil {
		return err
	}

	// Create a new Workplace Transmission that contains
	// the thread ID and message to be sent to the thread.
	tx := workplace.Transmission{
		Thread:  "thread-id",
		Message: "message",
	}

	// Send the transmission to the workplace API.
	err = wp.Notify(tx)
	if err != nil {
		return err
	}

	return nil
}

Roadmap

Contributing

Please feel free to make a pull request if you think something should be added to this package!

Credits

Shout out to the incredible Maria Letta for her excellent Gopher illustrations.

Licence

Code Copyright 2022 Ainsley Clark. Code released under the MIT Licence.

Documentation

Index

Constants

View Source
const (
	// Timeout specifies a time limit for requests made by the
	// Workplace Client.
	Timeout = time.Second * 20
)

Variables

This section is empty.

Functions

func ChunkMessage added in v0.0.3

func ChunkMessage(s string, chunkSize int) []string

ChunkMessage splits a string by length according to the chunkSize.

Types

type Client

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

Client represents the HTTP client for posting and returning data from the Workplace API.

func (*Client) Notify

func (c *Client) Notify(tx Transmission) error

Notify sends a transmission to the corresponding thread with a preformatted message.

Returns an error if the message could not be marshalled, sent or there was an error creating the request.

type Config

type Config struct {
	Token string
}

Config is the configuration passed to create a new Workplace client.

func (*Config) Validate

func (c *Config) Validate() error

Validate sanity checks the configuration.

type Notifier

type Notifier interface {
	// Notify sends a transmission to the corresponding thread with
	// a preformatted message.
	//
	// Returns an error if the message could not be marshalled,
	// sent or there was an error creating the request.
	Notify(tx Transmission) error
}

Notifier defines the single method interface that transmits messages to a workplace thread.

func New

func New(config Config) (Notifier, error)

New returns a new Workplace Client.

type Transmission

type Transmission struct {
	// Thread is the corresponding thread ID to send via workplace.
	Thread string `json:"thread" validate:"required" example:"t_111222333"`
	// Message is the formatted text message that will be sent
	// via workplace.
	Message string `json:"message" validate:"required" example:"Hey there!"`
}

Transmission represents the data needed in order to send a message via the Workplace API.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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