using Newtonsoft.Json.Linq;
public static void Main(string[] args)
string query = Console.ReadLine();
string apiEndPointUrl = "https://api.projectoxford.ai/luis/v1/application?id={0}&subscription-key={1}&q={2}&timezoneOffset=0.0";
string applicationId = "YourApplicationIdHere";
string key = "YourKeyHere";
string url = string.Format(apiEndPointUrl, applicationId, key, HttpUtility.UrlEncode(query));
string response = ProcessRequest(url);
string intent = GetIntent(response);
string nextResponse = GetNextResponseFromIntent(intent);
Console.WriteLine(nextResponse);
query = Console.ReadLine();
private static string GetNextResponseFromIntent(string intent)
string nextResponse = "";
nextResponse = "Your policy will finish at the end of this month";
nextResponse = "You are covered for Life and Critical illness.";
nextResponse = "Your policy begins on 1st December 2016";
case "ChangeDirectDebitDetails":
nextResponse = "No problem, what is your new sort code?";
case "MakePaymentToAccount":
nextResponse = "Ok, are you paying by Debit or Credit card?";
case "CheckDirectDebitDate":
nextResponse = "Your direct debit is set for the 1st of every month";
case "AddAnotherPersonToPolicy":
nextResponse = "Cool, what is their full name?";
case "ChangePersonalDetails":
nextResponse = "What details do you want to change?";
nextResponse = "I didn't understand that, try saying it in a different way.";
public static string GetIntent(string serverResponse)
JObject response = JObject.Parse(serverResponse);
return response["intents"][0]["intent"].ToString();
public static string ProcessRequest(string url)
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
return responseFromServer;