Created
February 19, 2019 11:08
-
-
Save icebeam7/885db0fe7019ebfc46ed1871ffef4cdb to your computer and use it in GitHub Desktop.
WeatherBotv4App - ConversationViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.ObjectModel; | |
using System.Threading.Tasks; | |
using System.Windows.Input; | |
using WeatherBotv4App.Helpers; | |
using WeatherBotv4App.Models; | |
using WeatherBotv4App.Services; | |
using Xamarin.Forms; | |
namespace WeatherBotv4App.ViewModels | |
{ | |
public class ConversationViewModel : BaseViewModel | |
{ | |
DirectLineService service; | |
public ObservableCollection<Message> Messages { get; set; } | |
private string _query; | |
public string Query | |
{ | |
get { return _query; } | |
set { SetProperty(ref _query, value); } | |
} | |
public ICommand SendQueryCommand { get; private set; } | |
public ConversationViewModel() | |
{ | |
service = new DirectLineService(Constants.BotUser); | |
Messages = new ObservableCollection<Message>(); | |
SendQueryCommand = new Command(SendMessage); | |
StartConversation(); | |
} | |
async Task StartConversation() => await service.GetMessages(Messages); | |
void SendMessage() | |
{ | |
if (!string.IsNullOrWhiteSpace(_query)) | |
{ | |
var user = service.Account.Name.ToUpper(); | |
var message = new Message(_query, user); | |
Messages.Add(message); | |
service.SendMessage(_query); | |
} | |
Query = string.Empty; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment