Ejemplo n.º 1
0
        public static IMessageActivity[] CreateChainCardReply(ChannelPlatform platform, FinalAttractor[] generatedPoints)
        {
            var replies = new IMessageActivity[1];

            var attachments     = new List <Attachment>();
            var attachmentReply = MessageFactory.Attachment(attachments);

            replies[0] = attachmentReply;

            attachmentReply.AttachmentLayout = AttachmentLayoutTypes.Carousel;

            double[][] incoords = new double[generatedPoints.Length][];
            for (int i = 0; i < incoords.Length; i++)
            {
                incoords[i]    = new double[2];
                incoords[i][0] = generatedPoints[i].X.center.point.latitude;
                incoords[i][1] = generatedPoints[i].X.center.point.longitude;
            }

            //var images = new List<CardImage>();
            //images.Add(new CardImage(CreateGoogleMapsStaticThumbnail(incoords[0])));

            var cardAction = new CardAction(ActionTypes.OpenUrl, "Open", value: CreateGoogleMapsRouteUrl(incoords));

            var buttons = new List <CardAction> {
                cardAction,
            };

            var heroCard = new HeroCard
            {
                Title = "Travel Chain on Google Maps",
                //Images = images,
                Buttons = buttons,
                Tap     = cardAction
            };

            attachmentReply.Attachments.Add(heroCard.ToAttachment());

            return(replies);
        }
Ejemplo n.º 2
0
        public static IMessageActivity[] CreateLocationCardsReply(ChannelPlatform platform, double[] incoords, bool showStreetAndEarthThumbnails = false, dynamic w3wResult = null, bool forRemoteViewing = false)
        {
            if (platform == ChannelPlatform.discord)
            {
                var embed = new DiscordEmbedBuilder();

                embed.Author      = new DiscordEmbedBuilder.EmbedAuthor();
                embed.Author.Name = w3wResult?.words;
                embed.Color       = DiscordColor.Azure;

                embed.Title = "View on Google Maps";
                embed.Url   = CreateGoogleMapsUrl(incoords);

                embed.Description  = $"Street View:\n{CreateGoogleStreetViewUrl(incoords)}\n\nGoogle Earth:\n{CreateGoogleEarthUrl(incoords)}";
                embed.ImageUrl     = CreateGoogleMapsStaticThumbnail(incoords);
                embed.ThumbnailUrl = CreateGoogleStreetViewThumbnailUrl(incoords);

                embed.Build();

                var entity = new Entity();
                entity.SetAs(embed);

                var replyActivity = new Activity(entities: new List <Entity> {
                    { entity }
                }, type: "DiscordEmbed");

                return(new IMessageActivity[] { replyActivity });
            }

            var useNativeLocationWidget = platform == ChannelPlatform.telegram || platform == ChannelPlatform.line;

            var replies = new IMessageActivity[useNativeLocationWidget ? 2 : 1];

            if (useNativeLocationWidget)
            {
                var nativeLocationWidgetReply = MessageFactory.Text("");
                var entity = new Entity();
                var geo    = new GeoCoordinates(latitude: incoords[0],
                                                longitude: incoords[1],
                                                elevation: 0);
                var place = new Place(name: w3wResult != null ? "What 3 Words Address" : "Location",
                                      address: w3wResult != null ? w3wResult.words : "",
                                      geo: geo);
                entity.SetAs(place);
                nativeLocationWidgetReply.Entities = new List <Entity>()
                {
                    entity
                };
                replies[1] = nativeLocationWidgetReply;
            }

            var attachments     = new List <Attachment>();
            var attachmentReply = MessageFactory.Attachment(attachments);

            replies[0] = attachmentReply;

            attachmentReply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            attachmentReply.Attachments.Add(CreateGoogleMapCard(incoords, !useNativeLocationWidget || showStreetAndEarthThumbnails, showStreetAndEarthThumbnails, w3wResult, forRemoteViewing: forRemoteViewing));

            if (showStreetAndEarthThumbnails)
            {
                attachmentReply.Attachments.Add(CreateGoogleStreetViewCard(incoords));
                attachmentReply.Attachments.Add(CreateGoogleEarthCard(incoords));
            }

            return(replies);
        }