glip

package module
v0.5.14 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 15 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/"                 // #nosec G101
	GlipWebhookV2BaseURLProduction = "https://hooks.ringcentral.com/webhook/v2/"              // #nosec G101
	GlipWebhookV1BaseURLSandbox    = "https://hooks-glip.devtest.ringcentral.com/webhook/"    // #nosec G101
	GlipWebhookV2BaseURLSandbox    = "https://hooks-glip.devtest.ringcentral.com/webhook/v2/" // #nosec G101
	AttachmentTypeCard             = "Card"
	HeaderValidationToken          = "Validation-Token"
)

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 PostFile added in v0.5.0

func PostFile(client *http.Client, serverURL, groupID, path string) (*http.Response, error)

func V1ToV2WebhookAttachment

func V1ToV2WebhookAttachment(v1att Attachment) v2.Attachment

func V1ToV2WebhookBody

func V1ToV2WebhookBody(v1msg GlipWebhookMessage) v2.GlipWebhookMessage

func V1ToV2WewbhookURI added in v0.5.0

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 GenericEvent added in v0.5.0

type GenericEvent struct {
	UUID           string    `json:"uuid,omitempty"`
	Event          string    `json:"event,omitempty"`
	Timestamp      time.Time `json:"timestamp,omitempty"`
	SubscriptionID string    `json:"subscriptionId,omitempty"`
	OwnerID        string    `json:"ownerId,omitempty"`
}

type GlipEvent added in v0.5.0

type GlipEvent struct {
	UUID           string          `json:"uuid,omitempty"`
	Event          string          `json:"event,omitempty"`
	Timestamp      time.Time       `json:"timestamp,omitempty"`
	SubscriptionID string          `json:"subscriptionId,omitempty"`
	OwnerID        string          `json:"ownerId,omitempty"`
	Body           TextMessageBody `json:"body,omitempty"`
}

type GlipEventMention added in v0.5.0

type GlipEventMention struct {
	ID   string `json:"id,omitempty"`
	Type string `json:"type,omitempty"`
	Name string `json:"name,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

func NewGlipWebhookClientFast

func NewGlipWebhookClientFast(urlOrGUID string, webhookVersion int) GlipWebhookClient

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 TextMessageBody added in v0.5.0

type TextMessageBody struct {
	ID               string             `json:"id,omitempty"`
	GroupID          string             `json:"groupId,omitempty"`
	Type             string             `json:"type,omitempty"`
	Text             string             `json:"text,omitempty"`
	CreatorID        string             `json:"creatorId,omitempty"`
	CreationTime     time.Time          `json:"creationTime,omitempty"`
	LastModifiedTime time.Time          `json:"lastModifiedTime,omitempty"`
	Mentions         []GlipEventMention `json:"mentions,omitempty"`
	EventType        string             `json:"eventType,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.5.0

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

Jump to

Keyboard shortcuts

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