/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { bool bSetStock = false; Luis.StockLUIS stLuis = await Luis.LUISStockClient.ParseUserInput(activity.Text); string strRet = string.Empty; string strStock = activity.Text; ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); // Get the stateClient to get/set Bot Data StateClient _stateClient = activity.GetStateClient(); BotData _botData = _stateClient.BotState.GetUserData(activity.ChannelId, activity.Conversation.Id); switch (stLuis.intents[0].intent) { case "RepeatLastStock": strStock = _botData.GetProperty <string>("LastStock"); if (null == strStock) { strRet = "I don't have a previous stock to look up!"; } else { strRet = await YahooStock.Yahoo.GetStock(strStock); } break; case "StockPrice": bSetStock = true; strRet = await YahooStock.Yahoo.GetStock(stLuis.entities[0].entity); break; case "None": strRet = "Sorry, I don't understand, perhaps try something like \"Show me Microsoft stock\""; break; default: break; } if (bSetStock) { _botData.SetProperty <string>("LastStock", stLuis.entities[0].entity); _stateClient.BotState.SetUserData(activity.ChannelId, activity.Conversation.Id, _botData); } // return our reply to the user Activity reply = activity.CreateReply(strRet); await connector.Conversations.ReplyToActivityAsync(reply); } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) //if type is message { Luis.StockLUIS stLuis = await Luis.LUISStockClient.ParseUserInput(activity.Text); //Setup State Client ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); //Bot State StateClient stateClient = activity.GetStateClient(); BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id); var userMessage = activity.Text; string endOutput = ""; bool isText = false; if (userData.GetProperty <bool>("launched")) { if (userData.GetProperty <bool>("transferNeedsConfirmation")) { if (userMessage.ToLower().Equals("y")) { string pleaseWait = "Please wait, processing your request"; Activity infoReply = activity.CreateReply(pleaseWait); await connector.Conversations.ReplyToActivityAsync(infoReply); //go ahead double amountToTransfer = userData.GetProperty <double>("transferAmount"); List <customerInfo> accountInfo = await AzureManager.AzureManagerInstance.GetTimelines("1"); if (userData.GetProperty <string>("transferFrom") == "cheque" && userData.GetProperty <string>("transferTo") == "saving") //cheque->saving { foreach (customerInfo t in accountInfo) { if (t.acc1Bal < amountToTransfer) { endOutput += "Sorry there's insufficient funds in your Cheque account"; isText = true; } else { await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc1Bal - amountToTransfer, "cheque"); await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc2Bal + amountToTransfer, "saving"); endOutput += "Transcation is complete"; isText = true; } } } else if (userData.GetProperty <string>("transferFrom") == "cheque" && userData.GetProperty <string>("transferTo") == "credit") //cheque->credit { foreach (customerInfo t in accountInfo) { if (t.acc1Bal < amountToTransfer) { endOutput += "Sorry there's insufficient funds in your Cheque account"; isText = true; } else { await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc1Bal - amountToTransfer, "cheque"); await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc3Bal + amountToTransfer, "credit"); endOutput += "Transcation is complete"; isText = true; } } } else if (userData.GetProperty <string>("transferFrom") == "saving" && userData.GetProperty <string>("transferTo") == "cheque") //saving->cheque { foreach (customerInfo t in accountInfo) { if (t.acc2Bal < amountToTransfer) { endOutput += "Sorry there's insufficient funds in your Saving account"; isText = true; } else { await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc2Bal - amountToTransfer, "saving"); await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc1Bal + amountToTransfer, "cheque"); endOutput += "Transcation is complete"; isText = true; } } } else if (userData.GetProperty <string>("transferFrom") == "saving" && userData.GetProperty <string>("transferTo") == "credit") //saving->credit { foreach (customerInfo t in accountInfo) { if (t.acc2Bal < amountToTransfer) { endOutput += "Sorry there's insufficient funds in your Saving account"; isText = true; } else { await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc2Bal - amountToTransfer, "saving"); await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc3Bal + amountToTransfer, "credit"); endOutput += "Transcation is complete"; isText = true; } } } else if (userData.GetProperty <string>("transferFrom") == "credit" && userData.GetProperty <string>("transferTo") == "cheque") //credit->cheque { foreach (customerInfo t in accountInfo) { if (t.acc3Bal < amountToTransfer) { endOutput += "Sorry there's insufficient funds in your Credit Card account"; isText = true; } else { await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc3Bal - amountToTransfer, "credit"); await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc1Bal + amountToTransfer, "cheque"); endOutput += "Transcation is complete"; isText = true; } } } else if (userData.GetProperty <string>("transferFrom") == "credit" && userData.GetProperty <string>("transferTo") == "saving") //credit->saving { foreach (customerInfo t in accountInfo) { if (t.acc3Bal < amountToTransfer) { endOutput += "Sorry there's insufficient funds in your Credit Card account"; isText = true; } else { await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc3Bal - amountToTransfer, "credit"); await AzureManager.AzureManagerInstance.UpdateTimeline("1", t.acc2Bal + amountToTransfer, "saving"); endOutput += "Transcation is complete"; isText = true; } } } userData.SetProperty <bool>("transferNeedsConfirmation", false); isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } else { //cancel userData.SetProperty <bool>("transferNeedsConfirmation", false); endOutput += "Transcation has been canceled"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } } else if (stLuis.topScoringIntent.intent == "transfer") { string toAccount = ""; string fromAccount = ""; string amount = ""; bool invalid = false; try { string test = stLuis.entities[2].type; } catch (Exception e) { invalid = true; } if (!invalid) { for (int i = 0; i < 3; i++) { if (stLuis.entities[i].type == "accountTypeTo") { toAccount = stLuis.entities[i].entity; } else if (stLuis.entities[i].type == "accountTypeFrom") { fromAccount = stLuis.entities[i].entity; } else if (stLuis.entities[i].type == "number") { amount = stLuis.entities[i].entity; } } /* * if ((string.IsNullOrEmpty(toAccount)) || (string.IsNullOrEmpty(fromAccount)) || (string.IsNullOrEmpty(amount)) || !(amount.All(char.IsDigit))) * { * endOutput += "Please specify the account you are transferring from/to as well as the amount in numerical values only\n\n"; * isText = true; * } */ amount = amount.Replace(" ", string.Empty); double amountValue = Convert.ToDouble(amount); //may use try catch if (fromAccount.Contains("cheque")) { if (toAccount.Contains("saving")) { userData.SetProperty <string>("transferFrom", "cheque"); userData.SetProperty <string>("transferTo", "saving"); userData.SetProperty <double>("transferAmount", amountValue); //convert to double before pls userData.SetProperty <bool>("transferNeedsConfirmation", true); endOutput += "Are you sure that you want to transfer $" + amountValue + " from your Cheque to your Saving account? Y/N"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } else if (toAccount.Contains("credit")) { userData.SetProperty <string>("transferFrom", "cheque"); userData.SetProperty <string>("transferTo", "credit"); userData.SetProperty <double>("transferAmount", amountValue); //convert to double before pls userData.SetProperty <bool>("transferNeedsConfirmation", true); endOutput += "Are you sure that you want to transfer $" + amountValue + " from your Cheque to your Credit card account? Y/N"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } } else if (fromAccount.Contains("saving")) { if (toAccount.Contains("cheque")) { userData.SetProperty <string>("transferFrom", "saving"); userData.SetProperty <string>("transferTo", "cheque"); userData.SetProperty <double>("transferAmount", amountValue); //convert to double before pls userData.SetProperty <bool>("transferNeedsConfirmation", true); endOutput += "Are you sure that you want to transfer $" + amountValue + " from your Saving to your Cheque account? Y/N"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } else if (toAccount.Contains("credit")) { userData.SetProperty <string>("transferFrom", "saving"); userData.SetProperty <string>("transferTo", "credit"); userData.SetProperty <double>("transferAmount", amountValue); //convert to double before pls userData.SetProperty <bool>("transferNeedsConfirmation", true); endOutput += "Are you sure that you want to transfer $" + amountValue + " from your Saving to your Credit card account? Y/N"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } } else if (fromAccount.Contains("credit")) { if (toAccount.Contains("cheque")) { userData.SetProperty <string>("transferFrom", "credit"); userData.SetProperty <string>("transferTo", "cheque"); userData.SetProperty <double>("transferAmount", amountValue); //convert to double before pls userData.SetProperty <bool>("transferNeedsConfirmation", true); endOutput += "Are you sure that you want to transfer $" + amountValue + " from your Credit Card to your Cheque account? Y/N"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } else if (toAccount.Contains("saving")) { userData.SetProperty <string>("transferFrom", "credit"); userData.SetProperty <string>("transferTo", "saving"); userData.SetProperty <double>("transferAmount", amountValue); //convert to double before pls userData.SetProperty <bool>("transferNeedsConfirmation", true); endOutput += "Are you sure that you want to transfer $" + amountValue + " from your Credit Card to your Saving account? Y/N"; isText = true; await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } } } else { endOutput += "Please specify the account you are transferring from/to as well as the amount in numerical values only\n\n"; isText = true; } } else if (stLuis.topScoringIntent.intent == "getRate") { if (stLuis.entities[0].type == "currency") { Exchange.Rootobject exchange = await Exchange.exchangeClient.ParseUserInput("NZD"); if (stLuis.entities[0].entity == "usd") { double amount = exchange.rates.USD; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " USD"; } else if (stLuis.entities[0].entity == "aud") { double amount = exchange.rates.AUD; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " AUD"; } else if (stLuis.entities[0].entity == "cny") { double amount = exchange.rates.CNY; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " CNY"; } else if (stLuis.entities[0].entity == "gbp") { double amount = exchange.rates.GBP; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " GBP"; } else if (stLuis.entities[0].entity == "hkd") { double amount = exchange.rates.HKD; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " HKD"; } else if (stLuis.entities[0].entity == "jpy") { double amount = exchange.rates.JPY; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " JPY"; } else if (stLuis.entities[0].entity == "krw") { double amount = exchange.rates.KRW; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " KRW"; } else if (stLuis.entities[0].entity == "sgd") { double amount = exchange.rates.SGD; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " SGD"; } else if (stLuis.entities[0].entity == "thb") { double amount = exchange.rates.THB; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " THB"; } else if (stLuis.entities[0].entity == "eur") { double amount = exchange.rates.EUR; endOutput += "1 NZD equals " + Math.Round(amount, 2) + " EUR"; } else { endOutput += "Are you trying to obtain an exchange rate? Can you try again with a different query?"; } isText = true; } else { endOutput += "Are you trying to obtain an exchange rate? If so, try again with a slighly different phase"; isText = true; } } else if (userMessage.ToLower().Contains("account")) { List <customerInfo> accountInfo = await AzureManager.AzureManagerInstance.GetTimelines("1"); bool infoFound = false; foreach (customerInfo t in accountInfo) { infoFound = true; Activity replyToConversation = activity.CreateReply(""); replyToConversation.Recipient = activity.From; replyToConversation.Type = "message"; replyToConversation.AttachmentLayout = AttachmentLayoutTypes.Carousel; replyToConversation.Attachments = new List <Attachment>(); string[] accountName = new string[3]; string[] accountNum = new string[3]; double[] accountBalance = new double[3]; string[] accountPicture = new String[3]; int numberOfAccount = 0; if (t.acc1No != null) { accountName[numberOfAccount] = t.acc1Name; accountNum[numberOfAccount] = t.acc1No; accountBalance[numberOfAccount] = t.acc1Bal; accountPicture[numberOfAccount] = "http://www.fitsnews.com/wp-content/uploads/2012/11/bank-account-numbers.jpg"; numberOfAccount++; if (t.acc2No != null) { accountName[numberOfAccount] = t.acc2Name; accountNum[numberOfAccount] = t.acc2No; accountBalance[numberOfAccount] = t.acc2Bal; accountPicture[numberOfAccount] = "http://gundomoney.com/wp-content/uploads/2016/01/saving-account-interest-rate.jpg"; numberOfAccount++; } if (t.acc3No != null) { accountName[numberOfAccount] = t.acc3Name; accountNum[numberOfAccount] = t.acc3No; accountBalance[numberOfAccount] = t.acc3Bal; accountPicture[numberOfAccount] = "http://www.psdgraphics.com/file/credit-card-perspective.jpg"; numberOfAccount++; } } for (int i = 0; i < numberOfAccount; i++) { List <CardImage> cardImages = new List <CardImage>(); cardImages.Add(new CardImage(url: accountPicture[i])); HeroCard plCard = new HeroCard() { Title = $" {accountName[i]}", Subtitle = $" {accountNum[i]}", //Account Number Text = $"Available Balance: ${Math.Round(accountBalance[i],2)}", Images = cardImages, }; Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); } await connector.Conversations.SendToConversationAsync(replyToConversation); return(Request.CreateResponse(HttpStatusCode.OK)); } if (!infoFound) { endOutput += "Hmm, something gone wrong. Could you please try again later."; isText = true; } } else if (userMessage.ToLower().Contains("detail") || userMessage.ToLower().Contains("info")) { List <customerInfo> timelines = await AzureManager.AzureManagerInstance.GetTimelines("1"); foreach (customerInfo t in timelines) { endOutput += "#Your Detail# \n\n ##" + t.firstName + " " + t.lastName + " \n\n**Phone Number:** " + t.phoneNum + "\n\n**Address:** " + t.address + ""; } isText = true; } else if (userMessage.ToLower().Contains("help")) { endOutput += "Something I can do: \n\n * Show your account info \n\n * Transfer funds between your accounts \n\n * Show your personal details \n\n * Show exchange rates information"; isText = true; } else if (userMessage.ToLower().Contains("thank")) { endOutput += "It's my pleasure"; isText = true; } else if (userMessage.ToLower().Contains("hello") || userMessage.ToLower().Contains("hi")) { endOutput += ":)"; isText = true; } else if (userMessage.ToLower().Contains("contoso")) { Activity replyToConversation = activity.CreateReply("Here's Contoso Bank Info"); replyToConversation.Recipient = activity.From; replyToConversation.Type = "message"; replyToConversation.Attachments = new List <Attachment>(); List <CardImage> cardImages = new List <CardImage>(); cardImages.Add(new CardImage(url: "https://cdn2.f-cdn.com/contestentries/699966/18283068/57a8de35ca18f_thumb900.jpg")); List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = "http://contoso.com", Type = "openUrl", Title = "Contoso Website" }; cardButtons.Add(plButton); ThumbnailCard plCard = new ThumbnailCard() { Title = "Contoso", Subtitle = "Call Centre 0800 888 5555", Images = cardImages, Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); await connector.Conversations.SendToConversationAsync(replyToConversation); return(Request.CreateResponse(HttpStatusCode.OK)); } else if (userMessage.ToLower().Contains("forget")) { endOutput = "User data cleared"; await stateClient.BotState.DeleteStateForUserAsync(activity.ChannelId, activity.From.Id); isText = true; } else { endOutput += "I'm not sure I understand. Type 'Help' for more information"; isText = true; } } else { Activity message = activity.CreateReply("Hello, welcome to Contoso BotBanking! How can I help you today?"); await connector.Conversations.ReplyToActivityAsync(message); userData.SetProperty <bool>("launched", true); await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData); } if (isText) { Activity infoReply = activity.CreateReply(endOutput); await connector.Conversations.ReplyToActivityAsync(infoReply); } } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { CheckNews news = new CheckNews(); CheckWeather weather = new CheckWeather(); Prompting prompts = new Prompting(); Enquiry Enquiry = new Enquiry(); if (activity.Type == ActivityTypes.Message) { Luis.StockLUIS stLuis = await Luis.LUISStockClient.ParseUserInput(activity.Text); string strRet = " "; int len = 0; // Get the stateClient to get/set Bot Data //StateClient _stateClient = activity.GetStateClient(); //BotData _botData = _stateClient.BotState.GetUserData(activity.Type, activity.Text); ; //data base connection string connectionString = ""; connectionString = "Data Source=VISHWANATH\\SQLSERVER2014;Initial Catalog=Bot_db;Integrated Security=true;User ID=Vishwanath; Password = "******"Dialogs": string[] dialog = { "wassuup..!!", "Hello there... how can i help you??", "hello... i'm here to help you" }; strRet = dialog[new Random().Next(0, dialog.Length)]; break; case "Intro": string[] Intro = { "I'm xxx.You ask anything related to career guidance and apart from that you can get trending news and weather forecast. What's your name?", "Hey..!!!!.I'm xxx.Nice to meet you. You can get career-related information.By the way what's your name.", "I'm the best bot you can ever have" }; strRet = Intro[new Random().Next(0, Intro.Length)]; break; case "NormalConvo": string[] Convo = { "Don't worry..we will solve it together.", "Tell me what's worrying you", "I guess I can solve it" }; strRet = Convo[new Random().Next(0, Convo.Length)]; break; case "User": string name = stLuis.entities[0].entity; string[] user = { "Heyy " + name + " what can I do ", "wasupp? " + name + " how are you doin?" }; strRet = user[new Random().Next(0, user.Length)]; break; case "End_Convo": string[] endConvo = { "It was nice talking to you. I hope this would be helpful.", "I would be glad if this helps you in choosing the right path", "I am happy, if this conversation would be of any help in choosing correct path for your career.All the best, hope you achieve great things ahead." }; strRet = endConvo[new Random().Next(0, endConvo.Length)]; break; case "News": await news.getNews(); Activity reply2 = activity.CreateReply("News:"); reply2.Attachments = new List <Attachment>(); reply2.AttachmentLayout = AttachmentLayoutTypes.Carousel; for (int i = 0; i < 10; i++) { reply2.Attachments.Add( new HeroCard { Title = news.title[i], Subtitle = news.desc[i], Images = new List <CardImage> { new CardImage(url: news.urlToImage[i]) }, Buttons = new List <CardAction> { new CardAction() { Value = news.url[i], Type = "openUrl", Title = "More" } } }.ToAttachment() ); } await connector.Conversations.ReplyToActivityAsync(reply2); break; case "Weather": string result = stLuis.entities[0].entity; string strWea = await weather.getWeather(result); string[] words = strWea.Split(','); Activity reply1 = activity.CreateReply("weather:"); string subTitle = "Temperature (celcius): " + words[0] + " \n" + "Condition: " + words[1] + " \n" + "Humidity: " + words[3]; reply1.AttachmentLayout = AttachmentLayoutTypes.Carousel; HeroCard card = new HeroCard() { Title = "Current Weather", Subtitle = subTitle, Images = new List <CardImage> { new CardImage(url: "https:" + words[2]) } }; reply1.Attachments = new List <Attachment> { card.ToAttachment( ) }; await connector.Conversations.ReplyToActivityAsync(reply1); break; case "Course": string fields = stLuis.entities[0].entity.ToLower(); //for (int i = 0; i < 2; i++) if (stLuis.entities[1].type.ToLower() == "field") { fields = stLuis.entities[1].entity.ToLower(); } con.Open(); cmd = new SqlCommand("select Course,Course_Desc,Years,Url from Courses where Field = '" + fields + "'", con); dr = cmd.ExecuteReader(); string[] Course = new string[30]; string[] Course_Desc = new string[30]; string[] Years = new string[30]; string[] Url1 = new string[30]; while (dr.Read()) { Course[len] = "" + dr["Course"]; Course_Desc[len] = "" + dr["Course_Desc"]; Years[len] = "" + dr["Years"]; Url1[len] = "" + dr["Url"]; len++; } dr.Close(); cmd.Dispose(); con.Close(); Activity reply5 = activity.CreateReply(); reply5.Attachments = new List <Attachment>(); reply5.AttachmentLayout = AttachmentLayoutTypes.Carousel; for (int i = 0; i < len; i++) { reply5.Attachments.Add( new ThumbnailCard { Title = Course[i], Subtitle = Course_Desc[i] + "-" + Years[i], Images = new List <CardImage> { new CardImage { Url = Url1[i], } }, }.ToAttachment() ); } await connector.Conversations.ReplyToActivityAsync(reply5); //} /*catch (IndexOutOfRangeException e) * { * strRet = "Ummm...can you specify in the following format 'Courses in field name' without any typos."; * }*/ break; case "Specialization": string fieldss = ""; try { for (int i = 0; i < 2; i++) { if (stLuis.entities[i].type.ToLower() == "field") { fieldss = stLuis.entities[i].entity.ToLower(); } } con.Open(); cmd = new SqlCommand("select Specialization,S_Desc, Url from Specializations where Field = '" + fieldss + "'", con); dr = cmd.ExecuteReader(); string[] Specialization = new string[34]; string[] S_Desc = new string[34]; string[] Url = new string[34]; Activity reply4 = activity.CreateReply(" "); reply4.Attachments = new List <Attachment>(); reply4.AttachmentLayout = AttachmentLayoutTypes.Carousel; while (dr.Read()) { Specialization[len] = "" + dr["Specialization"]; S_Desc[len] = "" + dr["S_Desc"]; Url[len] = "" + dr["Url"]; len++; } dr.Close(); cmd.Dispose(); con.Close(); for (int i = 0; i < len; i++) { reply4.Attachments.Add( new ThumbnailCard { Title = Specialization[i], Subtitle = S_Desc[i], Images = new List <CardImage> { new CardImage { Url = Url[i], } }, }.ToAttachment() ); } await connector.Conversations.ReplyToActivityAsync(reply4); } catch (IndexOutOfRangeException e) { strRet = "Ummm...can you specify in the following format 'Specialization in field name' without any typos."; } break; case "Exams": string field = stLuis.entities[0].entity.ToLower(); //for (int i = 0; i < 2; i++) if (stLuis.entities[1].type.ToLower() == "field") { field = stLuis.entities[1].entity.ToLower(); } con.Open(); cmd = new SqlCommand("select Exam_Name,Exam_Desc from Exams where Exam_ID IN (select Exam_ID from UG_Fields where Field = '" + field + "') ", con); dr = cmd.ExecuteReader(); string[] Exam_Name = new string[7]; string[] Exam_Desc = new string[7]; Activity reply3 = activity.CreateReply(" "); reply3.Attachments = new List <Attachment>(); reply3.AttachmentLayout = AttachmentLayoutTypes.Carousel; while (dr.Read()) { Exam_Name[len] = "" + dr["Exam_Name"]; Exam_Desc[len] = "" + dr["Exam_Desc"]; len++; } dr.Close(); cmd.Dispose(); con.Close(); for (int i = 0; i < len; i++) { reply3.Attachments.Add( new ThumbnailCard { Title = Exam_Name[i], Subtitle = Exam_Desc[i], Images = new List <CardImage> { new CardImage { Url = $"http://d2cyt36b7wnvt9.cloudfront.net/100marks/wp-content/uploads/2015/12/15151818/Entrance-exams.jpg" } }, }.ToAttachment() ); } await connector.Conversations.ReplyToActivityAsync(reply3); break; case "Career": await Conversation.SendAsync(activity, () => new RootDialog()); break; case "None": strRet = "I think you are going off topic. I can help you with career, news and weather. Please ask any queries related to this. "; break; default: string worriedFace = "\U0001F61F"; strRet = "Sorry, I am not getting you..." + worriedFace; break; } if (strRet != " ") { // return our reply to the user Activity reply = activity.CreateReply(strRet); await connector.Conversations.ReplyToActivityAsync(reply); } } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }