public static Tuple<Message, ApiCallResponse> get(string access_token, string channelId, string messageId) { ApiCallResponse apiCallResponse = new ApiCallResponse(); Message message = new Message(); try { if (string.IsNullOrEmpty(access_token)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter access_token"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } if (string.IsNullOrEmpty(channelId)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing channelId"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } if (string.IsNullOrEmpty(messageId)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing messageId"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } string requestUrl = Common.baseUrl + "/stream/0/channels/" + channelId + "/messages/" + messageId; Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendGetRequest( requestUrl, headers); return Helper.getData<Message>(response); } catch (Exception exp) { apiCallResponse.success = false; apiCallResponse.errorMessage = exp.Message; apiCallResponse.errorDescription = exp.StackTrace; } return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); }
public static Tuple<Message, ApiCallResponse> create(string access_token, string text, string channelId, List<string> receipientUsersnameOrIds, string reply_to = null, List<Annotation> annotations = null, Entities entities = null, int machineOnly = 0) { ApiCallResponse apiCallResponse = new ApiCallResponse(); Message message = new Message(); try { if (string.IsNullOrEmpty(access_token)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter access_token"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } if (string.IsNullOrEmpty(text)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter text"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } if (channelId.ToLower() == "pm" && receipientUsersnameOrIds == null) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter destinations for PM"; return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); } string requestUrl = Common.baseUrl; if (channelId.ToLower() == "pm") { requestUrl += "/stream/0/channels/pm/messages"; } else { requestUrl += "/stream/0/channels/" + channelId + "/messages"; } messageCreateParameters messageContent = new messageCreateParameters(); messageContent.text = text; messageContent.reply_to = reply_to; //messageContent.annotations = annotations; messageContent.entities = entities; messageContent.machine_only = machineOnly; messageContent.destinations = receipientUsersnameOrIds; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; string jsonString = JsonConvert.SerializeObject(messageContent, Formatting.None, settings); Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendPostRequestStringDataOnly( requestUrl, jsonString, headers, true, contentType:"application/json"); return Helper.getData<Message>(response); } catch (Exception exp) { apiCallResponse.success = false; apiCallResponse.errorMessage = exp.Message; apiCallResponse.errorDescription = exp.StackTrace; } return new Tuple<Message, ApiCallResponse>(message, apiCallResponse); }