using BotSharp.Core.Engines; using BotSharp.Core.Models; using BotSharp.NLP; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Text; namespace BotSharp.RestApi.Rasa { #if RASA_UI [Route("[controller]")] public class ParseController : ControllerBase { private readonly IBotPlatform _platform; /// /// Initialize dialog controller and get a platform instance /// /// public ParseController(IBotPlatform platform) { _platform = platform; } [HttpPost] public ActionResult Parse(RasaRequestModel request) { String clientAccessToken = Request.Headers["ClientAccessToken"]; var config = new AIConfiguration(clientAccessToken, SupportedLanguage.English); config.SessionId = "rasa nlu"; _platform.LoadAgent(clientAccessToken); var aIResponse = _platform.TextRequest(new AIRequest { Query = new String[] { request.Text } }); return new RasaResponse { Intent = new RasaResponseIntent { Name = aIResponse.Result.Metadata.IntentName, Confidence = aIResponse.Result.Score }, Entities = new List { }, Text = request.Text }; } } #endif }