Example #1
0
        private async Task MessageReceivedAsync(IDialogContext context, IAwaitable <object> result)
        {
            try
            {
                var    activity = await result as Activity;
                string message  = WebUtility.HtmlDecode(activity.Text);

                if (string.IsNullOrEmpty(message) == true)
                {
                    return;
                }

                // Handle the explicit invocation case in Skype
                string channelId = GetChannelId(activity);

                if (channelId == "skype" && message.StartsWith(activity.Recipient.Name) == true)
                {
                    message = message.Substring(activity.Recipient.Name.Length).Trim();
                }
                else if (channelId == "skype" && message.StartsWith("@" + activity.Recipient.Name) == true)
                {
                    message = message.Substring(activity.Recipient.Name.Length + 1).Trim();
                }

                // Handle intents
                LUISResult luisResult = await LUIS.QueryAsync(message);

                string   intent   = luisResult.TopScoringIntent?.Intent;
                string[] entities = luisResult.Entities?.Select(e => e.entity)?.ToArray() ?? new string[0];

                if (intent == "greeting")
                {
                    await ProcessGreetingIntent(context, activity);
                }
                else if (intent == "who")
                {
                    await ProcessQueryIntent(context, activity, BotTask.AskWho, message, entities);
                }
                else if (intent == "learnmore")
                {
                    await ProcessQueryIntent(context, activity, BotTask.AskLearnMore, message, entities);
                }
                else
                {
                    await ProcessQueryIntent(context, activity, BotTask.AskQuestion, message, entities);
                }

                context.Wait(MessageReceivedAsync);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MessageReceivedAsync throws expcetion: " + ex);
            }
        }
        private async static Task <LUISResult> GetLUISResult(string message)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "your key here");
            var uri = "your luis url here" + message;

            HttpResponseMessage response = await client.GetAsync(uri);

            var result = await response.Content.ReadAsStringAsync();

            LUISResult lr = JsonConvert.DeserializeObject <LUISResult>(result);

            return(lr);
        }
Example #3
0
        private async static Task <LUISResult> GetLUISResult(string message)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "0b86ab46c22944e2a5e7f4f79a6db05d");
            var uri = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/bb1db568-7477-4682-a427-aa761960138f?subscription-key=0b86ab46c22944e2a5e7f4f79a6db05d&timezoneOffset=0&verbose=true&q=" + message;

            HttpResponseMessage response = await client.GetAsync(uri);

            var result = await response.Content.ReadAsStringAsync();

            LUISResult lr = JsonConvert.DeserializeObject <LUISResult>(result);

            return(lr);
        }
Example #4
0
        /// <summary>
        /// Query LUIS service to obtain results
        /// </summary>
        public async Task <LUISResult> QueryAsync(string query)
        {
            if (string.IsNullOrEmpty(query) == true)
            {
                return(default(LUISResult));
            }

            query = WebUtility.UrlEncode(query);

            // Get request uri
            string requestUrl = this.BaseServiceUrl + "&verbose=true&timezoneOffset=0&q=" + query;
            Uri    requestUri = new Uri(requestUrl);

            LUISResult result = await HttpClientUtility.GetAsync <LUISResult>(requestUri, this.RequestHeaders);

            return(result);
        }
Example #5
0
        static void Main(string[] args)
        {
            //GetTweetsByHashTag("#machinelearning");

            //ProcessSentiment("1", "I love this new iphone");
            //ProcessSentiment("2", "I can't stand this new iphone");
            //ProcessSentiment("3", "I'm undecided about this new iphone, will wait a few more weeks");

            //ProcessEntities("1", "I love this new iphone");
            //ProcessEntities("2", "I can't stand this new iphone");
            //ProcessEntities("3", "I'm undecided about this new iphone, will wait a few more weeks");

            //ProcessKeyPhrases("1", "I love this new iphone");
            //ProcessKeyPhrases("2", "I can't stand this new iphone");
            //ProcessKeyPhrases("3", "I'm undecided about this new iphone, will wait a few more weeks");

            LUISResult lUISResultLead = GetLUISResult("I'm thinking of getting a new phone, any recommendations?").Result;
        }