Skip to content

darimuri/clova-cek-sdk-go

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Clova CEK SDK Go

Go SDK for the Clova Extensions

About Clova Extension Kit

See the official documentation for more information. (References changes to naver from line)

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

Packages

No packages published

Languages

  • Go 100.0%