Not so much a question as help for others having this problem. Took a fair amount of beating my head against a wall to make this work. (as much I as love golang, you do have think a little differently) - This will also work as a generic way to do any sort of post to an outside source in AppEngine.
Here is the function I am using to post simple messages to a slack channel via webhook. (assumes you know how to set up a webhook in slack - very easy to do - https://get.slack.help/hc/en-us/articles/115005265063-Incoming-WebHooks-for-Slack ) - NOTE: while there are a fair # of additional parameters you can pass in the json message (see link above) simple things like email addresses and image urls / web addresses will be automatically parsed by slack if passed in the 'text' parameter.
import (
"bytes"
"google.golang.org/appengine"
"google.golang.org/appengine/urlfetch"
"net/http"
)
func postSlackBetaSignup(req *http.Request, msg string) string {
ctx := appengine.NewContext(req);
request := urlfetch.Client(ctx);
data := []byte("{'text': '" + msg + "'}");
body := bytes.NewReader(data);
resp, err := request.Post("https://hooks.slack.com/services/<<<YOUR WEBHOOK HERE>>>", "application/json", body);
if err != nil {
return err.Error();
} else {
return resp.Status;
}
}
import (
"bytes"
"google.golang.org/appengine"
"google.golang.org/appengine/urlfetch"
"net/http"
)
func postSlackBetaSignup(req *http.Request, msg string) string {
ctx := appengine.NewContext(req);
request := urlfetch.Client(ctx);
data := []byte("{'text': '" + msg + "'}");
body := bytes.NewReader(data);
resp, err := request.Post("https://hooks.slack.com/services/<<<YOUR WEBHOOK HERE>>>", "application/json", body);
if err != nil {
return err.Error();
} else {
return resp.Status;
}
}