private async Task <List <Interaction> > PostUserResponse(string userResponse, int tempInteractionCounter) { //FAKE SENDING RESPONSE TO API ///..... ///END ///Handle the received interaction await ChatWindow.ScrollToAsync(0, ChatBox.Height, true); List <Interaction> interactions = new List <Interaction>(); switch (tempInteractionCounter) { case 0: interactions.Add(new Interaction() { SpokenWord = "Mine too!" }); interactions.Add(new Interaction() { SpokenWord = "Do you like pizza?" }); break; case 1: await Task.Run(async() => { System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); client.MaxResponseContentBufferSize = 256000; Stream stream = await client.GetStreamAsync("https://homepages.cae.wisc.edu/~ece533/images/boat.png"); byte[] testImg = GetImageStreamAsBytes(stream); interactions.Add(new Interaction() { image = testImg, showMessage = true }); }); break; default: interactions.Add(new Interaction() { SpokenWord = "Pyxus says something intelligent", showMessage = true }); break; } return(interactions); }
private async Task DisplayPyxusResponse(List <Interaction> i) { await ChatWindow.ScrollToAsync(0, ChatBox.Height, true); if (IsLoading) { Device.BeginInvokeOnMainThread(async() => { ChatBox.Children.Remove(loadingBtn); foreach (Interaction _interaction in i) { if (_interaction.image != null) {//Pyxus responds w/ image Image image = new Image() { Source = ImageSource.FromStream(() => new MemoryStream(_interaction.image)), VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.Start, Margin = new Thickness(10, 0, 10, 0) }; ChatBox.Children.Add(image); } else {//Pyxus responds w/ text ChatBox.Children.Add(new ButtonUser() { Text = _interaction.SpokenWord, VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.Start, Margin = new Thickness(10, 0, 10, 0) }); } RequestBox.IsVisible = _interaction.showMessage; CustomBtns.IsVisible = !_interaction.showMessage; sendBtn.IsVisible = _interaction.showMessage; } await ChatWindow.ScrollToAsync(0, ChatBox.Height, true); }); IsLoading = false; } }