From febe408e945e0f7f6a75ae897143f31674704d39 Mon Sep 17 00:00:00 2001 From: raghunath2711 Date: Tue, 27 Jun 2017 13:32:46 -0700 Subject: [PATCH 1/5] Added Eviction intents --- messages/BasicLuisDialog.csx | 87 +++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/messages/BasicLuisDialog.csx b/messages/BasicLuisDialog.csx index a5bcd1b..6d13316 100644 --- a/messages/BasicLuisDialog.csx +++ b/messages/BasicLuisDialog.csx @@ -20,7 +20,8 @@ public class BasicLuisDialog : LuisDialog await context.PostAsync($"You have reached the none intent. You said: {result.Query}"); // context.Wait(MessageReceived); } - + + #region Family & Safety // Go to https://luis.ai and create a new intent, then train/publish your luis app. // Finally replace "MyIntent" with the name of your newly created intent in the following handler @@ -100,4 +101,88 @@ public class BasicLuisDialog : LuisDialog await context.PostAsync($"You have reached the serve the opposing party intent. You said: {result.Query}"); // context.Wait(MessageReceived); } + + #endregion + + #region Housing & Apartment + [LuisIntent("Eviction and Defence")] + public async Task DefenceIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Eviction and Defence intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("HUD Eviction")] + public async Task HudIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the HUD Eviction intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + + [LuisIntent("Landlord locked me out what can i do")] + public async Task LockedIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Landlord locked me out what can i do intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Public & subsidized housing")] + public async Task PublicIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Public & subsidized housing intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Public Housing Evictions")] + public async Task PublicHousingIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Public Housing Evictions intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Public Housing Grievance Procedure")] + public async Task GrievanceIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Public Housing Grievance Procedure intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Section 515: Rural Rights")] + public async Task RuralrightsIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Section 515: Rural Rights intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Tenant Living in a foreclosed property")] + public async Task TenantIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Tenant Living in a foreclosed property intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Tenant Living in a foreclosed property")] + public async Task TenantIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Tenant Living in a foreclosed property intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Tenant's Rights in Washington state")] + public async Task TenantRightsIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Tenant's Rights in Washington state intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + + + + + + + + + #endregion } \ No newline at end of file From 6e0829f6fbb25d53132eaefa743ab16acf67bf2a Mon Sep 17 00:00:00 2001 From: raghunath2711 Date: Tue, 27 Jun 2017 13:43:02 -0700 Subject: [PATCH 2/5] Deleted additional syntax --- messages/BasicLuisDialog.csx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/messages/BasicLuisDialog.csx b/messages/BasicLuisDialog.csx index 6d13316..2d254c4 100644 --- a/messages/BasicLuisDialog.csx +++ b/messages/BasicLuisDialog.csx @@ -162,13 +162,6 @@ public class BasicLuisDialog : LuisDialog context.Wait(MessageReceived); } - [LuisIntent("Tenant Living in a foreclosed property")] - public async Task TenantIntent(IDialogContext context, LuisResult result) - { - await context.PostAsync($"You have reached the Tenant Living in a foreclosed property intent. You said: {result.Query}"); // - context.Wait(MessageReceived); - } - [LuisIntent("Tenant's Rights in Washington state")] public async Task TenantRightsIntent(IDialogContext context, LuisResult result) { From 97769532d2fb40a3f4b88d30a24a4283e064101c Mon Sep 17 00:00:00 2001 From: raghunath2711 Date: Tue, 27 Jun 2017 16:14:20 -0700 Subject: [PATCH 3/5] Added Tenant's Rights --- messages/BasicLuisDialog.csx | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/messages/BasicLuisDialog.csx b/messages/BasicLuisDialog.csx index 2d254c4..cdc9f39 100644 --- a/messages/BasicLuisDialog.csx +++ b/messages/BasicLuisDialog.csx @@ -105,6 +105,7 @@ public class BasicLuisDialog : LuisDialog #endregion #region Housing & Apartment + [LuisIntent("Eviction and Defence")] public async Task DefenceIntent(IDialogContext context, LuisResult result) { @@ -169,13 +170,41 @@ public class BasicLuisDialog : LuisDialog context.Wait(MessageReceived); } + #endregion + + #region Tenant's Rights + [LuisIntent("Can landlord do that")] + public async Task LandlorddothatIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Can landlord do that intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Rent-to-own in Washington state")] + public async Task RenttoownIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Rent-to-own in Washington state intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + [LuisIntent("Tenants if need repairs")] + public async Task NeedrepairsIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Tenants if need repairs intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + [LuisIntent("Getting security deposit back")] + public async Task SecuritydepositIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Getting security deposit back intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + #endregion - #endregion } \ No newline at end of file From cc0a4e11e4d2e2cda2bfb072c040946d958f475a Mon Sep 17 00:00:00 2001 From: raghunath2711 Date: Thu, 29 Jun 2017 11:53:15 -0700 Subject: [PATCH 4/5] Added Foreclosure, Emergency shelter & Assistance, Utilities & phone, Home buyers and owners, Housing discrimination, Mobile home park tenants, public & subsidized housing, veteran and servicemember rights. --- messages/BasicLuisDialog.csx | 201 +++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/messages/BasicLuisDialog.csx b/messages/BasicLuisDialog.csx index cdc9f39..9d3e525 100644 --- a/messages/BasicLuisDialog.csx +++ b/messages/BasicLuisDialog.csx @@ -204,6 +204,207 @@ public class BasicLuisDialog : LuisDialog #endregion + #region Foreclousre + + [LuisIntent("Foreclosure when have mortgage")] + public async Task ForeclosuremortagageIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Foreclosure when have mortgage intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Homeowner's guide to short sales")] + public async Task HomeownerguideIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Homeowner's guide to short sales intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Non Borrowing spouses and Reverse Mortgages")] + public async Task NonborrowingIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Non Borrowing spouses and Reverse Mortgages intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Emergency shelter & Assistance + + [LuisIntent("Fight a denial or termination for HEN")] + public async Task FightdenialIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Fight a denial or termination for HEN intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Local HEN Admin Directory Homeless prevention")] + public async Task HendirectoryIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Local HEN Admin Directory Homeless prevention intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("People unable to work : ABD and HEN")] + public async Task UnabletoworkIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the People unable to work : ABD and HEN intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Utilites & Phone + + [LuisIntent("Low income home energy")] + public async Task LowincomehomeIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Low income home energy intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Public utilities")] + public async Task PublicutilitiesIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Public utilities intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Homebuyers & Owners + + [LuisIntent("Forfeiture of Your Real Estate Contract")] + public async Task ForfeitureIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Forfeiture of Your Real Estate Contract intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Options to Avoid Property Tax Foreclosure")] + public async Task AvoidpropertyIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Options to Avoid Property Tax Foreclosure intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Know Your Rights Before Buying a Home")] + public async Task RightsbeforebuyingIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Know Your Rights Before Buying a Home intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region House Discrimination + + [LuisIntent("Fair Housing")] + public async Task FairhousingIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Fair Housing intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Fair Housing Guide for Renters & Home Buyers")] + public async Task GuideforrentersandbuyersIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Fair Housing Guide for Renters & Home Buyers intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Tenant Screening: Your Rights")] + public async Task TenantscreeningIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Tenant Screening: Your Rights intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + [LuisIntent("Service Animals Questions")] + public async Task ServiceanimalsIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Service Animals Questions intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Mobile home park tenants + + + [LuisIntent("My Landlord Has Not Paid Their Water Bill")] + public async Task landordnotpaidIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the My Landlord Has Not Paid Their Water Bill intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + + [LuisIntent("Buying a Manufactured Home")] + public async Task BuyingmanufacturedIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Buying a Manufactured Home intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Public & subsidized Hosuing + + [LuisIntent("When I Do Not Pay the Rent")] + public async Task DontpayrentIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the When I Do Not Pay the Rent intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Small claim court + + [LuisIntent("Using Small Claims Court to Recover Unpaid Wages")] + public async Task SmallclaimsIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Using Small Claims Court to Recover Unpaid Wages intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + + [LuisIntent("Certificate of Service - Small Claims Court")] + public async Task CertificatessmallIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Certificate of Service - Small Claims Court intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion + + #region Veteran and servicemember rights in housing and home loans + + [LuisIntent("About VA Home Loan Program")] + public async Task HomeloanprogramIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the About VA Home Loan Program intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + + [LuisIntent("Information for Military Personnel")] + public async Task MilitaryinfoIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Information for Military Personnel intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + + [LuisIntent("Military and Veteran Legal Resource Guide")] + public async Task MilitaryveteranguideIntent(IDialogContext context, LuisResult result) + { + await context.PostAsync($"You have reached the Military and Veteran Legal Resource Guide intent. You said: {result.Query}"); // + context.Wait(MessageReceived); + } + + #endregion From 76a1a29161a434a1d5a0b43ca70f32fbff5321ef Mon Sep 17 00:00:00 2001 From: v-kantra Date: Wed, 13 Sep 2017 15:55:20 -0700 Subject: [PATCH 5/5] Added Translator Feature to the bot --- messages/BasicLuisDialog.csx | 200 ++++++++++++++++++++++++++--------- 1 file changed, 151 insertions(+), 49 deletions(-) diff --git a/messages/BasicLuisDialog.csx b/messages/BasicLuisDialog.csx index eeb54a7..ad3d3ff 100644 --- a/messages/BasicLuisDialog.csx +++ b/messages/BasicLuisDialog.csx @@ -1,5 +1,7 @@ using System; +using System.Text; +using System.Web; using System.Threading.Tasks; using System.Net.Http; using System.Net.Http.Headers; @@ -12,6 +14,7 @@ using Microsoft.Bot.Connector; [Serializable] public class BasicLuisDialog : LuisDialog { + string token; public BasicLuisDialog() : base(new LuisService(new LuisModelAttribute("d70ddc6f-ccb7-4221-ad45-a89458ce02b5", "cc7f076047764c8bb37fec016887db9e"))) { } @@ -19,12 +22,20 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("None")] public async Task NoneIntent(IDialogContext context, LuisResult result) { - intentName = "None"; + intentName = "None"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + [LuisIntent("")] + public async Task EmptyIntent(IDialogContext context, LuisResult result) + { + intentName = ""; + context.Wait(MessageReceived); + } + + string result = ""; + #region Family & Safety string intentName = ""; @@ -37,16 +48,16 @@ public class BasicLuisDialog : LuisDialog await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + + [LuisIntent("Dissolution when wife is pregnant")] public async Task DissolutionIntent(IDialogContext context, LuisResult result) - { + { intentName = "Dissolution when wife is pregnant"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - - + [LuisIntent("Divorce")] public async Task DivorceIntent(IDialogContext context, LuisResult result) @@ -54,18 +65,16 @@ public class BasicLuisDialog : LuisDialog intentName = "Divorce"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); - - } - [LuisIntent("Eviction")] + [LuisIntent("Eviction")] public async Task EvictionIntent(IDialogContext context, LuisResult result) { intentName = "Eviction"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); - - + + } private async Task DoneWithDivorceDialog(IDialogContext context, IAwaitable result) @@ -74,16 +83,16 @@ public class BasicLuisDialog : LuisDialog await context.PostAsync($"Thank you for choosing legal bot. Enter another query that you would like to search for?"); context.Wait(MessageReceived); } - + [LuisIntent("Divorce, Debt, and Bankruptcy")] public async Task DDBIntent(IDialogContext context, LuisResult result) { - intentName = "Divorce, Debt, and Bankruptcy"; + intentName = "Divorce, Debt, and Bankruptcy"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); - + } - + [LuisIntent("Ending Domestic partnership with children")] public async Task WithChildrenIntent(IDialogContext context, LuisResult result) { @@ -91,15 +100,15 @@ public class BasicLuisDialog : LuisDialog await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + [LuisIntent("Ending Domestic partnership without children")] public async Task WithoutChildrenIntent(IDialogContext context, LuisResult result) { - intentName = "Ending Domestic partnership without children"; + intentName = "Ending Domestic partnership without children"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + [LuisIntent("Future retirement benefits")] public async Task RetirementIntent(IDialogContext context, LuisResult result) { @@ -107,35 +116,35 @@ public class BasicLuisDialog : LuisDialog await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + [LuisIntent("Helping Children")] public async Task HelpChildrenIntent(IDialogContext context, LuisResult result) { - intentName = "Helping Children"; + intentName = "Helping Children"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - - [LuisIntent("Jurisdiction")] + + [LuisIntent("Jurisdiction")] public async Task JurisdictionIntent(IDialogContext context, LuisResult result) { intentName = "Jurisdiction"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + [LuisIntent("Paperwork")] public async Task PaperworkIntent(IDialogContext context, LuisResult result) { - intentName = "Paperwork"; + intentName = "Paperwork"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } - + [LuisIntent("serve the opposing party")] public async Task ServeIntent(IDialogContext context, LuisResult result) { - intentName = "serve the opposing party"; + intentName = "serve the opposing party"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -164,7 +173,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Landlord locked me out what can i do")] public async Task LockedIntent(IDialogContext context, LuisResult result) { - intentName = "Landlord locked me out what can i do"; + intentName = "Landlord locked me out what can i do"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -188,7 +197,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Public Housing Grievance Procedure")] public async Task GrievanceIntent(IDialogContext context, LuisResult result) { - intentName = "Public Housing Grievance Procedure"; + intentName = "Public Housing Grievance Procedure"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -196,7 +205,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Section 515: Rural Rights")] public async Task RuralrightsIntent(IDialogContext context, LuisResult result) { - intentName = "Section 515: Rural Rights"; + intentName = "Section 515: Rural Rights"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -204,7 +213,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Tenant Living in a foreclosed property")] public async Task TenantIntent(IDialogContext context, LuisResult result) { - intentName = "Tenant Living in a foreclosed property"; + intentName = "Tenant Living in a foreclosed property"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -212,7 +221,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Tenant's Rights in Washington state")] public async Task TenantRightsIntent(IDialogContext context, LuisResult result) { - intentName = "Tenant's Rights in Washington state"; + intentName = "Tenant's Rights in Washington state"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -224,8 +233,8 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Can landlord do that")] public async Task LandlorddothatIntent(IDialogContext context, LuisResult result) { - - intentName = "Can landlord do that"; + + intentName = "Can landlord do that"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -249,7 +258,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Getting security deposit back")] public async Task SecuritydepositIntent(IDialogContext context, LuisResult result) { - intentName = "Getting security deposit back"; + intentName = "Getting security deposit back"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -277,7 +286,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Non Borrowing spouses and Reverse Mortgages")] public async Task NonborrowingIntent(IDialogContext context, LuisResult result) { - intentName = "Non Borrowing spouses and Reverse Mortgages"; + intentName = "Non Borrowing spouses and Reverse Mortgages"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -297,7 +306,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Local HEN Admin Directory Homeless prevention")] public async Task HendirectoryIntent(IDialogContext context, LuisResult result) { - intentName = "Local HEN Admin Directory Homeless prevention"; + intentName = "Local HEN Admin Directory Homeless prevention"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -305,7 +314,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("People unable to work : ABD and HEN")] public async Task UnabletoworkIntent(IDialogContext context, LuisResult result) { - intentName = "People unable to work : ABD and HEN"; + intentName = "People unable to work : ABD and HEN"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -365,7 +374,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Fair Housing")] public async Task FairhousingIntent(IDialogContext context, LuisResult result) { - intentName = "Fair Housing"; + intentName = "Fair Housing"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -373,7 +382,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Fair Housing Guide for Renters & Home Buyers")] public async Task GuideforrentersandbuyersIntent(IDialogContext context, LuisResult result) { - intentName = "Fair Housing Guide for Renters & Home Buyers"; + intentName = "Fair Housing Guide for Renters & Home Buyers"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -381,7 +390,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Tenant Screening: Your Rights")] public async Task TenantscreeningIntent(IDialogContext context, LuisResult result) { - intentName = "Tenant Screening: Your Rights"; + intentName = "Tenant Screening: Your Rights"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -402,7 +411,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("My Landlord Has Not Paid Their Water Bill")] public async Task landordnotpaidIntent(IDialogContext context, LuisResult result) { - intentName = "My Landlord Has Not Paid Their Water Bill"; + intentName = "My Landlord Has Not Paid Their Water Bill"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -465,7 +474,7 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Information for Military Personnel")] public async Task MilitaryinfoIntent(IDialogContext context, LuisResult result) { - intentName = "Information for Military Personnel"; + intentName = "Information for Military Personnel"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } @@ -474,26 +483,28 @@ public class BasicLuisDialog : LuisDialog [LuisIntent("Military and Veteran Legal Resource Guide")] public async Task MilitaryveteranguideIntent(IDialogContext context, LuisResult result) { - intentName = "Military and Veteran Legal Resource Guide"; + intentName = "Military and Veteran Legal Resource Guide"; await GetContentsFromContenExtractionApi(context); context.Wait(MessageReceived); } #endregion + #region ContentExtraction Api call async Task GetContentsFromContenExtractionApi(IDialogContext context) { try { - + await TextTranslate(context); + var query = ((Microsoft.Bot.Connector.Activity)((Microsoft.Bot.Builder.Dialogs.IBotContext)context).Activity).Text; var client = new HttpClient(); string intent = intentName; var uri = "http://contentsextractionapi.azurewebsites.net/api/ExtractContents"; - HttpResponseMessage response; + HttpResponseMessage response; string finalResponse = ""; - string reqBody = "{\"Topic\":\""+intent+"\",\"Title\":\"" + query+"\"}"; + string reqBody = "{\"Topic\":\"" + intent + "\",\"Title\":\"" + query + "\"}"; using (var content = new StringContent(reqBody)) { @@ -502,15 +513,106 @@ public class BasicLuisDialog : LuisDialog response.EnsureSuccessStatusCode(); finalResponse = await response.Content.ReadAsStringAsync(); var jsonString = await response.Content.ReadAsStringAsync(); - await context.PostAsync($"{jsonString}"); - } + await TextTranslate(context, jsonString); + } + } + catch (Exception e) + { + + } + } + #endregion + + #region Text Translate API for context + async Task TextTranslate(IDialogContext context) + { + try + { + string key = "f79c9411ee6d4daba6bb9aff008fe2eb"; + token = ""; + var uri = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken"; + HttpResponseMessage response; + var Tclient = new HttpClient(); + Tclient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key); + string reqBody = string.Empty; + using (var content = new StringContent(reqBody)) + { + content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + response = await Tclient.PostAsync(uri, content); + response.EnsureSuccessStatusCode(); + token = await response.Content.ReadAsStringAsync(); + } + + uri = "https://api.microsofttranslator.com/V2/Http.svc/Translate"; + result = ""; + var query = ((Microsoft.Bot.Connector.Activity)((Microsoft.Bot.Builder.Dialogs.IBotContext)context).Activity).Text; + string appid = "Bearer " + token; + string from = "en"; + string to = "ja"; + + uri = string.Format("https://api.microsofttranslator.com/V2/Http.svc/Translate?Text=" + query + "&from=" + from + "&to=" + to + "&appid=" + appid); + var httpClient = new HttpClient(); + var responseT = await httpClient.GetAsync(uri); + + //will throw an exception if not successful + responseT.EnsureSuccessStatusCode(); + + result = await responseT.Content.ReadAsStringAsync(); } catch (Exception e) { - + } } #endregion + #region Text Translate API for result + async Task TextTranslate(IDialogContext context, string response) + { + try + { + response = response.Replace("\",\"", ""); + response = response.Replace("&", ""); + response = response.Replace("%", ""); + response = response.Replace("<", ""); + response = response.Replace(">", ""); + response = response.Replace("*", ""); + response = response.Replace("#", ""); + response = response.Replace(";", ""); + response = response.Replace("/", ""); + response = response.Replace("\n", ""); + response = response.Replace("\r", ""); + response = response.Replace("\t", ""); + + + result = ""; + string appid = "Bearer " + token; + string from = "en"; + string to = "ja"; + + var uri = string.Format("https://api.microsofttranslator.com/V2/Http.svc/Translate?Text=" + response + "&from=" + from + "&to=" + to + "&appid=" + appid); + + var httpClient = new HttpClient(); + var responseT = await httpClient.GetAsync(uri); + + //will throw an exception if not successful + responseT.EnsureSuccessStatusCode(); + result = await responseT.Content.ReadAsStringAsync(); + + var idx = result.IndexOf(""); + // var strippedcontent = parsedLine.Substring(0, idx); + result = parsedLine.Substring(0, idx); + + + await context.PostAsync($"{result}"); + } + catch (Exception e) + { + + } + } + #endregion }