From 90d4f1e32a7b5fe98dc3604923d57c898b72e9d6 Mon Sep 17 00:00:00 2001 From: Todd Justin York Date: Mon, 21 Jan 2019 18:32:01 +0800 Subject: [PATCH 001/102] Synced exposing apis with SlackClient --- SlackAPI/SlackTaskClient.cs | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/SlackAPI/SlackTaskClient.cs b/SlackAPI/SlackTaskClient.cs index edc1eb41..329cbe12 100644 --- a/SlackAPI/SlackTaskClient.cs +++ b/SlackAPI/SlackTaskClient.cs @@ -7,6 +7,7 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; +using SlackAPI.RPCMessages; namespace SlackAPI { @@ -106,6 +107,10 @@ public Task GetUserListAsync() { return APIRequestWithTokenAsync(); } + + public Task ChannelsCreateAsync(string name) { + return APIRequestWithTokenAsync(new Tuple("name", name)); + } public Task GetChannelListAsync(bool ExcludeArchived = true) { @@ -425,6 +430,37 @@ public Task EmitLoginAsync(string agent = "Inumedia.SlackAPI") { return APIRequestWithTokenAsync(new Tuple("agent", agent)); } + public Task UpdateAsync(string ts, + string channelId, + string text, + string botName = null, + string parse = null, + bool linkNames = false, + Attachment[] attachments = null, + bool as_user = false) + { + List> parameters = new List>(); + + parameters.Add(new Tuple("ts", ts)); + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); + + if (!string.IsNullOrEmpty(botName)) + parameters.Add(new Tuple("username", botName)); + + if (!string.IsNullOrEmpty(parse)) + parameters.Add(new Tuple("parse", parse)); + + if (linkNames) + parameters.Add(new Tuple("link_names", "1")); + + if (attachments != null && attachments.Length > 0) + parameters.Add(new Tuple("attachments", JsonConvert.SerializeObject(attachments))); + + parameters.Add(new Tuple("as_user", as_user.ToString())); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } public Task JoinDirectMessageChannelAsync(string user) { @@ -474,6 +510,59 @@ public Task PostMessageAsync( return APIRequestWithTokenAsync(parameters.ToArray()); } + public Task PostEphemeralMessageAsync( + string channelId, + string text, + string targetuser, + string parse = null, + bool linkNames = false, + Attachment[] attachments = null, + bool as_user = false, + string thread_ts = null) + { + List> parameters = new List>(); + + parameters.Add(new Tuple("channel", channelId)); + parameters.Add(new Tuple("text", text)); + parameters.Add(new Tuple("user", targetuser)); + + if (!string.IsNullOrEmpty(parse)) + parameters.Add(new Tuple("parse", parse)); + + if (linkNames) + parameters.Add(new Tuple("link_names", "1")); + + if (attachments != null && attachments.Length > 0) + parameters.Add(new Tuple("attachments", + JsonConvert.SerializeObject(attachments, Formatting.None, + new JsonSerializerSettings // Shouldn't include a not set property + { + NullValueHandling = NullValueHandling.Ignore + }))); + + parameters.Add(new Tuple("as_user", as_user.ToString())); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } + + public Task AddReactionAsync( + string name = null, + string channel = null, + string timestamp = null) + { + List> parameters = new List>(); + + if (!string.IsNullOrEmpty(name)) + parameters.Add(new Tuple("name", name)); + + if (!string.IsNullOrEmpty(channel)) + parameters.Add(new Tuple("channel", channel)); + + if (!string.IsNullOrEmpty(timestamp)) + parameters.Add(new Tuple("timestamp", timestamp)); + + return APIRequestWithTokenAsync(parameters.ToArray()); + } public async Task UploadFileAsync(byte[] fileData, string fileName, string[] channelIds, string title = null, string initialComment = null, bool useAsync = false, string fileType = null) { From bf054f1c2aebbd5612701e5688915281accf3b7d Mon Sep 17 00:00:00 2001 From: clockworkcoding Date: Fri, 22 Feb 2019 23:39:30 -0500 Subject: [PATCH 002/102] Updated AccessTokenResponse to include the BotTokenResponse and team_id --- SlackAPI/RPCMessages/AccessTokenResponse.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/SlackAPI/RPCMessages/AccessTokenResponse.cs b/SlackAPI/RPCMessages/AccessTokenResponse.cs index ebf9fb9d..865d9faf 100644 --- a/SlackAPI/RPCMessages/AccessTokenResponse.cs +++ b/SlackAPI/RPCMessages/AccessTokenResponse.cs @@ -12,6 +12,24 @@ public class AccessTokenResponse : Response public string access_token; public string scope; public string team_name; - public Bot bot; + public string team_id { get; set; } + public BotTokenResponse bot; + } + + public class BotTokenResponse + { + public string emoji; + public string image_24; + public string image_32; + public string image_48; + public string image_72; + public string image_192; + + public bool deleted; + public UserProfile icons; + public string id; + public string name; + public string bot_user_id; + public string bot_access_token; } } From 0948badfd1946fa17020ecf2b85ac1c13e509ef8 Mon Sep 17 00:00:00 2001 From: Sergey Nechaev Date: Tue, 12 Mar 2019 21:48:07 +0700 Subject: [PATCH 003/102] Fixes timestamp serialization issue (#170) --- SlackAPI/Extensions.cs | 5 +++-- SlackAPI/JavascriptDateTimeConverter.cs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/SlackAPI/Extensions.cs b/SlackAPI/Extensions.cs index 194a9487..02d8d6e4 100644 --- a/SlackAPI/Extensions.cs +++ b/SlackAPI/Extensions.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Globalization; using Newtonsoft.Json; namespace SlackAPI @@ -17,10 +18,10 @@ public static string ToProperTimeStamp(this DateTime that, bool toUTC = true) { if (toUTC) { - return ((that.ToUniversalTime().Ticks - 621355968000000000m) / 10000000m).ToString("F6"); + return ((that.ToUniversalTime().Ticks - 621355968000000000m) / 10000000m).ToString("F6", CultureInfo.InvariantCulture); } else - return that.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString(); + return that.Subtract(new DateTime(1970, 1, 1)).TotalSeconds.ToString(CultureInfo.InvariantCulture); } public static K Deserialize(this string data) diff --git a/SlackAPI/JavascriptDateTimeConverter.cs b/SlackAPI/JavascriptDateTimeConverter.cs index d70d3742..29117bae 100644 --- a/SlackAPI/JavascriptDateTimeConverter.cs +++ b/SlackAPI/JavascriptDateTimeConverter.cs @@ -20,7 +20,7 @@ public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectTy DateTime res = new DateTime(621355968000000000 + (long)(value * 10000000m)).ToLocalTime(); System.Diagnostics.Debug.Assert( Decimal.Equals( - Decimal.Parse(res.ToProperTimeStamp()), + Decimal.Parse(res.ToProperTimeStamp(), CultureInfo.InvariantCulture), Decimal.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture)), "Precision loss :("); return res; From b10475b461d936c383fe2a8454ceb24d712d4fe0 Mon Sep 17 00:00:00 2001 From: max Date: Sat, 16 Mar 2019 19:06:38 -0400 Subject: [PATCH 004/102] adding block message types --- SlackAPI/Block.cs | 76 ++++++++++++++++++++++++ SlackAPI/SlackClient.cs | 41 ++++++++++--- SlackAPI/SlackTaskClient.cs | 6 +- SlackAPI/WebSocketMessages/NewMessage.cs | 1 + 4 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 SlackAPI/Block.cs diff --git a/SlackAPI/Block.cs b/SlackAPI/Block.cs new file mode 100644 index 00000000..91168dea --- /dev/null +++ b/SlackAPI/Block.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SlackAPI +{ + //see https://api.slack.com/reference/messaging/blocks + public class Block + { + public string type { get; set; } + public Text text { get; set; } + public Accessory accessory { get; set; } + public List elements { get; set; } + public Title title { get; set; } + public string image_url { get; set; } + public string alt_text { get; set; } + public List fields { get; set; } + } + public class Text + { + public string type { get; set; } + public string text { get; set; } + public bool? emoji { get; set; } + } + + public class Placeholder + { + public string type { get; set; } + public string text { get; set; } + public bool emoji { get; set; } + } + + public class Option + { + public Text text { get; set; } + public string value { get; set; } + } + + public class Accessory + { + public string type { get; set; } + public string image_url { get; set; } + public string alt_text { get; set; } + public Text text { get; set; } + public string value { get; set; } + public Placeholder placeholder { get; set; } + public List