add cloud function source to git

This commit is contained in:
olemorud
2022-12-07 17:54:31 +01:00
commit 6f66aab5cf
2 changed files with 44 additions and 0 deletions

43
function.go Normal file
View File

@@ -0,0 +1,43 @@
import (
"encoding/json"
"log"
"net/http"
)
type reply struct {
Response_type string `json:"response_type"`
Text string `json:"text"`
}
// HelloWorld prints the JSON encoded "message" field in the body
// of the request or "Hello, World!" if there isn't one.
func Coffee(writer http.ResponseWriter, request *http.Request) {
var data struct {
Message string `json:"message"`
Channel_id string `json:"channel_id"`
Channel_name string `json:"channel_name"`
Team_domain string `json:"team_domain"`
Team_id string `json:"team_id"`
Post_id string `json:"post_id"`
Text string `json:"text"`
Timestamp int64 `json:"timestamp"`
Token string `json:"token"`
Trigger_word string `json:"trigger_word"`
User_id string `json:"user_id"`
User_name string `json:"user_name"`
}
err := json.NewDecoder(request.Body).Decode(&data)
if err != nil {
log.Printf("json.NewDecoder: %v\n", err)
http.Error(writer, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
log.Printf("%+v", data.User_id)
if data.Token == "moha5q8xqjg9prbq7q73676z9y" || data.Token == "33szr8spqi8tx81ymdsxpq5mjh" {
json.NewEncoder(writer).Encode(&reply{Response_type: "comment", Text: "@omorud @ksarband @psvihra"})
}
}

1
go.mod Normal file
View File

@@ -0,0 +1 @@
module example.com/cloudfunction