-
Notifications
You must be signed in to change notification settings - Fork 5
/
nexmo.go
33 lines (30 loc) · 911 Bytes
/
nexmo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"log"
"net/http"
)
//NexmoHandler handles the GET requests from nexmo
func NexmoHandler(w http.ResponseWriter, r *http.Request) {
//A sample request from the nexmo service is
//?msisdn=19150000001&to=12108054321
//&messageID=000000FFFB0356D1&text=This+is+an+inbound+message
//&type=text&message-timestamp=2012-08-19+20%3A38%3A23
//So we read all those parameters
messageID := r.FormValue("messageID")
text := r.FormValue("text")
typ := r.FormValue("type")
timestamp := r.FormValue("message-timestamp=")
if len(text) > 0 && typ == "text" {
intent, err := FetchIntent(text)
if err != nil {
log.Printf("Error: %+v", err)
} else {
ret := ProcessIntent(intent)
log.Printf("We got messageID: %v on %v ", messageID, timestamp)
log.Printf("Wit gave us: %+v ", ret)
}
} else {
log.Print("Error: we got a blank text message")
}
w.WriteHeader(http.StatusOK)
}