commonchat

package module
v0.3.13 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 5 Imported by: 32

README

CommonChat

Build Status Go Report Card Docs License

CommonChat is an abstraction library for chat / team messaging services like Glip and Slack. It currently includes two parts:

  • Common message format - After converting a message to the commonchat.Message format, the libraries can be used to convert to individula chat services.
  • Webhook clients - Given a webhook URL, the clients use the commonchat.Adapter interface to enable webhook API calls using the commonchat.Message format.

It is currently used with the Chathooks webhook formatting service:

https://github.com/grokify/chathooks

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EmojiToURL

func EmojiToURL(urlFormat string, emoji string) (string, error)

EmojiToURL function takes a `Sprintf` `format` string and emoji string with or without surrounding colons (`:`) and returns a URL. Emoji strings must satisfy `[a-z_]+` regexp.

Types

type Adapter

type Adapter interface {
	SendWebhook(url string, ccMsg Message, formattedMsg interface{}, opts map[string]interface{}) (*fasthttp.Request, *fasthttp.Response, error)
	SendMessage(ccMsg Message, formattedMsg interface{}, opts map[string]interface{}) (*fasthttp.Request, *fasthttp.Response, error)
	WebhookUID(ctx *fasthttp.RequestCtx) (string, error)
}

type Attachment

type Attachment struct {
	AuthorIcon   string   `json:"author_icon,omitempty"`
	AuthorLink   string   `json:"author_link,omitempty"`
	AuthorName   string   `json:"author_name,omitempty"`
	Color        string   `json:"color,omitempty"`
	Fallback     string   `json:"fallback,omitempty"`
	Fields       []Field  `json:"fields,omitempty"`
	MarkdownIn   []string `json:"mrkdwn_in,omitempty"`
	Pretext      string   `json:"pretext,omitempty"`
	Text         string   `json:"text,omitempty"`
	ThumbnailURL string   `json:"thumbnail_url,omitempty"`
	Title        string   `json:"title,omitempty"`
}

func NewAttachment

func NewAttachment() Attachment

func (*Attachment) AddField

func (attach *Attachment) AddField(field Field)

type Field

type Field struct {
	Title string `json:"title,omitempty"`
	Value string `json:"value,omitempty"`
	Short bool   `json:"short,omitempty"`
}

type Message

type Message struct {
	Activity    string       `json:"activity,omitempty"`
	IconEmoji   string       `json:"icon_emoji,omitempty"`
	IconURL     string       `json:"icon_url,omitempty"`
	Title       string       `json:"title,omitempty"`
	Text        string       `json:"text,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
}

func NewMessage

func NewMessage() Message

func (*Message) AddAttachment

func (msg *Message) AddAttachment(att Attachment)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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