Skip to content
SDK of the Clova CEK for Go
Go
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
cek Add properties to Slot Jun 5, 2019
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.txt
README.md

README.md

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

You can’t perform that action at this time.