Exemplo n.º 1
0
        public IActionResult CreateIntent([FromRoute] string agentId, [FromBody] VmIntentDetail vmIntent)
        {
            if (agentId != vmIntent.AgentId)
            {
                return(BadRequest("AgentId is not matched with intent agentId."));
            }

            var agent  = new RasaAi(dc).LoadAgentById(dc, agentId);
            var intent = vmIntent.ToIntent();

            dc.DbTran(() => {
                intent.Id = agent.CreateIntent(dc, intent);
            });

            return(Ok(intent.Id));
        }
Exemplo 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);
        }
Exemplo n.º 3
0
        public IActionResult UpdateIntent([FromRoute] string intentId, [FromBody] VmIntentDetail vmIntent)
        {
            var agent = new RasaAi(dc);

            dc.DbTran(() => {
                var intent = agent.GetIntent(dc, intentId);

                // remove
                var originalIntent = dc.Table <Intent>().Find(intentId);
                dc.Table <Intent>().Remove(originalIntent);
                dc.SaveChanges();

                // add back
                intent             = vmIntent.ToIntent(intent);
                intent.UpdatedTime = DateTime.UtcNow;

                dc.Table <Intent>().Add(intent);
            });

            return(Ok(intentId));
        }