Ejemplo n.º 1
0
        public static VmIntentResponse FromIntentResponse(IntentResponse intentResponse)
        {
            var response = new VmIntentResponse
            {
                Action = intentResponse.Action
            };

            response.AffectedContexts = intentResponse.Contexts.Select(ctx => ctx.ToObject <VmIntentResponseContext>()).ToList();

            response.Parameters = intentResponse.Parameters.Select(p => VmIntentResponseParameter.FromIntentResponseParameter(p)).ToList();

            response.Messages = intentResponse.Messages.Select(msg => {
                if (msg.Speech == null)
                {
                    return(new VmIntentResponseMessage());
                }

                return(new VmIntentResponseMessage
                {
                    Payload = msg.Payload,
                    Type = msg.Type,
                    Speeches = JsonConvert.DeserializeObject <List <String> >(msg.Speech)
                });
            }).ToList();

            return(response);
        }
Ejemplo n.º 2
0
        public VmIntentDetail GetIntentById([FromRoute] string intentId)
        {
            var agent  = new RasaAi(dc);
            var intent = agent.GetIntent(dc, intentId);
            var vm     = new VmIntentDetail
            {
                Id        = intent.Id,
                AgentId   = intent.AgentId,
                Name      = intent.Name,
                Events    = new List <string>(),
                Contexts  = intent.Contexts.Select(x => x.Name).ToList(),
                UserSays  = intent.UserSays.Select(x => x.ToObject <VmIntentExpression>()).ToList(),
                Responses = intent.Responses.Select(x => VmIntentResponse.FromIntentResponse(x)).ToList()
            };

            return(vm);
        }