glip

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 11 Imported by: 3

README

Glip Webhook Client in Go

Build Status Go Report Card Docs License Chat

Installation

$ go get github.com/grokify/go-glip

Usage

  1. Create a webhook URL for a conversation in Glip
  2. Use the code below to send a message to the webhook URL
import (
    "fmt"
    "github.com/grokify/go-glip"
)

func sendMessage() {
    // Can instantiate webhook client with full URL or GUID only
    url := "https://hooks.glip.com/webhook/00001111-2222-3333-4444-555566667777"
    client, err := glipwebhook.NewGlipWebhookClient(url)
    if err != nil {
        panic("BAD URL")
    }

    msg := glipwebhook.GlipWebhookMessage{
        Icon:     "https://raw.githubusercontent.com/grokify/glip-go-webhook/master/glip_gopher_600x600xfff.png",
        Activity: "Gopher [Bot]",
        Title:    "Test Message Title",
        Body:     "Test Message Body"}

    resp, err := client.PostMessage(msg)

    respBodyBytes, err := client.SendMessage(msg)
    if err == nil {
        fmt.Printf("%v\n", string(respBodyBytes))
    }
}
Using fasthttp client

Posts can be made using fasthttp.

import (
    "fmt"
    "github.com/grokify/go-glip"
)

func sendMessage() {
    // Can instantiate webhook client with full URL or GUID only
    url := "https://hooks.glip.com/webhook/00001111-2222-3333-4444-555566667777"
    client, err := glipwebhook.NewGlipWebhookClientFast(url)
    if err != nil {
        panic("BAD URL")
    }

    msg := glipwebhook.GlipWebhookMessage{
        Body: "Test Message Body"}

    req, resp, err := client.PostMessageFast(msg)
    if err == nil {
        fmt.Println(string(resp.Body()))
    }
    fasthttp.ReleaseRequest(req)
    fasthttp.ReleaseResponse(resp)
}

You can reuse the client for different Webhook URLs or GUIDs as follows:

// Webhook URL
res, resp, err := client.PostWebhookFast(url, msg)

// Webhook GUID
res, resp, err := client.PostWebhookGUIDFast(guid, msg)

Documentation

Index

Constants

View Source
const (
	ApiPathGlipFiles               = "/restapi/v1.0/glip/files"
	ApiPathGlipGroups              = "/restapi/v1.0/glip/groups"
	ApiPathGlipPosts               = "/restapi/v1.0/glip/posts"
	GlipWebhookV1BaseURLProduction = "https://hooks.ringcentral.com/webhook/"
	GlipWebhookV2BaseURLProduction = "https://hooks.ringcentral.com/webhook/v2/"
	GlipWebhookV1BaseURLSandbox    = "https://hooks-glip.devtest.ringcentral.com/webhook/"
	GlipWebhookV2BaseURLSandbox    = "https://hooks-glip.devtest.ringcentral.com/webhook/v2/"
	AttachmentTypeCard             = "Card"
)

Variables

View Source
var (
	WebhookBaseURL string = "https://hooks.glip.com/webhook/"
)

Functions

func MustNewWebhookURLString added in v0.4.0

func MustNewWebhookURLString(input string, webhookVersion int) string

func V1ToV2WebhookAttachment

func V1ToV2WebhookAttachment(v1att Attachment) v2.Attachment

func V1ToV2WebhookBody

func V1ToV2WebhookBody(v1msg GlipWebhookMessage) v2.GlipWebhookMessage

func V1ToV2WewbhookUri

func V1ToV2WewbhookUri(input string) (string, error)

Types

type Attachment

type Attachment struct {
	Type         string  `json:"card,omitempty"`
	Color        string  `json:"color,omitempty"`
	Pretext      string  `json:"pretext,omitempty"`
	AuthorName   string  `json:"author_name,omitempty"`
	AuthorLink   string  `json:"author_link,omitempty"`
	AuthorIcon   string  `json:"author_icon,omitempty"`
	Title        string  `json:"title,omitempty"`
	TitleLink    string  `json:"title_link,omitempty"`
	Fallback     string  `json:"fallback,omitempty"`
	Fields       []Field `json:"fields,omitempty"`
	Text         string  `json:"text,omitempty"`
	ImageURL     string  `json:"image_url,omitempty"`
	ThumbnailURL string  `json:"thumbnail_url,omitempty"`
	Footer       string  `json:"footer,omitempty"`
	FooterIcon   string  `json:"footer_icon,omitempty"`
	TS           int64   `json:"ts,omitempty"`
}

type Author

type Author struct {
	Name    string `json:"name,omitempty"`
	URI     string `json:"uri,omitempty"`
	IconURI string `json:"iconUri,omitempty"`
}

type Field

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

type Footnote

type Footnote struct {
	Text    string `json:"text,omitempty"`
	IconURI string `json:"iconUri,omitempty"`
}

type GlipWebhookClient

type GlipWebhookClient struct {
	HttpClient *http.Client
	FastClient fasthttp.Client
	WebhookUrl string
	// contains filtered or unexported fields
}

func NewGlipWebhookClient

func NewGlipWebhookClient(urlOrGuid string, webhookVersion int) (GlipWebhookClient, error)

func NewGlipWebhookClientFast

func NewGlipWebhookClientFast(urlOrGuid string, webhookVersion int) (GlipWebhookClient, error)

func (*GlipWebhookClient) PostMessage

func (client *GlipWebhookClient) PostMessage(message GlipWebhookMessage) (*http.Response, error)

func (*GlipWebhookClient) PostMessageFast

func (client *GlipWebhookClient) PostMessageFast(message GlipWebhookMessage) (*fasthttp.Request, *fasthttp.Response, error)

Request using fasthttp Recycle request and response using fasthttp.ReleaseRequest(req) and fasthttp.ReleaseResponse(resp)

func (*GlipWebhookClient) PostWebhook

func (client *GlipWebhookClient) PostWebhook(url string, message GlipWebhookMessage) (*http.Response, error)

func (*GlipWebhookClient) PostWebhookFast

func (client *GlipWebhookClient) PostWebhookFast(url string, message GlipWebhookMessage) (*fasthttp.Request, *fasthttp.Response, error)

func (*GlipWebhookClient) PostWebhookGUID

func (client *GlipWebhookClient) PostWebhookGUID(guid string, message GlipWebhookMessage) (*http.Response, error)

func (*GlipWebhookClient) PostWebhookGUIDFast

func (client *GlipWebhookClient) PostWebhookGUIDFast(guidOrURL string, message GlipWebhookMessage) (*fasthttp.Request, *fasthttp.Response, error)

func (*GlipWebhookClient) PostWebhookV1Bytes added in v0.2.0

func (client *GlipWebhookClient) PostWebhookV1Bytes(url string, message []byte) (*http.Response, error)

func (*GlipWebhookClient) PostWebhookV2

func (client *GlipWebhookClient) PostWebhookV2(url string, message v2.GlipWebhookMessage) (*http.Response, error)

type GlipWebhookError

type GlipWebhookError struct {
	Code           string                   `json:"code,omitempty"`
	Message        string                   `json:"message,omitempty"`
	HttpStatusCode int                      `json:"http_status_code,omitempty"`
	ResponseData   string                   `json:"response_data,omitempty"`
	Response       GlipWebhookErrorResponse `json:"response,omitempty"`
}

func (*GlipWebhookError) Inflate

func (gwerr *GlipWebhookError) Inflate()

type GlipWebhookErrorResponse

type GlipWebhookErrorResponse struct {
	Code       string `json:"code"`
	Message    string `json:"message"`
	Validation bool   `json:"validation"`
}

type GlipWebhookMessage

type GlipWebhookMessage struct {
	Icon           string       `json:"icon,omitempty"`
	Activity       string       `json:"activity,omitempty"`
	Title          string       `json:"title,omitempty"`
	Body           string       `json:"body,omitempty"`
	AttachmentType string       `json:"attachment_type,omitempty"`
	Attachments    []Attachment `json:"attachments,omitempty"`
}

type GlipWebhookResponse

type GlipWebhookResponse struct {
	Status  string           `json:"status,omitempty"`
	Message string           `json:"message,omitempty"`
	Error   GlipWebhookError `json:"error,omitempty"`
}

type WebhookURL added in v0.3.3

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

func NewWebhookURL added in v0.3.3

func NewWebhookURL(input string) (WebhookURL, error)

func (*WebhookURL) Id added in v0.3.3

func (w *WebhookURL) Id() string

func (*WebhookURL) IsGUID added in v0.3.3

func (w *WebhookURL) IsGUID() bool

func (*WebhookURL) OriginalInput added in v0.3.3

func (w *WebhookURL) OriginalInput() string

func (*WebhookURL) OriginalVersion added in v0.3.3

func (w *WebhookURL) OriginalVersion() int

func (*WebhookURL) V1URL added in v0.3.3

func (w *WebhookURL) V1URL() string

func (*WebhookURL) V2URL added in v0.3.3

func (w *WebhookURL) V2URL() string

Directories

Path Synopsis
cmd
bot_rest command
find_team command
post_attachment command
post_simple command
test_post command
upload_file command
webhook_inbound command
cmd/build command

Jump to

Keyboard shortcuts

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