-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQuickSlack.cs
39 lines (38 loc) · 1.52 KB
/
QuickSlack.cs
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
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Countersoft.Foundation.Commons.Extensions;
namespace TSJ.Gemini.Slack
{
public static class QuickSlack
{
public static void Send(string slackApiUrl, string channel, string text, string fallback = null, string color = null, object[] fields = null, string fieldsText = null){
//this method could and should be a one-liner
var o = new
{
channel = channel,
username = "Gemini",
link_names = 1,
icon_emoji = ":traffic_light:",
text = text,
attachments = (fields != null && fields.Length > 0) ? new[] {
new
{
fallback = fallback,
text = fieldsText,
//pretext = "",
color = color,
fields = fieldsText.HasValue() ? null : fields
}
}
: null
};
var wc = new WebClient();
wc.UploadString(new Uri(slackApiUrl),
o.ToJson().Replace("\"_short\"", "\"short\""));
}
}
}