Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. func Twit(w http.ResponseWriter, r *http.Request) {
  2. defaultResponse := &SlashResponse{ResponseType: "ephemeral", Text: "success"}
  3.  
  4. // prepare to make a slack delayed response
  5. responseURL := r.FormValue("response_url")
  6. go sendDelayResponse(responseURL, r)
  7.  
  8. w.Header().Set("Content-Type", "application/json")
  9. w.WriteHeader(200)
  10. json.NewEncoder(w).Encode(defaultResponse)
  11. }
  12.  
  13. func sendDelayResponse(url string, r *http.Request) {
  14. response := &SlashResponse{ResponseType: "in_channel", Text: twit.TweetTCL(r)}
  15. b, _ := json.Marshal(response)
  16.  
  17. // send request to slack using given response_url
  18. ctx := appengine.NewContext(r)
  19. client := urlfetch.Client(ctx)
  20. req, _ := http.NewRequest("POST", url, bytes.NewBuffer(b))
  21. req.Header.Add("Content-Type", "application/json")
  22. resp, err := client.Do(req)
  23. defer resp.Body.Close()
  24.  
  25. if err != nil {
  26. log.Println(err)
  27. } else {
  28. log.Println("success")
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement