public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            switch (turnContext.Activity.Type)
            {
            case ActivityTypes.Message:
                if (turnContext.Activity.Text == "AMAZON.CancelIntent")
                {
                    await turnContext.SendActivityAsync("You asked to cancel!");
                }
                else
                {
                    await turnContext.SendActivityAsync($"You said '{turnContext.Activity.Text}'\n");

                    turnContext.AlexaSetCard(new AlexaCard()
                    {
                        Type    = AlexaCardType.Simple,
                        Title   = "Alexa Card Sample",
                        Content = $"You said '{turnContext.Activity.Text}'\n",
                    });
                }

                break;

            case AlexaRequestTypes.LaunchRequest:
                var responseMessage = $"Hello, how can I help you?!";
                await turnContext.SendActivityAsync(responseMessage);

                break;
            }
        }
Ejemplo n.º 2
0
        // Send Activity to channels
        private async Task SendActivity(ITurnContext turnContext, string message)
        {
            Activity activity = turnContext.Activity.CreateReply();

            // Fetching the gold rates
            GoldRate result = GoldRatesParser.GetRates().Result;

            // Messages based upon the entity's value
            if (string.IsNullOrEmpty(message))
            {
                activity.Text = string.Format(Messages.GetRateMessages(), result.Carat24, result.Carat22);
            }
            else if (message == "22")
            {
                activity.Text = string.Format(Messages.GetRateCaratMessages(), message, result.Carat22);
            }
            else
            {
                activity.Text = string.Format(Messages.GetRateCaratMessages(), message, result.Carat24);
            }

            // Platform specific cards (Google)
            if (turnContext.Activity.ChannelId == "google")
            {
                var card = new GoogleBasicCard()
                {
                    Content = new GoogleBasicCardContent()
                    {
                        Title         = "Today's gold rate",
                        Subtitle      = "Keeping you up to date about the gold rates on daily basis.",
                        FormattedText = activity.Text,
                        Display       = ImageDisplayOptions.DEFAULT,
                        Image         = new Image()
                        {
                            Url = "https://images-na.ssl-images-amazon.com/images/I/71lpB+tqfgL._SL210_QL95_BG0,0,0,0_FMpng_.png"
                        },
                    },
                };

                turnContext.GoogleSetCard(card);
            }

            // Platform specific cards (Alexa)
            if (turnContext.Activity.ChannelId == "alexa")
            {
                turnContext.AlexaSetCard(new AlexaCard()
                {
                    Type    = AlexaCardType.Simple,
                    Title   = "Today's gold rate",
                    Content = activity.Text
                });
            }

            // Adaptive Cards can also be written here to support other OOTB channels

            await turnContext.SendActivityAsync(activity);
        }
Ejemplo n.º 3
0
        private async Task ProcessWeatherAsync(ITurnContext context, WeatherDetails weatherDetails, CancellationToken cancellationToken)
        {
            Logger.LogInformation("ProcessWeatherAsync");

            // Retrieve LUIS results for Weather.
            if (weatherDetails != null)
            {
                // await turnContext.SendActivityAsync(MessageFactory.Text($"ProcessWeather entities were found in the message:\n\n{string.Join("\n\n", result.Entities.Select(i => i.Entity))}"), cancellationToken);
                GetWeatherInPlaceAction action = new GetWeatherInPlaceAction();
                var place       = weatherDetails.Location;
                var date        = weatherDetails.Date;
                var weatherCard = (AdaptiveCards.AdaptiveCard) await action.FulfillAsync(place, date, _luisRecognizer.APIXUKey);

                var alexaWeatherCard = (AlexaCardContent)await action.FulfillAsyncAlexa(place, date, _luisRecognizer.APIXUKey);

                if (weatherCard == null)
                {
                    await context.SendActivityAsync(MessageFactory.Text($"Are you sure that's a real City? {place}."), cancellationToken);

                    if (alexaWeatherCard == null)
                    {
                        context.AlexaSetCard(new AlexaCard()
                        {
                            Type    = AlexaCardType.Standard,
                            Title   = "AQMD Weather",
                            Content = $"Are you sure that's a real City? {place}.",
                        });
                    }
                }
                else
                {
                    // await turnContext.AlexaSendProgressiveResponse("Hold on, I will just check that for you.");
                    var adaptiveCardAttachment = new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = weatherCard,
                    };
                    await context.SendActivityAsync(alexaWeatherCard.text);

                    context.AlexaSetCard(new AlexaCard()
                    {
                        Type    = AlexaCardType.Standard,
                        Title   = alexaWeatherCard.title,
                        Content = alexaWeatherCard.text,
                        Image   = new AlexaCardImage {
                            SmallImageUrl = alexaWeatherCard.smallImageUrl
                        }
                    });
                    await context.SendActivityAsync(MessageFactory.Attachment(adaptiveCardAttachment), cancellationToken);
                }
            }
            else
            {
                await context.SendActivityAsync(MessageFactory.Text($"Please specify a city or location. For Example Ask Weather in California."), cancellationToken);

                context.AlexaSetCard(new AlexaCard()
                {
                    Type    = AlexaCardType.Standard,
                    Title   = $"Weather App",
                    Content = $"Please specify a city or location. For Example Ask Weather in California.",
                });
            }
        }