Ejemplo n.º 1
0
        public override async Task <SkillResponse> GetSkillResponse(SkillRequest skillRequest)
        {
            base.Logger.LogTrace("BEGIN GetSkillResponse. RequestId: {0}.", skillRequest.Request.RequestId);

            IntentRequest intentRequest = skillRequest.Request as IntentRequest;

            if (intentRequest.Intent.ConfirmationStatus == "DENIED")
            {
                return(string.Format("Okay").Tell(true));
            }

            // Get the right handler for the IntentRequest based on the name of the intent
            IIntentRequestHandler requestHandler = base.RequestHandlers.Where(x => x.HandlerName == intentRequest.Intent.Name).FirstOrDefault() as IIntentRequestHandler;

            if (requestHandler == null)
            {
                throw new NotSupportedException(string.Format("Cannot successfully route IntentRequest '{0}'.", intentRequest.Intent.Name));
            }

            // Handle the request
            SkillResponse skillResponse = await Task.Run(() => requestHandler.Handle(skillRequest));

            base.Logger.LogTrace("END GetSkillResponse. RequestId: {0}.", skillRequest.Request.RequestId);

            return(skillResponse);
        }
Ejemplo n.º 2
0
        public Function()
        {
            _serviceProvider            = new ServiceProviderBuilder().Build();
            _intentRequestHandler       = _serviceProvider.GetService <IIntentRequestHandler>();
            _launchRequestHandler       = _serviceProvider.GetService <ILaunchRequestHandler>();
            _sessionEndedRequestHandler = _serviceProvider.GetService <ISessionEndedRequestHandler>();

            _requestStrategy = new Dictionary <Type, Func <SkillRequest, Task <SkillResponse> > >()
            {
                { typeof(ILaunchRequest), _launchRequestHandler.HandleAsync },
                { typeof(IIntentRequest), _intentRequestHandler.HandleAsync },
                { typeof(ISessionEndedRequest), _sessionEndedRequestHandler.HandleAsync }
            };
        }