Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?

What I have tried:

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 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")]
Posted
Updated 14-Nov-17 18:12pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900