webhook-quickstart

command module
v0.0.0-...-ac68d48 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

README

Refactored Webhook Quickstart Example

Source Code

// ezcx/examples/webhook-quickstart is a refactoring of the Google Cloud provided
// Go webhook quickstart: https://cloud.google.com/dialogflow/cx/docs/quick/webhook 
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/yaq-cc/ezcx"
)

var (
	PORT = os.Getenv("PORT")
)

func main() {
	ctx := context.Background()
	lg := log.Default()
	server := ezcx.NewServer(ctx, ":"+PORT, lg)
	server.HandleCx("/confirm", cxConfirm)
	server.ListenAndServe(ctx)
}

func cxConfirm(res *ezcx.WebhookResponse, req *ezcx.WebhookRequest) error {
	params := req.GetSessionParameters()

	size := params["size"]
	color := params["color"]

	res.AddTextResponse(
		fmt.Sprintf("You can pick up your order for a %s %s shirt in 5 days.",
			size, color),
	)
	params["cancel-period"] = "2"
	res.AddSessionParameters(params)
	return nil
}

Documentation

Overview

ezcx/examples/webhook-quickstart is a refactoring of the Google Cloud provided Go webhook quickstart: https://cloud.google.com/dialogflow/cx/docs/quick/webhook

Jump to

Keyboard shortcuts

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