New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/ignaci0/okgohook

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ignaci0/okgohook

  • v0.2.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

ignaci0/okgohook

This module, composed by two packages provides the means to implement fulfillment service webhooks so Actions On Google can send to a running server.

It's important to remark this module does not implement DialogFlow fulfillments but fulfillment services for the new conversational actions.

This module's features include:

  • Implementation of http.Handler interface so that it is compatible with http.ServeMux (and other modules such as gorilla/mux)
  • It provides data types for the fulfillment requests (complete) and response (partial) ; missing ones can be introduced later by comunity or myself upon need
  • It implements HealthCheck system intent route
  • It supports request verification by validating JWT received and the intended audience
  • Additional matching rules out of the box: locale and handler
  • Matcher interface to introduce custom request matchers

To get started building your own actions this is the place to go.

Since actions can be run in alfa channel, this is quite convenient to run home server's automated tasks.


Install

Assuming go toolchain is available:

go get github.com/ignaci0/okgohook

Examples

Hello World

Just because:

webhookRouter := okgohook.NewRouter()
webhookRouter.HandleIntent("hello", func (req *aog.FulfillmentRequest) *aog.FulfillmentResponse {
	return &aog.FulfillmentResponse {
		Prompt: &aog.Prompt {
			FirstSimple: &aog.Simple { Speech: "Hello World!" },
		},
	}
}) 

//Let's use gorilla/mux for this sample:
router := mux.NewRouter()
router.Handle("/webhook", webhookRouter)
//It plays well with other handlers, e.g.:
//router.PathPrefix("/").Handler...

srv := &http.Server {
	Handler: router,
	Address: ":8080",
	WriteTimeout: 2 * time.Second,
	ReadTimeout: 2 * time.Second,
}

log.Fatal(srv.ListenAndServe())

Basic Echo

This sample fulfillment function talks back the user request:

webhookRouter := okgohook.NewRouter()
webhookRouter.HandleIntent("hello", func (req *aog.FulfillmentRequest) *aog.FulfillmentResponse {
	return &aog.FulfillmentResponse {
		Prompt: &aog.Prompt {
			FirstSimple: &aog.Simple { Speech: req.Intent.Query },
		},
	}
}) 

With additional matches

webhookRouter := okgohook.NewRouter()

webhookRouter.HandleIntent("hello", func (req *aog.FulfillmentRequest) *aog.FulfillmentResponse { }).WithHandler("world").WithLocaleLike("EN")
webhookRouter.HandleIntent("hello", func (req *aog.FulfillmentRequest) *aog.FulfillmentResponse { }).WithHandler("world").WithLocaleLike("ES")

With token verification and authorization

Currently it is not possible to verify the token without audience verification.

webhookRouter := okgohook.NewRouter().Authorize("my-app")

When the newly created router is provided with an audience, a goroutine is launched to retrieve and keep up to date the signing token certificates. This means the server shall require access to the internet to retrieve them.

TO-DOs/Roadmap

  • Remove unnecessary logging and add a logger facility/middlewares
  • Implement missing response types
  • Change the certificates verifications to a newer keys url
  • Add proxy support for certificates retrieval
  • Find a way to get rid off the aog package by autogenerating code for from the gRPC specification

FAQs

Package last updated on 21 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc