Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private DocumentSelectOption[] GetCarouselOptions(string gasStationId, bool isFavorite)
        {
            var fixPriceOption = new DocumentSelectOption
            {
                Label = new DocumentContainer {
                    Value = "✍️ Corrigir preço"
                },
                Value = new DocumentContainer {
                    Value = new Trigger {
                        StateId = "3.1.1", Payload = gasStationId
                    }
                },
            };

            var favoriteGastationOption =
                isFavorite ?
                new DocumentSelectOption
            {
                Label = new DocumentContainer {
                    Value = "🚫 Desfavoritar"
                },
                Value = new DocumentContainer {
                    Value = new Trigger {
                        StateId = "3.1.2", Payload = gasStationId
                    }
                },
            }
                :
            new DocumentSelectOption
            {
                Label = new DocumentContainer {
                    Value = "⭐ Favoritar posto"
                },
                Value = new DocumentContainer {
                    Value = new Trigger {
                        StateId = "3.1.2", Payload = gasStationId
                    }
                },
            };

            var routeOption = new DocumentSelectOption
            {
                Label = new DocumentContainer {
                    Value = "🚗 Definir rota"
                },
                Value = new DocumentContainer {
                    Value = new Trigger {
                        StateId = "3.1.3", Payload = gasStationId
                    }
                },
            };

            return(new DocumentSelectOption[]
            {
                fixPriceOption,
                favoriteGastationOption,
                routeOption
            });
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public static DocumentSelectOption CreateQuickReplyDefaultButton(string text, string key)
        {
            var button = new DocumentSelectOption();

            button.Label       = new DocumentContainer();
            button.Label.Value = CreateText(text);
            button.Value       = new DocumentContainer();
            button.Value.Value = CreateText(key);

            return(button);
        }
Ejemplo n.º 5
0
        public static DocumentSelectOption CreateQuickReplySendLocationButton()
        {
            var button = new DocumentSelectOption();

            button.Label       = new DocumentContainer();
            button.Label.Value = new Input();
            (button.Label.Value as Input).Validation      = new InputValidation();
            (button.Label.Value as Input).Validation.Rule = InputValidationRule.Type;
            (button.Label.Value as Input).Validation.Type = Location.MediaType;

            return(button);
        }
Ejemplo n.º 6
0
        public DocumentSelectOption CreateDocumentSelectionOption(int order, string text, WebLink value)
        {
            var doc = new DocumentSelectOption();

            doc.Order       = order;
            doc.Label       = new DocumentContainer();
            doc.Label.Value = value;
            //doc.Value = new DocumentContainer();
            //doc.Value.Value = value;

            return(doc);
        }
        private DocumentSelectOption[] GetOptions(CardMessageResponse cardMessageResponse)
        {
            DocumentSelectOption[] options = null;

            if (cardMessageResponse.Buttons != null && cardMessageResponse.Buttons.Count() > 0)
            {
                options = new DocumentSelectOption[cardMessageResponse.Buttons.Count()];

                for (int j = 0; j < cardMessageResponse.Buttons.Count(); j++)
                {
                    if (!string.IsNullOrEmpty(cardMessageResponse.Buttons[j].Postback))
                    {
                        if (cardMessageResponse.Buttons[j].Postback.Contains("http"))
                        {
                            options[j] = new DocumentSelectOption
                            {
                                Label = new DocumentContainer
                                {
                                    Value = new WebLink
                                    {
                                        Title = !string.IsNullOrEmpty(cardMessageResponse.Buttons[j].Text) ? cardMessageResponse.Buttons[j].Text : null,
                                        Uri   = new Uri(cardMessageResponse.Buttons[j].Postback)
                                    }
                                }
                            };
                        }
                        else
                        {
                            options[j] = new DocumentSelectOption
                            {
                                Label = new DocumentContainer
                                {
                                    Value = new PlainText
                                    {
                                        Text = !string.IsNullOrEmpty(cardMessageResponse.Buttons[j].Text) ? cardMessageResponse.Buttons[j].Text : null
                                    }
                                },
                                Value = new DocumentContainer
                                {
                                    Value = new PlainText
                                    {
                                        Text = cardMessageResponse.Buttons[j].Postback
                                    }
                                }
                            };
                        }
                    }
                }
            }

            return(options);
        }
Ejemplo n.º 8
0
        public DocumentSelectOption CreateDocumentSelectionOption(int?order, string text, object value = null)
        {
            value = value ?? order;

            var doc = new DocumentSelectOption();

            doc.Order       = order;
            doc.Label       = new DocumentContainer();
            doc.Label.Value = new PlainText {
                Text = $"{text}"
            };
            doc.Value       = new DocumentContainer();
            doc.Value.Value = new PlainText {
                Text = $"{value}"
            };

            return(doc);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
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;
            //$"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);
        }
Ejemplo n.º 11
0
        public DocumentSelectOption[] CreateDocumentSelectOptions(List <CarrosselOptions> options)
        {
            DocumentSelectOption[] opts = new DocumentSelectOption[options.Count];
            int i = 0;

            foreach (var option in options)
            {
                if (option.label.GetType() == typeof(WebLink))
                {
                    opts[i]       = new DocumentSelectOption();
                    opts[i].Label = new DocumentContainer {
                        Value = (WebLink)option.label
                    };
                    opts[i].Value = new DocumentContainer {
                        Value = option.value.ToString()
                    };
                    i++;
                }
                else
                {
                    opts[i]       = new DocumentSelectOption();
                    opts[i].Label = new DocumentContainer {
                        Value = new PlainText {
                            Text = option.label.ToString()
                        }
                    };
                    opts[i].Value = new DocumentContainer {
                        Value = new PlainText {
                            Text = option.value.ToString()
                        }
                    };
                    i++;
                }
            }
            return(opts);
        }
        //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);
        }