Documentation ¶
Index ¶
- Constants
- Variables
- func ErrUnmarshalWrapper(site string, err error) error
- type HandlerFunc
- type Server
- func (s *Server) HandleCx(pattern string, handler HandlerFunc)
- func (s *Server) Init(ctx context.Context, addr string, lg *log.Logger, signals ...os.Signal) *Server
- func (s *Server) ListenAndServe(ctx context.Context)
- func (s *Server) Reconfigure() error
- func (s *Server) ServeMux() *http.ServeMux
- func (s *Server) SetHandler(h http.Handler)
- func (s *Server) Shutdown(ctx context.Context) error
- type WebhookRequest
- func (req *WebhookRequest) Context() context.Context
- func (req *WebhookRequest) CopyPageInfo(res *WebhookResponse)
- func (req *WebhookRequest) CopyPayload(res *WebhookResponse) *WebhookResponse
- func (req *WebhookRequest) CopySessionInfo(res *WebhookResponse) *WebhookResponse
- func (req *WebhookRequest) GetPageFormParameters() map[string]any
- func (req *WebhookRequest) GetPayload() map[string]any
- func (req *WebhookRequest) GetPayloadParameter(key string) (any, bool)
- func (req *WebhookRequest) GetSessionParameter(key string) (any, bool)
- func (req *WebhookRequest) GetSessionParameters() map[string]any
- func (req *WebhookRequest) InitializeResponse() *WebhookResponse
- func (req *WebhookRequest) Logger() *log.Logger
- func (req *WebhookRequest) ReadReader(rd io.Reader) error
- func (req *WebhookRequest) ReadRequest(r *http.Request) error
- func (req *WebhookRequest) TestCxHandler(out io.Writer, h HandlerFunc) (*WebhookResponse, error)
- func (req *WebhookRequest) WriteRequest(w io.Writer) error
- type WebhookResponse
- func (res *WebhookResponse) AddOutputAudioTextResponse(ssml string)
- func (res *WebhookResponse) AddPayload(m map[string]any) error
- func (res *WebhookResponse) AddSessionParameters(m map[string]any) error
- func (res *WebhookResponse) AddTextResponse(txts ...string)
- func (res *WebhookResponse) SetPayload(m map[string]any) error
- func (res *WebhookResponse) SetSessionParameters(m map[string]any) error
- func (res *WebhookResponse) WriteResponse(w io.Writer) error
Constants ¶
const (
Logger contextKey = iota
)
Variables ¶
Functions ¶
func ErrUnmarshalWrapper ¶
Types ¶
type HandlerFunc ¶
type HandlerFunc func(*WebhookResponse, *WebhookRequest) error
HandlerFunc is an adapter that converts a given ezcx.HandlerFunc into an http.Handler.
func (HandlerFunc) ServeHTTP ¶
func (h HandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)
Implementing ServeHTTP allows the ezcx.HandlerFunc to satisfy the http.Handler interface.
Error handling is an area of future improvement. For instance, if a required parameter is missing, it should be up to the developer to handle that i.e.: return an HTTP error (400, 500) or return a ResponseMessage indicating something went wrong...
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) HandleCx ¶
func (s *Server) HandleCx(pattern string, handler HandlerFunc)
HandleCx registers the handler for the given pattern. While the HandleCx method itself isn't safe for concurrent usage, the underlying method it wraps (*ServeMux).Handle IS guarded by a mutex.
func (*Server) ListenAndServe ¶
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. ListenAndServe is responsible for handling signals and managing graceful shutdown(s) whenever the right signals are intercepted.
func (*Server) SetHandler ¶
SetHandler allows the user to set a custom mux or handler.
type WebhookRequest ¶
type WebhookRequest struct { cx.WebhookRequest // contains filtered or unexported fields }
func NewTestingWebhookRequest ¶
func NewTestingWebhookRequest(session, payload, pageform map[string]any) (*WebhookRequest, error)
Testing
func NewWebhookRequest ¶
func NewWebhookRequest() *WebhookRequest
func WebhookRequestFromReader ¶
func WebhookRequestFromReader(rd io.Reader) (*WebhookRequest, error)
yaquino@2022-10-11: Dialogflow CX API May include "extra" fields that may throw errors and interface with protojson.Unmarshal. As per the documentation, these fields may be ignored. Now also pointing at req.WebhookRequest for unmarshalling..
func WebhookRequestFromRequest ¶
func WebhookRequestFromRequest(r *http.Request) (*WebhookRequest, error)
yaquino@2022-10-07: Refactored to flow http.Request's context to the WebhookRequest instance.
func (*WebhookRequest) Context ¶
func (req *WebhookRequest) Context() context.Context
func (*WebhookRequest) CopyPageInfo ¶
func (req *WebhookRequest) CopyPageInfo(res *WebhookResponse)
func (*WebhookRequest) CopyPayload ¶
func (req *WebhookRequest) CopyPayload(res *WebhookResponse) *WebhookResponse
func (*WebhookRequest) CopySessionInfo ¶
func (req *WebhookRequest) CopySessionInfo(res *WebhookResponse) *WebhookResponse
func (*WebhookRequest) GetPageFormParameters ¶
func (req *WebhookRequest) GetPageFormParameters() map[string]any
func (*WebhookRequest) GetPayload ¶
func (req *WebhookRequest) GetPayload() map[string]any
func (*WebhookRequest) GetPayloadParameter ¶
func (req *WebhookRequest) GetPayloadParameter(key string) (any, bool)
func (*WebhookRequest) GetSessionParameter ¶
func (req *WebhookRequest) GetSessionParameter(key string) (any, bool)
func (*WebhookRequest) GetSessionParameters ¶
func (req *WebhookRequest) GetSessionParameters() map[string]any
func (*WebhookRequest) InitializeResponse ¶
func (req *WebhookRequest) InitializeResponse() *WebhookResponse
func (*WebhookRequest) ReadReader ¶
func (req *WebhookRequest) ReadReader(rd io.Reader) error
func (*WebhookRequest) ReadRequest ¶
func (req *WebhookRequest) ReadRequest(r *http.Request) error
func (*WebhookRequest) TestCxHandler ¶
func (req *WebhookRequest) TestCxHandler(out io.Writer, h HandlerFunc) (*WebhookResponse, error)
yaquino: 2022-10-08Review this...!
func (*WebhookRequest) WriteRequest ¶
func (req *WebhookRequest) WriteRequest(w io.Writer) error
Is this the right format??
type WebhookResponse ¶
type WebhookResponse struct {
cx.WebhookResponse
}
func NewWebhookResponse ¶
func NewWebhookResponse() *WebhookResponse
func (*WebhookResponse) AddOutputAudioTextResponse ¶
func (res *WebhookResponse) AddOutputAudioTextResponse(ssml string)
func (*WebhookResponse) AddPayload ¶
func (res *WebhookResponse) AddPayload(m map[string]any) error
func (*WebhookResponse) AddSessionParameters ¶
func (res *WebhookResponse) AddSessionParameters(m map[string]any) error
func (*WebhookResponse) AddTextResponse ¶
func (res *WebhookResponse) AddTextResponse(txts ...string)
func (*WebhookResponse) SetPayload ¶
func (res *WebhookResponse) SetPayload(m map[string]any) error
func (*WebhookResponse) SetSessionParameters ¶
func (res *WebhookResponse) SetSessionParameters(m map[string]any) error
func (*WebhookResponse) WriteResponse ¶
func (res *WebhookResponse) WriteResponse(w io.Writer) error
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
context-and-logging
Module
|
|
dependency-injection
Module
|
|
hussains-hedgetrimmer
Module
|
|
webhook-quickstart
Module
|
|
gcp
|
|