Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func Twit(w http.ResponseWriter, r *http.Request) {
- defaultResponse := &SlashResponse{ResponseType: "ephemeral", Text: "success"}
- // prepare to make a slack delayed response
- responseURL := r.FormValue("response_url")
- go sendDelayResponse(responseURL, r)
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(200)
- json.NewEncoder(w).Encode(defaultResponse)
- }
- func sendDelayResponse(url string, r *http.Request) {
- response := &SlashResponse{ResponseType: "in_channel", Text: twit.TweetTCL(r)}
- b, _ := json.Marshal(response)
- // send request to slack using given response_url
- ctx := appengine.NewContext(r)
- client := urlfetch.Client(ctx)
- req, _ := http.NewRequest("POST", url, bytes.NewBuffer(b))
- req.Header.Add("Content-Type", "application/json")
- resp, err := client.Do(req)
- defer resp.Body.Close()
- if err != nil {
- log.Println(err)
- } else {
- log.Println("success")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement