-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlackIntegration.cs
More file actions
29 lines (24 loc) · 829 Bytes
/
Copy pathSlackIntegration.cs
File metadata and controls
29 lines (24 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System.Net;
using System.IO;
namespace SlackIntegration
{
public class SlackBot
{
public int Send(string url, string data)
{
var httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.ContentType = "application/json";
using (var streamWriter = new StreamWriter(httpRequest.GetRequestStream()))
{
streamWriter.Write("{\"text\":\"" + data + "\"}");
}
var httpResponse = (HttpWebResponse)httpRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
return (int)httpResponse.StatusCode;
}
}
}