Home How to make luis Intent dynamic based on endpoint url json string response
Reply: 0

How to make luis Intent dynamic based on endpoint url json string response

user3807114
1#
user3807114 Published in 2017-11-14 13:08:18Z

I want to make Intent value dynamic based on JSON string response from LUIS endpoint url. Based on intent value matched, it will fetch records from SQL Server database. I have this issue: How do I make the intent value dynamic while calling the intent function?

    public  static async Task<string> MakeRequest(string Query)
    {

        var client = new HttpClient();
        var queryString = HttpUtility.ParseQueryString(string.Empty);
        // Request headers
        client.DefaultRequestHeaders.Add("XXXXXXX", "XXXXXXX");

        var uri = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/XXXXX=0&q=" + Query;


        var response = await client.GetAsync(uri);
        var responseContent = await response.Content.ReadAsStringAsync();
        var responseitem = JsonConvert.SerializeObject(responseContent, Formatting.Indented);
        JToken content = JToken.Parse(responseitem);
        var intentOnly =Convert.ToString((from s in content.Children()["responseContent"] select s).ToList());
        var jsonresponse = JObject.Parse(responseContent);
        intentOnly = jsonresponse.SelectToken("intents[1].intent").ToString();
        return intentOnly;
    }

    [LuisIntent("HI")]
    public async Task FindIntent(IDialogContext context, LuisResult result)
    {

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }

        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter();
        SqlCommand cmd = new SqlCommand("USP_GET_RESP", con);
        cmd.Parameters.Add(new SqlParameter("@ACTION", "A"));
        cmd.Parameters.Add(new SqlParameter("@INTENT", result.Intents[0].Intent.ToString()));
        cmd.CommandType = CommandType.StoredProcedure;
        da.SelectCommand = cmd;
        cmd.ExecuteNonQuery();
        da.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            await context.PostAsync(dt.Rows[0]["VCH_ANSWER"].ToString());
        }
        else
        {
            await context.PostAsync("Please get in touch with your account manager. Contact details are on the top right corner of this page.");
        }

        context.Wait(MessageReceived);
    }

I want to place dynamic intent value in place of HI ex- [LuisIntent("HI")]

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.365821 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO