コード例 #1
0
        public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> result)
        {
            var message = await result;

            string entity = "";

            if (message.Text.Length > 0)
            {
                entity = message.Text;
            }

            await context.PostAsync("Here is a weather : ");

            if (entity == "")
            {
                entity = "Mostar";
            }
            try
            {
                CardUtil.showWeatherHeroCard((IMessageActivity)context.Activity, WeatherData.getWeatherData(entity));
            }
            catch (Exception e)
            {
                await context.PostAsync($"I couldn't find a weather forecast :( You can try again. ");
            }

            context.Done <object>(null);
        }
コード例 #2
0
        public async Task Weather(IDialogContext context, LuisResult result)
        {
            // OpenWeatherAPI openWeatherAPI = new OpenWeatherAPI(WebConfigurationManager.AppSettings["OpenWeatherAPI"]);
            //OpenWeatherAPI openWeatherAPI = new OpenWeatherAPI("bd5e378503939ddaee76f12ad7a97608");
            string          entity = "";
            QureyController qc     = new QureyController();

            qc.PostQuestionOne(result.Query, result.TopScoringIntent.Intent, result.TopScoringIntent.Score.ToString(), "0");

            if (result.Entities.Count > 0)
            {
                entity = result.Entities[0].Entity;
            }

            if (entity == "" || WeatherData.getWeatherData(entity) == null)
            {
                context.Call(new WeatherDialog(), this.ResumeAfterOptionDialog);
            }
            else
            {
                try
                {
                    CardUtil.showWeatherHeroCard((IMessageActivity)context.Activity, WeatherData.getWeatherData(entity));
                    string res = "Weather for entity";
                    qc.PostAnswerOne(res, result.TopScoringIntent.Intent);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Error when generating data: {e}");
                    await context.PostAsync($"I couldn't find a weather forecast :( You can try again. ");
                }
            }
        }