clova-cek-sdk-go

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0

README

Clova CEK SDK Go

Go SDK for the Clova Extensions

About Clova Extension Kit

See the official documentation for more information.

Installation

$ go get github.com/line/clova-cek-sdk-go/cek

Usage

package main

import (
	"encoding/json"
	"log"
	"net/http"

	"github.com/line/clova-cek-sdk-go/cek"
)

func main() {
	ext := cek.NewExtension("com.example.my_extension")
	http.HandleFunc("/callback", func(w http.ResponseWriter, r *http.Request) {
		message, err := ext.ParseRequest(r)
		if err != nil {
			log.Printf("invalid request")
			http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
			return
		}

		var response *cek.ResponseMessage
		switch request := message.Request.(type) {
		case *cek.IntentRequest:
			switch request.Intent.Name {
			case "Clova.GuideIntent":
				response = cek.NewResponseBuilder().
					OutputSpeech(
						cek.NewOutputSpeechBuilder().
							AddSpeechText("話しかけてください", cek.SpeechInfoLangJA).
							Build()).
					Build()
			}
		case *cek.LaunchRequest:
			response = cek.NewResponseBuilder().
				OutputSpeech(
					cek.NewOutputSpeechBuilder().
						AddSpeechText("起動しました", cek.SpeechInfoLangJA).
						Build()).
				Build()
		}
		if response != nil {
			if err := json.NewEncoder(w).Encode(response); err != nil {
				http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
				return
			}
		}
	})
	if err := http.ListenAndServe(":8080", nil); err != nil {
		log.Fatal(err)
	}
}

LICENSE

See LICENSE.txt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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