rchooks

package module
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2023 License: MIT Imports: 14 Imported by: 0

README

RCHooks - RingCentral Webhook Tools

Build Status Go Report Card Docs License Video

rchooks is a toolset for creating, listing, recreating, and deleting RingCentral webhooks. It is especially useful in development when working with ngrok and when webhooks are blocked when test servers are taken down and non-responsive. It includes the following:

  • rchooks CLI app
  • keepalive_lambda AWS Lambda function to check and rebuild webhook when blacklisted
  • rchooks SDK package for utilities to build your own apps

YouTube Tutorial Video: https://youtu.be/DYrzzJe8OyI

Apps

CLI App
CLI Installation
$ go install github.com/grokify/rchooks/cmd/rchooks
$ rchooks --env=/path/to/.env --list

Prior to Go 1.18, use go get:

$ go get github.com/grokify/rchooks/cmd/rchooks
$ rchooks --env=/path/to/.env --list
CLI Usage

By default, rchooks looks for an environment file path specified by the ENV_PATH environment variable or a .env file in the current working directory. You can also explicitly specify a .env file with the --env path parameter.

$ rchooks --list
$ rchooks --create=https://example.com/webhook
$ rchooks --recreate=https://example.com/webhook
$ rchooks --recreate=11112222-3333-4444-5555-66667777888
$ rchooks --delete=https://example.com/webhook
$ rchooks --delete=11112222-3333-4444-5555-66667777888

Configure OAuth by setting the oauth2more/credentials file via --creds and the account via --account.

Set the following enviroment variables:

  • RINGCENTRAL_WEBHOOK_DEFINITION_JSON - Create subscription JSON body
Example Webhook Definition

An example value for RINGCENTRAL_WEBHOOK_DEFINITION_JSON can be the following. For a long lived webhook, use a value like 500000000 seconds which is equivalent to 15.85 years.

{
  "eventFilters":[
    "/restapi/v1.0/glip/posts",
    "/restapi/v1.0/glip/groups",
    "/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS"
  ],
  "deliveryMode":{
    "transportType":"WebHook",
    "address":"https://12345678.execute-api.us-east-1.amazonaws.com/prod/webhook"
  },
  "expiresIn":500000000
 }

Compact example:

{"eventFilters":["/restapi/v1.0/glip/posts","/restapi/v1.0/glip/groups","/restapi/v1.0/account/~/extension/~/message-store/instant?type=SMS"],"deliveryMode":{"transportType":"WebHook","address":"https://12345678.execute-api.us-east-1.amazonaws.com/prod/webhook"},"expiresIn":500000000}

Keepalive Lambda Function
Installation

Build the lambda function and then upload to AWS:

$ go get github.com/grokify/rchooks
$ cd $GOPATH/src/github.com/grokify/rchooks/apps/keepalive_lambda
$ sh build_lambda.sh

Set the following enviroment variables:

  • RINGCENTRAL_TOKEN - JSON string or simple access token string
  • RINGCENTRAL_SERVER_URL
  • RINGCENTRAL_WEBHOOK_DEFINITION_JSON - Create subscription JSON body

Notes

Blacklist Reasons
  • I/O operation is failed. Details: [Read timed out]
  • Webhook response exceeds max size. Read bytes count: [1024]
  • Webhook responses with code: [404], reason: [Not Found]

Documentation

Index

Constants

View Source
const (
	EventFilterExtension     = "/restapi/v1.0/account/~/extension/~"
	EventFilterMessagePosts  = "/restapi/v1.0/glip/posts"
	EventFilterMessageGroups = "/restapi/v1.0/glip/groups"
	EventFilterSmsInbound    = "/restapi/v1.0/account/~/a2p-sms/messages?direction=Inbound"
	EventFilterSmsBatch      = "/restapi/v1.0/account/~/a2p-sms/batch"
	EventFilterSmsOptOuts    = "/restapi/v1.0/account/~/a2p-sms/opt-outs"

	SlugExtension     = "extension"
	SlugMessageGroups = "msggroups"
	SlugMessagePosts  = "msgposts"
	SlugSmsBatch      = "a2psmsbatch"
	SlugSmsInbound    = "a2psmsinbound"
	SlugSmsOptOuts    = "a2psmsoptouts"
)
View Source
const (
	WebhookStatusBlacklisted     = "Blacklisted"
	RingCentralAPIResponseFormat = `RingCentral_API_Status_Code [%v]`
	ExpiresMax                   = 499999999 // 15 years
	HeaderValidationToken        = "Validation-Token"
	TransportTypePubNub          = "PubNub"
	TransportTypeWebHook         = "WebHook"
)

Variables

This section is empty.

Functions

func ConvertEvent added in v0.4.0

func ConvertEvent(slug string) (string, error)

func ConvertEvents added in v0.4.0

func ConvertEvents(slugs ...string) ([]string, error)

func FilterSubscriptionsForRequest added in v0.3.0

func FilterSubscriptionsForRequest(ress []rc.SubscriptionResponse, req rc.CreateSubscriptionRequest) []rc.SubscriptionResponse

func NewCreateSubscriptionRequestPermahook added in v0.3.0

func NewCreateSubscriptionRequestPermahook(eventFilters []string, hookURL string) rc.CreateSubscriptionRequest

func NewCreateSubscriptionRequestPermahookBotSimple added in v0.3.0

func NewCreateSubscriptionRequestPermahookBotSimple(hookURL string) rc.CreateSubscriptionRequest

func ParseCreateSubscriptionRequest added in v0.3.0

func ParseCreateSubscriptionRequest(data []byte) (rc.CreateSubscriptionRequest, error)

func SlugToFilterMap added in v0.4.0

func SlugToFilterMap() map[string]string

Types

type RcHooks added in v0.3.0

type RcHooks struct {
	Client *rc.APIClient
}

func (*RcHooks) CheckAndFixSubscription added in v0.3.0

func (util *RcHooks) CheckAndFixSubscription(ctx context.Context, req rc.CreateSubscriptionRequest) (rc.SubscriptionInfo, error)

func (*RcHooks) CreateSubscription added in v0.3.0

func (util *RcHooks) CreateSubscription(ctx context.Context, req rc.CreateSubscriptionRequest) (rc.SubscriptionInfo, error)

func (*RcHooks) DeleteBlacklisted added in v0.3.0

func (util *RcHooks) DeleteBlacklisted(ctx context.Context, matches []rc.SubscriptionResponse) ([]rc.SubscriptionResponse, error)

func (*RcHooks) DeleteByIDOrURL added in v0.5.0

func (util *RcHooks) DeleteByIDOrURL(ctx context.Context, idOrURLToDelete string) ([]rc.SubscriptionResponse, error)

func (*RcHooks) DeleteSubscription added in v0.3.0

func (util *RcHooks) DeleteSubscription(ctx context.Context, subscriptionID string) error

func (*RcHooks) GetSubscriptions added in v0.3.0

func (*RcHooks) RecreateSubscriptionIDOrURL added in v0.5.0

func (util *RcHooks) RecreateSubscriptionIDOrURL(ctx context.Context, subIDOrURL string) ([]rc.SubscriptionInfo, error)

type RcHooksConfig added in v0.3.0

type RcHooksConfig struct {
	Token                 string `env:"RINGCENTRAL_TOKEN"`
	ServerURL             string `env:"RINGCENTRAL_SERVER_URL"`
	WebhookDefinitionJSON string `env:"RINGCENTRAL_WEBHOOK_DEFINITION_JSON"`
	WebhookDefinition     rc.CreateSubscriptionRequest
}

func NewRcHooksConfigCreds added in v0.3.0

func NewRcHooksConfigCreds(creds goauth.Credentials, hookDefJSON string) (RcHooksConfig, error)

func NewRcHooksConfigEnv added in v0.3.0

func NewRcHooksConfigEnv(envVarTokenOrJSON, envVarServerURL, envVarHookDef string) RcHooksConfig

func (*RcHooksConfig) Client added in v0.3.0

func (rchConfig *RcHooksConfig) Client() (*http.Client, error)

func (*RcHooksConfig) ClientUtil added in v0.3.0

func (rchConfig *RcHooksConfig) ClientUtil() (ringcentral.ClientUtil, error)

func (*RcHooksConfig) Inflate added in v0.3.0

func (rchConfig *RcHooksConfig) Inflate() error

func (*RcHooksConfig) InitializeRcHooks added in v0.4.0

func (rchConfig *RcHooksConfig) InitializeRcHooks(ctx context.Context) (RcHooks, error)

type WebhookDefinitionThin added in v0.3.0

type WebhookDefinitionThin struct {
	URL          string   `json:"url"`
	EventFilters []string `json:"eventFilters"`
}

func (*WebhookDefinitionThin) Full added in v0.3.0

Directories

Path Synopsis
cmd
main.go

Jump to

Keyboard shortcuts

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