public async Task <HttpResponseMessage> ExecuteIntent([FromBody] SkillServiceRequest request) { try { var controllerId = _securityService.GetControllerUidFromAmazonUserId(request.Session.User.UserId); if (controllerId == null) { throw new UnauthorizedAccessException(); } var apiRequest = new ApiRequest { Action = "Service/IPersonalAgentService/ProcessSkillServiceRequest", Parameter = JObject.FromObject(request) }; var apiResponse = await _messageBroker.SendRequestAsync(controllerId.Value, apiRequest, TimeSpan.FromSeconds(5)); if (apiResponse.ResultCode == ApiResultCode.Success) { return(CreateJsonResponse(apiResponse.Result.ToObject <SkillServiceResponse>())); } return(CreateJsonResponse("Es ist ein Fehler aufgetreten. Du musst dich bei Christian beschweren.")); } catch (ControllerNotReachableException) { return(CreateJsonResponse("Ich konnte deine Wohnung leider nicht erreichen. Versuche es später noch einmal.")); } }
private string GetSlotValue(SkillServiceRequest skillServiceRequest, string slotName) { SkillServiceRequestRequestIntentSlot slot; if (!skillServiceRequest.Request.Intent.Slots.TryGetValue(slotName, out slot)) { return(null); } return(slot.Value); }
private string GetText(SkillServiceRequest skillServiceRequest) { var result = string.Empty; foreach (var slot in skillServiceRequest.Request.Intent.Slots) { result += slot.Value.Value + " "; } return(result.Trim()); }
public MessageContext Create(SkillServiceRequest skillServiceRequest) { if (skillServiceRequest == null) { throw new ArgumentNullException(nameof(skillServiceRequest)); } _currentContext = new MessageContext { Kind = MessageContextKind.Speech, Text = GetText(skillServiceRequest), Intent = skillServiceRequest.Request.Intent.Name }; foreach (var slot in skillServiceRequest.Request.Intent.Slots) { _currentContext.Slots[slot.Key] = slot.Value.Value; } if (skillServiceRequest.Request.Intent.Name == "ChangeState") { var mentionedArea = GetSlotValue(skillServiceRequest, "Area"); var mentionedComponent = GetSlotValue(skillServiceRequest, "Component"); var mentionedState = GetSlotValue(skillServiceRequest, "State"); IdentifyAreas(mentionedArea); IdentifyComponents(mentionedComponent); IdentifyCommands(mentionedState); var areaFound = !string.IsNullOrEmpty(mentionedArea) && _currentContext.IdentifiedAreaIds.Any(); if (!areaFound) { // TODO: Extend logic and check which component identification leads to a precise value (Count == 1). } FilterComponentIds(); } return(_currentContext); }