public static Promise <FetchSendMessageResponse> SendMessage(string channelId, string content, string nonce, string parentMessageId = "") { var promise = new Promise <FetchSendMessageResponse>(); var para = new SendCommentParameter { content = content, parentMessageId = parentMessageId, nonce = nonce }; var body = JsonConvert.SerializeObject(para); var request = HttpManager.initRequest(Config.apiAddress + "/api/channels/" + channelId + "/messages", Method.POST); var bodyRaw = Encoding.UTF8.GetBytes(body); request.uploadHandler = new UploadHandlerRaw(bodyRaw); request.SetRequestHeader("Content-Type", "application/json"); HttpManager.resume(request).Then(responseText => { var sendMessageResponse = new FetchSendMessageResponse { channelId = channelId, content = content, nonce = nonce }; promise.Resolve(sendMessageResponse); }).Catch(exception => { promise.Reject(exception); }); return(promise); }
public static Promise <Message> SendComment(string channelId, string content, string nonce, string parentMessageId = "") { var promise = new Promise <Message>(); var para = new SendCommentParameter { content = content, parentMessageId = parentMessageId, nonce = nonce }; var request = HttpManager.POST($"{Config.apiAddress}/api/channels/{channelId}/messages", para); HttpManager.resume(request).Then(responseText => { var message = JsonConvert.DeserializeObject <Message>(responseText); promise.Resolve(message); }).Catch(exception => { promise.Reject(exception); }); return(promise); }
public static Promise <FetchSendMessageResponse> SendMessage(string channelId, string content, string nonce, string parentMessageId = "") { var promise = new Promise <FetchSendMessageResponse>(); var para = new SendCommentParameter { content = content, parentMessageId = parentMessageId, nonce = nonce }; var request = HttpManager.POST($"{Config.apiAddress}/api/channels/{channelId}/messages", para); HttpManager.resume(request).Then(responseText => { var sendMessageResponse = new FetchSendMessageResponse { channelId = channelId, content = content, nonce = nonce }; promise.Resolve(sendMessageResponse); }).Catch(exception => { promise.Reject(exception); }); return(promise); }