ailistener-old

The central Server which transports webhook events from the Dialogflow bot to the local nodes
git clone git://archive.git.mtrnord.blog/OpenHomeAuto/ailistener-old.git
Log | Files | Refs | README | LICENSE

commit b5c45513651a6830f6c3aa7cc3b265775b43a9e8
parent a4b759ac01d67c2fb8ca56a33ac9933aaf0fe170
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sat,  2 Jun 2018 10:37:58 +0200

Make parsing more robust and add dummy response

Diffstat:
MwsListener/server.go | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/wsListener/server.go b/wsListener/server.go @@ -22,13 +22,27 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) { } func DFHandler(w http.ResponseWriter, r *http.Request) { - var dfr *df.Request + var dfr df.Request + if r.Body == nil { + http.Error(w, "Please send a request body", http.StatusNotAcceptable) + return + } + defer r.Body.Close() decoder := json.NewDecoder(r.Body) - err := decoder.Decode(dfr) + err := decoder.Decode(&dfr) if err != nil { - w.WriteHeader(http.StatusInternalServerError) + http.Error(w, err.Error(), http.StatusInternalServerError) } - w.WriteHeader(http.StatusAccepted) log.Printf("%v", dfr) + + // Send back a fulfillment + dff := &df.Fulfillment{ + FulfillmentMessages: df.Messages{ + df.ForGoogle(df.SingleSimpleResponse("hello", "hello")), + {RichMessage: df.Text{Text: []string{"hello"}}}, + }, + } + json.NewEncoder(w).Encode(dff) + w.WriteHeader(http.StatusOK) }