-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlackMessageWriter.cs
More file actions
30 lines (26 loc) · 944 Bytes
/
Copy pathSlackMessageWriter.cs
File metadata and controls
30 lines (26 loc) · 944 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
30
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Slack_App
{
class SlackMessageWriter
{
private readonly string _url;
private readonly HttpClient _client;
public SlackMessageWriter(string token)
{
_url = "https://slack.com/api/chat.postMessage";
_client = new HttpClient();
_client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
}
public async Task WriteMessage(string message)
{
var postObject = new { channel = "#general", text = message };
var json = JsonConvert.SerializeObject(postObject);
var content = new StringContent(json, Encoding.UTF8, "application/json");
await _client.PostAsync(_url, content);
}
}
}