private async void MessageBox_Send(object sender, RoutedEventArgs e) { MessageUpsert mu = new MessageUpsert(); mu.Content = mbox.Text; // mu.Activity = new MessageActivity() { type = 3, party_id = "spotify:"+LocalModels.LocalState.CurrentUser.Id, session_id = Managers.GatewayManager.session }; await RESTCalls.CreateMessage(App.CurrentChannelId, mu); }
public static MessageContainer MakeMessage(string chnId, MessageUpsert upsert) { Message message = new Message() { ChannelId = chnId, Content = upsert.Content, User = LocalState.CurrentUser, TTS = upsert.TTS, Timestamp = DateTime.Now }; MessageContainer msg = new MessageContainer(message, GetMessageType(message.Type), false, null, true); return(msg); }
public static async Task CreateMessage(string id, string text) { try { MessageUpsert message = new MessageUpsert(); message.Content = text; IChannelService channelservice = AuthenticatedRestFactory.GetChannelService(); await channelservice.CreateMessage(id, message); } catch (Exception exception) { App.NavigateToBugReport(exception); } }
public static async Task CreateMessage(string id, string text, Windows.Storage.StorageFile file) { try { MessageUpsert message = new MessageUpsert(); message.Content = text; HttpMultipartFormDataContent content = new HttpMultipartFormDataContent("---------------------------7e11a60110a78"); //content.Add(new HttpStringContent(message.Content), "content"); content.Add(new HttpStringContent(Uri.EscapeUriString(JsonConvert.SerializeObject(message))), "payload_json"); //content.Add(new HttpStringContent(message.TTS.ToString()), "tts"); if (file != null) { content.Add(new HttpStreamContent(await file.OpenAsync(Windows.Storage.FileAccessMode.Read)), "file", file.Name); } content.Headers.ContentType = new Windows.Web.Http.Headers.HttpMediaTypeHeaderValue("multipart/form-data; boundary=---------------------------7e11a60110a78"); if (messageclient.DefaultRequestHeaders.Authorization == null) { messageclient.DefaultRequestHeaders.Authorization = new Windows.Web.Http.Headers.HttpCredentialsHeaderValue(Token); } var send = messageclient.PostAsync(new Uri(config.BaseUrl + "/v6/channels/" + id + "/messages"), content); send.Progress = MessageUploadProgress; var resp = await send; if (resp.IsSuccessStatusCode) { id = ""; } } catch (Exception exception) { App.NavigateToBugReport(exception); } }
/// <summary> /// Send message post request /// </summary> private async void App_CreateMessageHandler(object sender, App.CreateMessageArgs e) { // TODO: Show pending message item till sent if (e.Message.Content.Length > 10000) // Too long { MessageDialog md = new MessageDialog("Sorry, but this message is way too long to be sent, even with Quarrel", "Over 10 000 characters?!"); await md.ShowAsync(); } else if (e.Message.Content.Length > 2000) // Too long for one message { // Show loading indicator MessagesLoading.Visibility = Visibility.Visible; //Split the message into <2000 char ones and send them individually IEnumerable <string> split = SplitToLines(e.Message.Content, 2000); int splitcount = split.Count(); if (splitcount < 10) { for (int i = 0; i < splitcount; i++) { // Get split message MessageUpsert splitmessage = new MessageUpsert { Content = split.ElementAt(i) }; if (i == splitcount) { splitmessage.file = e.Message.file; } // Send message Stopwatch sw = new Stopwatch(); sw.Start(); await RESTCalls.CreateMessage(e.ChannelId, splitmessage); sw.Stop(); //make sure to wait at least 500ms between each message if (sw.ElapsedMilliseconds < 500) { await Task.Delay(Convert.ToInt32(500 - sw.ElapsedMilliseconds)); } } } else { MessageDialog md = new MessageDialog("Sorry, but this message is way too long to be sent, even with Quarrel", "Wait, what?!"); await md.ShowAsync(); return; } // Hide loading indicator MessagesLoading.Visibility = Visibility.Collapsed; } else { //Just send the message await RESTCalls.CreateMessage(e.ChannelId, e.Message); } }
/// <inheritdoc /> public virtual Task <Message> CreateMessage(string channelId, MessageUpsert message) { var arguments = new object[] { channelId, message }; return((Task <Message>)methodImpls["CreateMessage"](Client, arguments)); }