Skip to content

Instantly share code, notes, and snippets.

@YMA-MDL
Last active October 28, 2016 07:49
Show Gist options
  • Select an option

  • Save YMA-MDL/eda980f37cd1186fe533 to your computer and use it in GitHub Desktop.

Select an option

Save YMA-MDL/eda980f37cd1186fe533 to your computer and use it in GitHub Desktop.
// retrieve the document name
String documentName = this.getProperty("name");
// retrieve the document id
String documentID = this.getID();
// create the POST web request
var httpWebRequest = (HttpWebRequest) WebRequest.Create("https://hooks.slack.com/services/XXXXX/XXXXX/XXXXXXXXXX");
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
// send message content
using(var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) {
string BaseUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.Replace("Server","").TrimEnd('/') + "/";
string ItemUrl = "Client/default.aspx?StartItem={0}:{1}";
string FullUrl = BaseUrl + String.Format(ItemUrl, this.getType(), this.getID());
var obj = new Dictionary<string, string>
{
{ "title", "Document Release"},
{ "title_link", FullUrl},
{ "text", "Document " + documentName +" has been released. \n <"+FullUrl+"|Click here>" }
};
var jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var json = jsSerializer.Serialize(obj);
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
// Get web service call response
var httpResponse = (HttpWebResponse) httpWebRequest.GetResponse();
using(var streamReader = new StreamReader(httpResponse.GetResponseStream())) {
var result = streamReader.ReadToEnd();
}
return this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment