private List <DocumentSelect> GetItemList(NewsResponse news)
        {
            var itemList = new List <DocumentSelect>();

            foreach (Blog b in news.Blogs)
            {
                var item = new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            AspectRatio = MyConstants.FacebookCarouselAspectRatio,
                            Uri         = new Uri("https:" + b.Thumbnail.Url),
                            Title       = b.Title,
                            Text        = b.Author
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption()
                        {
                            Label = new DocumentContainer
                            {
                                Value = new WebLink {
                                    Uri = new Uri(b.defaultUrl), Text = "Read"
                                }
                            }
                        }
                    }
                };
                itemList.Add(item);
            }
            return(itemList);
        }
Example #2
0
        public static DocumentCollection CreateCarroussel(List <MediaLink> content, List <CarrousselButton> buttons)
        {
            var carroussel = new DocumentCollection();

            //contents.
            carroussel.Items    = new DocumentSelect[content.Count];
            carroussel.ItemType = DocumentSelect.MediaType;

            //Para cada content existente.
            for (int i = 0; i < content.Count; i++)
            {
                var id_button = 0;

                var tmp = new DocumentSelect();
                tmp.Header       = new DocumentContainer();
                tmp.Header.Value = new MediaLink();
                (tmp.Header.Value as MediaLink).Title      = (content[i] as MediaLink).Title;
                (tmp.Header.Value as MediaLink).Text       = (content[i] as MediaLink).Text;
                (tmp.Header.Value as MediaLink).PreviewUri = (content[i] as MediaLink).PreviewUri;
                (tmp.Header.Value as MediaLink).Uri        = (content[i] as MediaLink).Uri;
                (tmp.Header.Value as MediaLink).Type       = (content[i] as MediaLink).Type;

                if (buttons != null)
                {
                    var contentButtons = buttons.Select(b => b).Where(b => b?.Container == i).OrderBy(b => b?.Order);
                    DocumentSelectOption[] tmp_buttons = new DocumentSelectOption[contentButtons.Count()];

                    foreach (var button in contentButtons)
                    {
                        if (button.Type == ButtonType.Default)
                        {
                            DocumentSelectOption tmp_button = new DocumentSelectOption();
                            tmp_button.Order       = button.Order;
                            tmp_button.Label       = new DocumentContainer();
                            tmp_button.Label.Value = button.DocumentType;
                            tmp_button.Value       = new DocumentContainer();
                            tmp_button.Value.Value = CreateText(button.Value);
                            tmp_buttons[id_button] = tmp_button;
                            id_button++;
                        }
                        else if (button.Type == ButtonType.Share)
                        {
                            DocumentSelectOption tmp_button = new DocumentSelectOption();
                            tmp_button.Order       = button.Order;
                            tmp_button.Label       = new DocumentContainer();
                            tmp_button.Label.Value = button.DocumentType;
                            tmp_buttons[id_button] = tmp_button;
                            id_button++;
                        }
                    }
                    tmp.Options = tmp_buttons;
                }
                else
                {
                    tmp.Options = new DocumentSelectOption[0];
                }
                carroussel.Items[i] = tmp;
            }
            return(carroussel);
        }
Example #3
0
        public async Task ReceiveAsync(Message message, CancellationToken cancellationToken = default(CancellationToken))
        {
            DocumentSelect collection = RetornaObjetoDocumentCollection();
            await _sender.SendMessageAsync(collection, message.From, cancellationToken);

            throw new NotImplementedException();
        }
        private List <DocumentSelect> GetItemList(CompetitorElement[] divisionTeams, Flow flowIdentity)
        {
            var tag              = GetTagFromFlow(flowIdentity);
            var buttonsTexts     = GetButtonTextFromFlow(flowIdentity).Split('|');
            var buttonText       = buttonsTexts[0];
            var secondButtonText = "";

            if (buttonsTexts.Length == 2)
            {
                secondButtonText = buttonsTexts[1];
            }
            var itemList = new List <DocumentSelect>();

            foreach (CompetitorElement c in divisionTeams)
            {
                var item = new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            Title       = c.Competitor.Name,
                            Text        = c.Competitor.HomeLocation,
                            Uri         = new Uri(c.Competitor.Logo),
                            AspectRatio = MyConstants.FacebookCarouselAspectRatio
                        }
                    }
                };
                var options     = new List <DocumentSelectOption>();
                var firstOption = new DocumentSelectOption
                {
                    Label = new DocumentContainer {
                        Value = PlainText.Parse(buttonText)
                    },
                    Value = new DocumentContainer {
                        Value = "Add" + tag + c.Competitor.AbbreviatedName
                    }
                };
                options.Add(firstOption);
                if (!secondButtonText.IsNullOrWhiteSpace())
                {
                    var secondOption = new DocumentSelectOption
                    {
                        Label = new DocumentContainer {
                            Value = PlainText.Parse(secondButtonText)
                        },
                        Value = new DocumentContainer {
                            Value = "Remove" + tag + c.Competitor.AbbreviatedName
                        }
                    };
                    options.Add(secondOption);
                }
                item.Options = options.ToArray();
                itemList.Add(item);
            }
            return(itemList);
        }
Example #5
0
        public DocumentSelect getDocumentSelectWithImage()
        {
            JsonDocument jsonDocuments = new JsonDocument();

            jsonDocuments.Add("action", "show-items");
            document2 = new DocumentSelectOption[]
            {
                new DocumentSelectOption
                {
                    Label = new DocumentContainer
                    {
                        Value = new WebLink
                        {
                            Title = "Go to your site",
                            Uri   = new Uri("https://meusanimais.com.br/14-nomes-criativos-para-o-seu-gato/")
                        }
                    }
                },
                new DocumentSelectOption
                {
                    Label = new DocumentContainer
                    {
                        Value = new PlainText
                        {
                            Text = "Show stock here!"
                        }
                    },
                    Value = new DocumentContainer
                    {
                        Value = jsonDocuments
                    }
                }
            };

            var document = new DocumentSelect
            {
                Header = new DocumentContainer
                {
                    Value = new MediaLink
                    {
                        Title       = "Welcome to mad hatter",
                        Text        = "Here we have the best hats for your head.",
                        Type        = "image/jpeg",
                        Uri         = new Uri("http://i.overboard.com.br/imagens/produtos/0741720126/Ampliada/chapeu-new-era-bucket-print-vibe.jpg"),
                        AspectRatio = "1.1"
                    }
                },
                Options = document2
            };

            return(document);
        }
        public async Task <Message> GetCarousel(List <string> teams, CancellationToken cancellationToken)
        {
            var carousel      = new DocumentCollection();
            var carouselItems = new List <DocumentSelect>();

            foreach (string s in teams)
            {
                var team  = GetTeamIdFromTag(s);
                var match = await _owlFilter.GetNextMatchAsync(team);

                var item = new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            Title       = $"{match.StartDate.ConvertLongIntoDateTime().Date.DayOfWeek}",
                            Text        = $"{match.Competitors[0].Name} vs {match.Competitors[1].Name}",
                            Uri         = new Uri("https://s3-sa-east-1.amazonaws.com/i.imgtake.takenet.com.br/ixwke/ixwke.jpg"),
                            AspectRatio = MyConstants.FacebookCarouselAspectRatio
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer {
                                Value = new WebLink {
                                    Uri = new Uri("https://overwatchleague.com/en-us/schedule"), Text = "🗓Full Agenda"
                                }
                            }
                        }
                    }
                };
                carouselItems.Add(item);
            }

            if (carouselItems.Count >= 7)
            {
                carouselItems = carouselItems.Take(7).ToList();
            }

            carousel.Items    = carouselItems.ToArray();
            carousel.Total    = carouselItems.Count;
            carousel.ItemType = DocumentSelect.MediaType;
            return(new Message()
            {
                Content = carousel
            });
        }
Example #7
0
        public DocumentCollection ShowErros()
        {
            var documents = new DocumentSelect[ProcessErrors().Count()];
            var errors    = ProcessErrors();
            var position  = 0;

            foreach (var error in ProcessErrors())
            {
                documents[position] =
                    new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            Title = error.Person.Name,
                            Text  = $"You said {error.AnswerName}.",
                            Type  = "image/jpeg",
                            Uri   = new Uri(error.Person.Uri),
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new WebLink
                                {
                                    Title = "Search on Workplace",
                                    Uri   = new Uri("https://take.facebook.com/search/top/?q=" + error.Person.Name)
                                }
                            }
                        }
                    }
                };

                position++;
            }
            var document = new DocumentCollection
            {
                ItemType = "application/vnd.lime.document-select+json",
                Items    = documents,
            };

            return(document);
        }
        /// <summary>
        /// Método que monta o retorno para criação de um objeto de MENU
        /// </summary>
        /// <param name="NomeDeputado"></param>
        /// <returns></returns>
        private DocumentSelect ProcessaRetorno(string NomeDeputado)
        {
            Models.Deputado modelDeputado = dep.RetornaDeputadoEscolhido(NomeDeputado);

            if (modelDeputado == null)
            {
                return(null);
            }

            //Armazenagem de deputado escolhido
            Opcoes.Instance.DeputadoEscolhido = modelDeputado;

            //Monta um objeto de Menu, exibindo a foto e o nome do deputado
            var document = new DocumentSelect
            {
                Header = new DocumentContainer
                {
                    Value = new MediaLink
                    {
                        Title      = $"DEPUTADO: {modelDeputado.nomeParlamentar}",
                        Text       = $"RETRATO DO DEPUTADO {modelDeputado.nomeParlamentar}",
                        Type       = MediaType.Parse("image/jpg"),
                        PreviewUri = new Uri(modelDeputado.urlFoto),
                        Uri        = new Uri(modelDeputado.urlFoto),
                        Size       = 400
                    }
                },
                Options = new DocumentSelectOption[] {
                    new DocumentSelectOption {
                        Label = new DocumentContainer {
                            Value = new PlainText {
                                Text = "Votações do Deputado"
                            }
                        }, Order = 1
                    },
                    new DocumentSelectOption {
                        Label = new DocumentContainer {
                            Value = new PlainText {
                                Text = "Despesas do Deputado"
                            }
                        }, Order = 2
                    },
                }
            };

            return(document);
        }
Example #9
0
        public static DocumentSelect CreateQuickReply(string MenuText, List <DocumentSelectOption> options)
        {
            DocumentSelect document = new DocumentSelect();

            document.Scope        = SelectScope.Immediate;
            document.Header       = new DocumentContainer();
            document.Header.Value = new PlainText();
            (document.Header.Value as PlainText).Text = MenuText;

            DocumentSelectOption[] selectOption = new DocumentSelectOption[options.Count()];

            for (int i = 0; i < options.Count(); i++)
            {
                selectOption[i] = options[i];
            }

            document.Options = selectOption;

            return(document);
        }
        public static DocumentSelect CreateQuickReply(string MenuText, List <DocumentSelectOption> options)
        {
            DocumentSelect document = new DocumentSelect();

            document.Scope        = SelectScope.Immediate;
            document.Header       = new DocumentContainer();
            document.Header.Value = new PlainText();
            (document.Header.Value as PlainText).Text = MenuText;
            //$"Onde você está? 🙂\n\n📨Envie seu CEP, endereço ou localização"

            DocumentSelectOption[] selectOption = new DocumentSelectOption[options.Count()];

            for (int i = 0; i < options.Count(); i++)
            {
                selectOption[i] = options[i];
            }

            document.Options = selectOption;

            return(document);
        }
Example #11
0
        public void DocumentSelect_ToContainer()
        {
            // Arrange
            var documentSelect = new DocumentSelect
            {
                Header  = PlainText.Parse("Unit tests").ToDocumentContainer(),
                Options = new DocumentSelectOption[]
                {
                    new DocumentSelectOption
                    {
                        Label = PlainText.Parse("Unit test").ToDocumentContainer(),
                        Value = PlainText.Parse("Unit test").ToDocumentContainer()
                    }
                },
                Scope = SelectScope.Immediate
            };

            // Act
            var container = documentSelect.ToDocumentContainer();

            // Assert
            container.Value.ShouldBe(documentSelect);
            container.Type.ShouldBe(DocumentSelect.MediaType);
        }
        private List <DocumentSelect> GetItemList(RankingResponse standings)
        {
            var itemList     = new List <DocumentSelect>();
            var standingList = standings.Content.Take(5).ToList();

            foreach (Content r in standingList)
            {
                var item = new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            AspectRatio = MyConstants.FacebookCarouselAspectRatio,
                            Uri         = new Uri(r.Competitor.Logo),
                            Title       = $"#{r.Placement}: {r.Competitor.Name}",
                            Text        = $"W:{r.Records[0].MatchWin}|L:{r.Records[0].MatchLoss}"
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer {
                                Value = "🔔Add Alert"
                            },
                            Value = new DocumentContainer {
                                Value = $"Add#Alert_{r.Competitor.AbbreviatedName}"
                            }
                        }
                    }
                };
                itemList.Add(item);
            }
            return(itemList);
        }
Example #13
0
 public Task SetPersistentMenuAsync(DocumentSelect persistentMenu, CancellationToken cancellationToken)
 => ProcessCommandAsync <Document>(
     CreateSetCommandRequest(persistentMenu, $"{PROFILE_URI}/{PERSISTENT_MENU_ID}"),
     cancellationToken);
        //Messenger Special Implementations: Receipt, CallButton, List, QuickReply;
        #region Messenger
        public static DocumentCollection MESSENGER_CreateCarouselDocument(CarouselModel carouselModel)
        {
            var carousel = new DocumentCollection();

            //contents.
            carousel.Items    = new DocumentSelect[carouselModel.Cards.Count];
            carousel.ItemType = DocumentSelect.MediaType;

            var cards = carouselModel.Cards.OrderBy(c => c.Order).ToList();

            //Para cada content existente.
            for (int i = 0; i < cards.Count; i++)
            {
                var tmp = new DocumentSelect();
                tmp.Header       = new DocumentContainer();
                tmp.Header.Value = new MediaLink();
                (tmp.Header.Value as MediaLink).Title = cards[i].Title;
                (tmp.Header.Value as MediaLink).Text  = cards[i].Subtitle;

                try
                {
                    (tmp.Header.Value as MediaLink).PreviewUri = new Uri(cards[i].UrlImage);
                    (tmp.Header.Value as MediaLink).Uri        = new Uri(cards[i].UrlImage);
                }
                catch { }

                (tmp.Header.Value as MediaLink).Type = MediaType.Parse("image/*");

                var buttons = cards[i].Buttons.OrderBy(c => c.Order).ToList();

                DocumentSelectOption[] tmp_buttons = new DocumentSelectOption[buttons.Count()];
                if (buttons.Any())
                {
                    for (int j = 0; j < buttons.Count(); j++)
                    {
                        if (buttons[j].Type == Models.ButtonType.Text)
                        {
                            DocumentSelectOption button = new DocumentSelectOption();
                            button.Order       = j;
                            button.Label       = new DocumentContainer();
                            button.Label.Value = GENERIC_CreateTextDocument(buttons[j].Text);
                            button.Value       = new DocumentContainer();
                            button.Value.Value = GENERIC_CreateTextDocument(buttons[j].Value);
                            tmp_buttons[j]     = button;
                        }
                        else if (buttons[j].Type == Models.ButtonType.Link)
                        {
                            DocumentSelectOption button = new DocumentSelectOption();
                            button.Order       = j;
                            button.Label       = new DocumentContainer();
                            button.Label.Value = GENERIC_CreateWebLinkDocument(buttons[j].Value, null, buttons[j].Text);
                            button.Value       = new DocumentContainer();
                            button.Value.Value = GENERIC_CreateTextDocument(buttons[j].Value);
                            tmp_buttons[j]     = button;
                        }
                        else if (buttons[j].Type == Models.ButtonType.Share)
                        {
                            DocumentSelectOption button = new DocumentSelectOption();
                            button.Order       = button.Order;
                            button.Label       = new DocumentContainer();
                            button.Label.Value = new WebLink()
                            {
                                Uri = new Uri("share:")
                            };
                            tmp_buttons[j] = button;
                        }
                    }
                }
                tmp.Options = tmp_buttons;

                carousel.Items[i] = tmp;
            }
            return(carousel);
        }
        public DocumentCollection getDocumentCollectionMenuMultimidia()
        {
            jsonDocuments  = new JsonDocument();
            jsonDocuments2 = new JsonDocument();
            jsonDocuments3 = new JsonDocument();

            jsonDocuments.Add("Key1", "value1");
            jsonDocuments.Add("Key2", "2");

            jsonDocuments2.Add("Key3", "value3");
            jsonDocuments2.Add("Key4", "4");

            jsonDocuments3.Add("Key5", "value5");
            jsonDocuments3.Add("Key6", "6");

            DocumentSelect[] documents = new DocumentSelect[]
            {
                new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            Title = "Title",
                            Text  = "This is a first item",
                            Type  = "image/jpeg",
                            Uri   = new Uri("http://www.isharearena.com/wp-content/uploads/2012/12/wallpaper-281049.jpg"),
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new WebLink
                                {
                                    Title = "Link",
                                    Uri   = new Uri("http://www.adoteumgatinho.org.br/")
                                }
                            }
                        },
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new PlainText
                                {
                                    Text = "Text 1"
                                }
                            },
                            Value = new DocumentContainer
                            {
                                Value = jsonDocuments
                            }
                        }
                    }
                },
                new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            Title = "Title 2",
                            Text  = "This is another item",
                            Type  = "image/jpeg",
                            Uri   = new Uri("http://www.freedigitalphotos.net/images/img/homepage/87357.jpg")
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new WebLink
                                {
                                    Title = "Second link",
                                    Text  = "Weblink",
                                    Uri   = new Uri("https://pt.dreamstime.com/foto-de-stock-brinquedo-pl%C3%A1stico-amarelo-do-pato-image44982058")
                                }
                            }
                        },
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new PlainText {
                                    Text = "Second text"
                                }
                            },
                            Value = new DocumentContainer
                            {
                                Value = jsonDocuments2
                            }
                        },
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new PlainText {
                                    Text = "More one text"
                                }
                            },
                            Value = new DocumentContainer
                            {
                                Value = jsonDocuments3
                            }
                        }
                    }
                }
            };

            var document = new DocumentCollection
            {
                ItemType = "application/vnd.lime.document-select+json",
                Items    = documents,
            };

            return(document);
        }
        private Document GetDocument(string raw, string type)
        {
            if ("text" == type)
            {
                return(PlainText.Parse(raw));
            }

            if ("menu" == type || "quickreply" == type)
            {
                var parts  = raw.Split('|');
                var select = new Select
                {
                    Text    = parts[0],
                    Options = parts
                              .Where(p => p != parts[0])
                              .Select(o => new SelectOption {
                        Text = o, Value = PlainText.Parse(o)
                    })
                              .ToArray(),
                    Scope = ("quickreply" == type) ? SelectScope.Immediate : SelectScope.Transient
                };
                return(select);
            }

            if ("carousel_img" == type)
            {
                var docColl = new DocumentCollection
                {
                    ItemType = DocumentSelect.MediaType
                };

                var items = new List <DocumentSelect>();
                var cards = raw.Split('%');

                foreach (var item in cards)
                {
                    var parts  = item.Split('|');
                    var header = new List <string>();
                    for (int i = 0; i < parts.Length - 1; i++)
                    {
                        header.Add(parts[i]);
                    }
                    var btns = parts[parts.Length - 1].Split('&');

                    var docSel = new DocumentSelect
                    {
                        Header = new DocumentContainer
                        {
                            Value = new MediaLink
                            {
                                Title = header[1],
                                Text  = header[2],
                                Uri   = new Uri("http://site.com/" + header[0] + ".jpg"),
                                Type  = new MediaType(MediaType.DiscreteTypes.Image, MediaType.SubTypes.JPeg)
                            }
                        },
                        Options = btns.Select(b =>
                                              new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new PlainText {
                                    Text = b
                                }
                            }
                        }
                                              ).ToArray()
                    };
                    items.Add(docSel);
                }

                docColl.Items = items.ToArray();
                docColl.Total = docColl.Items.Length;

                return(docColl);
            }

            if ("carousel_txt" == type)
            {
                var docColl = new DocumentCollection
                {
                    ItemType = DocumentSelect.MediaType,
                };

                var items = new List <DocumentSelect>();
                var cards = raw.Split('%');

                foreach (var item in cards)
                {
                    var parts  = item.Split('|');
                    var header = new List <string>();
                    for (int i = 0; i < parts.Length - 1; i++)
                    {
                        header.Add(parts[i]);
                    }
                    var btns = parts[parts.Length - 1].Split('&');

                    var docSel = new DocumentSelect
                    {
                        Header = new DocumentContainer
                        {
                            Value = new PlainText
                            {
                                Text = header[0],
                            }
                        },
                        Options = btns.Select(b =>
                                              new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new PlainText {
                                    Text = b
                                }
                            }
                        }
                                              ).ToArray()
                    };
                    items.Add(docSel);
                }

                docColl.Items = items.ToArray();
                docColl.Total = docColl.Items.Length;

                return(docColl);
            }

            return(PlainText.Parse(raw));
        }
        private List <DocumentSelect> AddLastItem(List <DocumentSelect> list, Flow flow)
        {
            var item = new DocumentSelect();

            if (flow == Flow.News)
            {
                item = new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            AspectRatio = MyConstants.FacebookCarouselAspectRatio,
                            Uri         = new Uri("https://s3-sa-east-1.amazonaws.com/i.imgtake.takenet.com.br/igm0d/igm0d.jpg"),
                            Title       = "News website",
                            Text        = "Wanna see everything?"
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new WebLink {
                                    Uri = new Uri("https://overwatchleague.com/news"), Text = "All news"
                                }
                            }
                        }
                    }
                };
            }
            else if (flow == Flow.Standings)
            {
                item = new DocumentSelect
                {
                    Header = new DocumentContainer
                    {
                        Value = new MediaLink
                        {
                            AspectRatio = MyConstants.FacebookCarouselAspectRatio,
                            Uri         = new Uri("https://s3-sa-east-1.amazonaws.com/i.imgtake.takenet.com.br/imd25/imd25.jpg"),
                            Title       = "Full Standings",
                            Text        = "Wanna see everything?"
                        }
                    },
                    Options = new DocumentSelectOption[]
                    {
                        new DocumentSelectOption
                        {
                            Label = new DocumentContainer
                            {
                                Value = new WebLink {
                                    Uri = new Uri("https://overwatchleague.com/standings"), Text = "Full Standings"
                                }
                            }
                        }
                    }
                };
            }
            list.Add(item);
            return(list);
        }