public new void Setup() { base.Setup(); var sender = new RestSender(); _messenger = new Messenger(sender); }
public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); var triggerDetails = taskInstance.TriggerDetails as AppServiceTriggerDetails; if (triggerDetails != null) { this.VoiceServiceConnection = VoiceCommandServiceConnection.FromAppServiceTriggerDetails(triggerDetails); // toReturn = await voiceCommandConnection.GetVoiceCommandAsync(); } VoiceCommandResponse voiceResponse = VoiceCommandResponse.CreateResponse(new VoiceCommandUserMessage() { DisplayMessage = "Default Response", SpokenMessage = $"Sorry, something went wrong when running the command" }); try { VoiceCommand voiceCommand = await VoiceServiceConnection.GetVoiceCommandAsync(); RestSender rester = new RestSender(); switch (voiceCommand.CommandName) { case CREATE_TEAM_COMMAND: string teamName = voiceCommand?.Properties["siteName"]?[0]; // voiceResponse = CreateSite(teamName); await ShowProgressScreen($"Creating a team portal for the {teamName}"); Uri toNavTo = await rester.CreateSharePointSiteAsync(teamName); await ShowProgressScreen($"Navigating to the {teamName} portal"); await rester.NavigateToUriAsync(toNavTo); voiceResponse = VoiceCommandResponse.CreateResponse(new VoiceCommandUserMessage() { DisplayMessage = "Team portal created successfully!", SpokenMessage = $"Team portal was created successfully!" }); break; case ADD_TASK_COMMAND: string firstName = voiceCommand.Properties["firstName"][0]; string taskName = voiceCommand.Properties["action"][0]; await ShowProgressScreen($"Telling {firstName} to {taskName}"); await rester.CreateTaskAsync(userFirstName: firstName, taskName : taskName); voiceResponse = VoiceCommandResponse.CreateResponse(new VoiceCommandUserMessage() { DisplayMessage = "Task created successfully!", SpokenMessage = $"{firstName} was told to {taskName}!" }); break; default: break; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } finally { deferral.Complete(); } await VoiceServiceConnection.ReportSuccessAsync(voiceResponse); }