/// <summary>
        /// 1. IsMultiSelect == false && IsCompact == true => render as a drop down select element
        /// 2. IsMultiSelect == false && IsCompact == false => render as a list of radio buttons
        /// 3. IsMultiSelect == true => render as a list of toggle inputs
        /// </summary>
        protected static HtmlTag ChoiceSetRender(AdaptiveChoiceSetInput adaptiveChoiceSetInput, AdaptiveRenderContext context)
        {
            if (!adaptiveChoiceSetInput.IsMultiSelect)
            {
                if (adaptiveChoiceSetInput.Style == AdaptiveChoiceInputStyle.Compact)
                {
                    var uiSelectElement = new HtmlTag("select")
                                          .Attr("name", adaptiveChoiceSetInput.Id)
                                          .AddClass("ac-input")
                                          .AddClass("ac-multichoiceInput")
                                          .Style("width", "100%");

                    foreach (var choice in adaptiveChoiceSetInput.Choices)
                    {
                        var option = new HtmlTag("option")
                        {
                            Text = choice.Title
                        }
                        .Attr("value", choice.Value);

                        if (choice.Value == adaptiveChoiceSetInput.Value)
                        {
                            option.Attr("selected", string.Empty);
                        }
                        uiSelectElement.Append(option);
                    }

                    return(uiSelectElement);
                }
                else
                {
                    return(ChoiceSetRenderInternal(adaptiveChoiceSetInput, context, "radio"));
                }
            }
            else
            {
                return(ChoiceSetRenderInternal(adaptiveChoiceSetInput, context, "checkbox"));
            }
        }
Esempio n. 2
0
        public void ChoiceSetInput()
        {
            var renderContext = new AdaptiveRenderContext(
                new AdaptiveHostConfig(),
                new AdaptiveElementRenderers <HtmlTag, AdaptiveRenderContext>());

            var dropdownList = new AdaptiveChoiceSetInput()
            {
                Id      = "1",
                Value   = "1,3",
                Style   = AdaptiveChoiceInputStyle.Compact,
                Choices =
                {
                    new AdaptiveChoice()
                    {
                        Title = "Value 1",
                        Value = "1"
                    },
                    new AdaptiveChoice()
                    {
                        Title = "Value 2",
                        Value = "2"
                    },
                    new AdaptiveChoice()
                    {
                        Title = "Value 3",
                        Value = "3"
                    }
                }
            };

            var dropdownGeneratedHtml = TestHtmlRenderer.CallChoiceSetInputRender(dropdownList, renderContext).ToString();

            // Generated HTML should have an additional disabled and hidden option which is selected.
            Assert.AreEqual(
                "<select class='ac-input ac-multichoiceInput' name='1' style='width: 100%;'><option disabled='' hidden='' selected=''/><option value='1'>Value 1</option><option value='2'>Value 2</option><option value='3'>Value 3</option></select>",
                dropdownGeneratedHtml);
        }
Esempio n. 3
0
        private AdaptiveElement GetPlayerControl()
        {
            var repeat = new AdaptiveChoiceSetInput
            {
                Id            = "Repeat",
                Style         = AdaptiveChoiceInputStyle.Compact,
                IsMultiSelect = true,

                Choices = new List <AdaptiveChoice>
                {
                    new AdaptiveChoice
                    {
                        Title = "🔁",
                        Value = "track"
                    }
                },
            };
            var shuffle = new AdaptiveChoiceSetInput
            {
                Id            = "Shuffle",
                Style         = AdaptiveChoiceInputStyle.Compact,
                IsMultiSelect = true,
                Choices       = new List <AdaptiveChoice>
                {
                    new AdaptiveChoice
                    {
                        Title = "🔀",
                        Value = "true"
                    }
                },
            };

            return(new AdaptiveContainer
            {
                VerticalContentAlignment = AdaptiveVerticalContentAlignment.Center,
                Items = new List <AdaptiveElement>
                {
                    new AdaptiveColumnSet
                    {
                        Columns = new List <AdaptiveColumn>
                        {
                            new AdaptiveColumn
                            {
                                SelectAction = new AdaptiveSubmitAction
                                {
                                    DataJson = JsonConvert.SerializeObject(new InputAction
                                    {
                                        Action = "previous"
                                    })
                                },
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = "⏮",
                                        Size = AdaptiveTextSize.Large,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                                    }
                                }
                            },
                            new AdaptiveColumn
                            {
                                SelectAction = new AdaptiveSubmitAction
                                {
                                    DataJson = JsonConvert.SerializeObject(new InputAction
                                    {
                                        Action = "pause"
                                    })
                                },
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = "⏸",
                                        Size = AdaptiveTextSize.Large,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                                    }
                                }
                            },
                            new AdaptiveColumn
                            {
                                SelectAction = new AdaptiveSubmitAction
                                {
                                    Id = "player",
                                    DataJson = JsonConvert.SerializeObject(new InputAction
                                    {
                                        Action = "play"
                                    })
                                },
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = "▶",
                                        Size = AdaptiveTextSize.Large,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                                    }
                                },
                            },
                            new AdaptiveColumn
                            {
                                SelectAction = new AdaptiveSubmitAction
                                {
                                    DataJson = JsonConvert.SerializeObject(new InputAction
                                    {
                                        Action = "next"
                                    })
                                },
                                Items = new List <AdaptiveElement>
                                {
                                    new AdaptiveTextBlock
                                    {
                                        Text = "⏭",
                                        Size = AdaptiveTextSize.Large,
                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Center
                                    }
                                },
                            },
                            new AdaptiveColumn
                            {
                            },
                            new AdaptiveColumn
                            {
                                SelectAction = new AdaptiveSubmitAction
                                {
                                    DataJson = JsonConvert.SerializeObject(new InputAction
                                    {
                                        Action = "playerSettings"
                                    })
                                },
                                Items = new List <AdaptiveElement>
                                {
                                    shuffle,
                                    repeat
                                }
                            }
                        }
                    }
                }
            });
        }
        public static Attachment Generate(ITurnContext turnContext, List <ReportFormatType> reportFormats)
        {
            AdaptiveCard adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

            // Scope choice set for channel/ message for group chat
            var scopeContainer = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };
            var conversationType = turnContext.Activity.Conversation.ConversationType;

            if (conversationType == Constants.ChannelConversationType)
            {
                scopeContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtChannelScopeMessage)
                {
                    Size   = AdaptiveTextSize.Medium,
                    Weight = AdaptiveTextWeight.Default,
                    Wrap   = true,
                });

                var choiceSet = new AdaptiveChoiceSetInput()
                {
                    Id      = ChannelScopeInputId,
                    Style   = AdaptiveChoiceInputStyle.Expanded,
                    Choices = new List <AdaptiveChoice>()
                    {
                        new AdaptiveChoice()
                        {
                            Value = Resources.Strings.ChannelHistoryOptionAll,
                            Title = Resources.Strings.ChannelHistoryOptionAll,
                        },
                        new AdaptiveChoice()
                        {
                            Value = Resources.Strings.ChannelHistoryOptionConversation,
                            Title = Resources.Strings.ChannelHistoryOptionConversation,
                        },
                    },
                    Value = Resources.Strings.ChannelHistoryOptionAll,
                };
                scopeContainer.Items.Add(choiceSet);
            }

            adaptiveCard.Body.Add(scopeContainer);

            // Timer range choice set
            var timeRangeContainer = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };

            timeRangeContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtTimeRangeReportMessage)
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Default,
                Wrap   = true,
            });
            var timeSet = new AdaptiveChoiceSetInput()
            {
                Id      = TimeRangeInputId,
                Style   = AdaptiveChoiceInputStyle.Expanded,
                Choices = new List <AdaptiveChoice>()
                {
                    new AdaptiveChoice()
                    {
                        Value = Resources.Strings.TimePeriodOptionAllTime,
                        Title = Resources.Strings.TimePeriodOptionAllTime,
                    },
                    new AdaptiveChoice()
                    {
                        Value = Resources.Strings.TimePeriodOptionLast7Days,
                        Title = Resources.Strings.TimePeriodOptionLast7Days,
                    },
                    new AdaptiveChoice()
                    {
                        Value = Resources.Strings.TimePeriodOptionLastDay,
                        Title = Resources.Strings.TimePeriodOptionLastDay,
                    },
                },
                Value = Resources.Strings.TimePeriodOptionAllTime,
            };

            timeRangeContainer.Items.Add(timeSet);
            adaptiveCard.Body.Add(timeRangeContainer);

            // File format choice set
            var fileFormatContainer = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };

            fileFormatContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtFileTypeReportMessage)
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Default,
                Wrap   = true,
            });
            var reportFormatChoices = reportFormats.Select(x => new AdaptiveChoice()
            {
                Value = ReportFileFormatConverter.GetReportFormat(x),
                Title = ReportFileFormatConverter.GetReportFormat(x),
            }).ToList();
            var formatSet = new AdaptiveChoiceSetInput()
            {
                Id      = ReportTypeInputId,
                Style   = AdaptiveChoiceInputStyle.Expanded,
                Choices = reportFormatChoices,
                Value   = reportFormatChoices.First().Value,
            };

            fileFormatContainer.Items.Add(formatSet);
            adaptiveCard.Body.Add(fileFormatContainer);

            adaptiveCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title = Resources.Strings.SignOutButtonText,
                Data  = new Dictionary <string, string> {
                    ["action"] = SignOutAction
                },
            });
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title = Resources.Strings.MessageExtExtractButton,
                Id    = GenerateBtnId,
                Data  = new Dictionary <string, string> {
                    ["action"] = GenerateReportAction
                },
            });


            return(adaptiveCard.ToAttachment());
        }
Esempio n. 5
0
        public override AdaptiveCard GetCreateNewCard(List <Group> groups, List <Team> teams, bool isEditCard)
        {
            // Update this code to add groups & teams.
            var employeGroups = new List <AdaptiveChoice>();

            foreach (var group in groups)
            {
                employeGroups.Add(new AdaptiveChoice()
                {
                    Title = group.Name, Value = group.Id
                });
            }

            var channels = new List <AdaptiveChoice>();

            foreach (var team in teams)
            {
                foreach (var channel in team.Channels)
                {
                    channels.Add(new AdaptiveChoice()
                    {
                        Title = $"{team.Name} > {channel.Name}", Value = $"{team.Id};{channel.Id}"
                    });
                }
            }

            string groupRecipients = null;

            if (Recipients.Groups != null && Recipients.Groups.Count != 0)
            {
                groupRecipients = string.Join(",", Recipients.Groups.Select(g => g.GroupId));
            }

            string channelRecipients = null;

            if (Recipients.Channels != null & Recipients.Channels.Count != 0)
            {
                channelRecipients = string.Join(",", Recipients.Channels.Select(g => g.TeamId + ";" + g.Channel.Id));
            }


            AdaptiveElement channelsAdaptiveCardInput;

            if (channels.Count > 0)
            {
                channelsAdaptiveCardInput = new AdaptiveChoiceSetInput()
                {
                    Id            = "channels",
                    Spacing       = AdaptiveSpacing.None,
                    Value         = isEditCard ? channelRecipients : "",
                    Choices       = new List <AdaptiveChoice>(channels),
                    IsMultiSelect = true,
                    Style         = AdaptiveChoiceInputStyle.Compact
                }
            }
            ;
            else
            {
                channelsAdaptiveCardInput = new AdaptiveTextBlock()
                {
                    Text = "No channels configured!",
                    Wrap = true,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                }
            };

            AdaptiveElement groupsAdaptiveCardInput;

            if (groups.Count > 0)
            {
                groupsAdaptiveCardInput = new AdaptiveChoiceSetInput()
                {
                    Id      = "groups",
                    Spacing = AdaptiveSpacing.None,

                    Choices       = new List <AdaptiveChoice>(employeGroups),
                    IsMultiSelect = true,
                    Style         = AdaptiveChoiceInputStyle.Compact,
                    Value         = isEditCard ? groupRecipients : ""
                }
            }
            ;
            else
            {
                groupsAdaptiveCardInput = new AdaptiveTextBlock()
                {
                    Text = "No groups configured!",
                    Wrap = true,
                    HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                }
            };

            var messageTypeChoices = new List <AdaptiveChoice>();

            messageTypeChoices.Add(new AdaptiveChoice()
            {
                Title = "❕ Important", Value = "Important"
            });
            messageTypeChoices.Add(new AdaptiveChoice()
            {
                Title = "❗ Emergency", Value = "Emergency"
            });
            messageTypeChoices.Add(new AdaptiveChoice()
            {
                Title = "📄 Information", Value = "Information"
            });
            var newCampaignCard = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
            {
                Body = new List <AdaptiveElement>()
                {
                    new AdaptiveContainer()
                    {
                        Items = new List <AdaptiveElement>()
                        {
                            new AdaptiveImage()
                            {
                                Url = new System.Uri(ApplicationSettings.BaseUrl + "/Resources/CreateMessageHeader.png")
                            },
                            new AdaptiveTextBlock()
                            {
                                Text     = $"This {ApplicationSettings.AppFeature} will be sent from the {ApplicationSettings.AppName} app handle. Fields marked with (*) are mandatory while composing.",
                                Size     = AdaptiveTextSize.Small,
                                Color    = AdaptiveTextColor.Accent,
                                Spacing  = AdaptiveSpacing.Small,
                                Weight   = AdaptiveTextWeight.Bolder,
                                IsSubtle = true,
                                Wrap     = true,
                            },
                            new AdaptiveTextBlock()
                            {
                                Separator = true,

                                Spacing = AdaptiveSpacing.Large,
                                Size    = AdaptiveTextSize.Large,
                                Color   = AdaptiveTextColor.Accent,
                                Text    = "Choose Audience"
                            },
                            new AdaptiveColumnSet()
                            {
                                Columns = new List <AdaptiveColumn>()
                                {
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            new AdaptiveTextBlock()
                                            {
                                                Text = "Choose group(s) of people",
                                                Wrap = true,
                                                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                            }
                                        },
                                        Width = "50",
                                    },
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            groupsAdaptiveCardInput
                                        },
                                        Width = "50"
                                    }
                                }
                            },
                            new AdaptiveColumnSet()
                            {
                                Columns = new List <AdaptiveColumn>()
                                {
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            new AdaptiveTextBlock()
                                            {
                                                Text = "Choose channel(s) in Teams",
                                                Wrap = true,
                                                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                            }
                                        },
                                        Width = "50",
                                    },
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            channelsAdaptiveCardInput
                                        },
                                        Width = "50"
                                    }
                                }
                            },
                            new AdaptiveContainer()
                            {
                                Spacing   = AdaptiveSpacing.Large,
                                Separator = true,
                                Items     = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Size  = AdaptiveTextSize.Large,
                                        Color = AdaptiveTextColor.Accent,
                                        Text  = "Compose Message"
                                    },
                                    new AdaptiveColumnSet()
                                    {
                                        Columns = new List <AdaptiveColumn>()
                                        {
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextBlock()
                                                    {
                                                        Text = "Title*",
                                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                    }
                                                },
                                                Width = "20"
                                            },
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextInput()
                                                    {
                                                        Id          = "title",
                                                        Placeholder = "eg: Giving Campaign 2018 is here",
                                                        Value       = isEditCard? Title: ""
                                                    }
                                                },
                                                Width = "85"
                                            }
                                        }
                                    },
                                    new AdaptiveColumnSet()
                                    {
                                        Columns = new List <AdaptiveColumn>()
                                        {
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextBlock()
                                                    {
                                                        Text = "Sub-Title",
                                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                    }
                                                },
                                                Width = "20"
                                            },
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextInput()
                                                    {
                                                        Id          = "subTitle",
                                                        Placeholder = "eg: Have you contributed to the mission?",
                                                        Value       = isEditCard? SubTitle: ""
                                                    }
                                                },
                                                Width = "85"
                                            }
                                        }
                                    },
                                    new AdaptiveColumnSet()
                                    {
                                        Columns = new List <AdaptiveColumn>()
                                        {
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextBlock()
                                                    {
                                                        Text = "Image*",
                                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                    }
                                                },
                                                Width = "20"
                                            },
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextInput()
                                                    {
                                                        Id          = "image",
                                                        Placeholder = "eg: https:// URL to image of exact size 530px X 95px",
                                                        Value       = isEditCard? ImageUrl: ""
                                                    }
                                                },
                                                Width = "85"
                                            }
                                        }
                                    },
                                    new AdaptiveColumnSet()
                                    {
                                        Columns = new List <AdaptiveColumn>()
                                        {
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextBlock()
                                                    {
                                                        Text = "Author alias*",
                                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                    }
                                                },
                                                Width = "20"
                                            },
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextInput()
                                                    {
                                                        Id          = "authorAlias",
                                                        Placeholder = "eg: [email protected]",
                                                        Value       = isEditCard? Author?.EmailId: ""
                                                    }
                                                },
                                                Width = "85"
                                            }
                                        }
                                    },
                                    new AdaptiveColumnSet()
                                    {
                                        Columns = new List <AdaptiveColumn>()
                                        {
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextBlock()
                                                    {
                                                        Text = "Preview*",
                                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                    }
                                                },
                                                Width = "20"
                                            },
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextInput()
                                                    {
                                                        Id          = "preview",
                                                        Placeholder = "eg: The 2018 Employee Giving Campaign is officially underway! Our incredibly generous culture of employee giving is unique to Contoso, and has a long history going back to our founder and his family’s core belief and value in philanthropy. Individually and collectively, we can have an incredible impact no matter how we choose to give. We are all very fortunate and 2018 has been a good year for the company which we are all participating in. Having us live in a community with a strong social safety net benefits us all so lets reflect our participation in this year's success with participation in Give.",
                                                        IsMultiline = true,
                                                        Value       = isEditCard? Preview: ""
                                                    }
                                                },
                                                Width = "85"
                                            }
                                        }
                                    },
                                    new AdaptiveColumnSet()
                                    {
                                        Columns = new List <AdaptiveColumn>()
                                        {
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextBlock()
                                                    {
                                                        Text = "Body*",
                                                        HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                    }
                                                },
                                                Width = "20"
                                            },
                                            new AdaptiveColumn()
                                            {
                                                Items = new List <AdaptiveElement>()
                                                {
                                                    new AdaptiveTextInput()
                                                    {
                                                        Id          = "body",
                                                        Placeholder = "eg: I hope you will take advantage of some of the fun and impactful opportunities that our giving team has put together and I’d like to thank our VPALs John Doe and Jason Natie for all the hard work they've put into planning these events for our team. To find out more about these opportunities, look for details in Give 2018 > General channel.",
                                                        IsMultiline = true,
                                                        Value       = isEditCard? Body: ""
                                                    }
                                                },
                                                Width = "85"
                                            }
                                        }
                                    },
                                }
                            }
                        }
                    },
                    new AdaptiveContainer()
                    {
                        Spacing   = AdaptiveSpacing.Large,
                        Separator = true,
                        Items     = new List <AdaptiveElement>()
                        {
                            new AdaptiveTextBlock()
                            {
                                Size  = AdaptiveTextSize.Large,
                                Color = AdaptiveTextColor.Accent,
                                Text  = "Choose Message Properties"
                            },
                        },
                    },
                    new AdaptiveContainer()
                    {
                        Spacing = AdaptiveSpacing.Medium,
                        Items   = new List <AdaptiveElement>()
                        {
                            new AdaptiveColumnSet()
                            {
                                Columns = new List <AdaptiveColumn>()
                                {
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            new AdaptiveToggleInput()
                                            {
                                                Id    = "acknowledge",
                                                Title = "Request acknowledgement",
                                                Value = isEditCard? IsAcknowledgementRequested.ToString(): "false",
                                            }
                                        }
                                    },
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            new AdaptiveToggleInput()
                                            {
                                                Id    = "allowContactIns",
                                                Title = "Allow recipient to contact",
                                                Value = isEditCard? IsContactAllowed.ToString(): "false",
                                            }
                                        },
                                        Width = "stretch"
                                    }
                                }
                            },
                            new AdaptiveColumnSet()
                            {
                                Columns = new List <AdaptiveColumn>()
                                {
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            new AdaptiveTextBlock()
                                            {
                                                HorizontalAlignment = AdaptiveHorizontalAlignment.Left,
                                                Text = "Choose Message Sensitivity",
                                            }
                                        },
                                        Width = "50"
                                    },
                                    new AdaptiveColumn()
                                    {
                                        Items = new List <AdaptiveElement>()
                                        {
                                            new AdaptiveChoiceSetInput()
                                            {
                                                Id            = "messageType",
                                                Spacing       = AdaptiveSpacing.None,
                                                Value         = isEditCard?  Sensitivity.ToString() : "Important",
                                                Choices       = new List <AdaptiveChoice>(messageTypeChoices),
                                                IsMultiSelect = false,
                                                Style         = AdaptiveChoiceInputStyle.Compact,
                                            },
                                        },
                                        Width = "50"
                                    }
                                }
                            }
                        }
                    }
                },
                Actions = new List <AdaptiveAction>()
                {
                    new AdaptiveSubmitAction()
                    {
                        Title = "✔️ Preview",
                        Data  = isEditCard?
                                new AnnouncementActionDetails()
                        {
                            ActionType = Constants.CreateOrEditAnnouncement, Id = Id
                        }
                        :new ActionDetails()
                        {
                            ActionType = Constants.CreateOrEditAnnouncement
                        }
                    },
                    new AdaptiveSubmitAction()
                    {
                        Title = "❌ Cancel",
                        Data  = new ActionDetails()
                        {
                            ActionType = Constants.Cancel
                        }
                    }
                }
            };

            return(newCampaignCard);
        }
Esempio n. 6
0
 private void SetValue(AdaptiveChoiceSetInput choiceSet, object value)
 {
     choiceSet.Value = Convert.ToString(value);
 }
Esempio n. 7
0
        public async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument)
        {
            AdaptiveCard card = new AdaptiveCard();

            card.Body.Add(new AdaptiveTextBlock()
            {
                Text   = "Adaptive Card rendering test",
                Size   = AdaptiveTextSize.Large,
                Weight = AdaptiveTextWeight.Bolder
            });

            var choiceSet = new AdaptiveChoiceSetInput();

            choiceSet.Choices.Add(
                new AdaptiveChoice()
            {
                Title = "Zuko",
                Value = "zuko"
            });
            choiceSet.Choices.Add(new AdaptiveChoice()
            {
                Title = "Buko",
                Value = "buko"
            });
            card.Body.Add(choiceSet);

            Attachment attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card
            };

            var replyToConversation = context.MakeMessage();

            replyToConversation.Attachments.Add(attachment);

            //return our reply to the user
            await context.PostAsync(replyToConversation);

            string json = @"{
    ""$schema"": ""http://adaptivecards.io/schemas/adaptive-card.json"",
    ""type"": ""AdaptiveCard"",
    ""version"": ""1.0"",
    ""body"": [
        {
            ""type"": ""TextBlock"",
            ""text"": ""title"",
            ""weight"": ""bolder"",
            ""size"": ""large""
        },
        {
            ""type"": ""TextBlock"",
            ""text"": ""shortText"",
            ""wrap"": ""true""
        },
        {
            ""type"": ""TextBlock"",
            ""text"": ""Date: date"",
            ""separator"": ""true"",
            ""weight"": ""bolder""
        }
    ],
    ""actions"": [
        {
            ""type"": ""Action.OpenUrl"",
            ""title"": ""More information"",
            ""url"": ""Url""
        },
        {
            ""type"": ""Action.Submit"",
            ""title"": ""Subscribe"",
            ""data"": ""subscribesentence""
        }
    ]
}";
            AdaptiveCardParseResult result = AdaptiveCard.FromJson(json);

            AdaptiveCard card2       = result.Card;
            Attachment   attachment2 = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = card2
            };

            var replyToConversation2 = context.MakeMessage();

            replyToConversation2.Attachments.Add(attachment2);
            await context.PostAsync(replyToConversation2);

            context.Wait(MessageReceivedAsync);
        }
        /// <summary>
        /// Return the appropriate status choices based on the state and information in the ticket.
        /// </summary>
        /// <returns>An adaptive element which contains the dropdown choices.</returns>
        private AdaptiveChoiceSetInput GetAdaptiveChoiceSetInput()
        {
            AdaptiveChoiceSetInput choiceSet = new AdaptiveChoiceSetInput
            {
                Id            = nameof(ChangeTicketStatusPayload.Action),
                IsMultiSelect = false,
                Style         = AdaptiveChoiceInputStyle.Compact
            };

            if (this.Ticket.Status == (int)TicketState.Open)
            {
                if (!this.Ticket.IsAssigned())
                {
                    choiceSet.Value   = ChangeTicketStatusPayload.AssignToSelfAction;
                    choiceSet.Choices = new List <AdaptiveChoice>
                    {
                        new AdaptiveChoice
                        {
                            Title = Resource.AssignToMeActionChoiceTitle,
                            Value = ChangeTicketStatusPayload.AssignToSelfAction,
                        },
                        new AdaptiveChoice
                        {
                            Title = Resource.CloseActionChoiceTitle,
                            Value = ChangeTicketStatusPayload.CloseAction,
                        },
                    };
                }
                else
                {
                    choiceSet.Value   = ChangeTicketStatusPayload.CloseAction;
                    choiceSet.Choices = new List <AdaptiveChoice>
                    {
                        new AdaptiveChoice
                        {
                            Title = Resource.UnassignActionChoiceTitle,
                            Value = ChangeTicketStatusPayload.ReopenAction,
                        },
                        new AdaptiveChoice
                        {
                            Title = Resource.AssignToMeActionChoiceTitle,
                            Value = ChangeTicketStatusPayload.AssignToSelfAction,
                        },
                        new AdaptiveChoice
                        {
                            Title = Resource.CloseActionChoiceTitle,
                            Value = ChangeTicketStatusPayload.CloseAction,
                        },
                    };
                }
            }
            else if (this.Ticket.Status == (int)TicketState.Closed)
            {
                choiceSet.Value   = ChangeTicketStatusPayload.ReopenAction;
                choiceSet.Choices = new List <AdaptiveChoice>
                {
                    new AdaptiveChoice
                    {
                        Title = Resource.ReopenActionChoiceTitle,
                        Value = ChangeTicketStatusPayload.ReopenAction,
                    },
                    new AdaptiveChoice
                    {
                        Title = Resource.ReopenAssignToMeActionChoiceTitle,
                        Value = ChangeTicketStatusPayload.AssignToSelfAction,
                    },
                };
            }

            return(choiceSet);
        }
Esempio n. 9
0
        public static View Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            object list;
            string str = input.Value;

            if (str != null)
            {
                list = (
                    from p in str.Split(new char[] { ',' })
                    select p.Trim() into s
                    where !string.IsNullOrEmpty(s)
                    select s).ToList <string>();
            }
            else
            {
                list = null;
            }
            if (list == null)
            {
                list = new List <string>();
            }
            List <string> strs        = (List <string>)list;
            StackLayout   stackLayout = new StackLayout();

            stackLayout.Orientation = StackOrientation.Vertical;
            foreach (AdaptiveChoice choice in input.Choices)
            {
                if (input.IsMultiSelect)
                {
                    var checkBox = new CheckBox()
                    {
                        Text           = choice.Title,
                        IsChecked      = strs.Contains(choice.Value),
                        BindingContext = choice,
                        Style          = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox")
                    };
                    stackLayout.Children.Add(checkBox);


                    checkBox.CheckUnCheckAction = new Action <CheckBox>((c) =>
                    {
                        if (CheckBoxUpdating)
                        {
                            return;
                        }
                        CheckBoxUpdating = true;

                        if (c.Text == "All")
                        {
                            stackLayout.Children.ForEach((i) => (i as CheckBox).IsChecked = c.IsChecked);
                        }
                        else if (c.IsChecked)
                        {
                            CheckBox allCheckBox = null;
                            var isChecked        = true;
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    allCheckBox = box;
                                }
                                else if (!box.IsChecked)
                                {
                                    isChecked = false;
                                    break;
                                }
                            }
                            if (allCheckBox != null && isChecked)
                            {
                                allCheckBox.IsChecked = true;
                            }
                        }
                        else
                        {
                            foreach (var i in stackLayout.Children)
                            {
                                var box = i as CheckBox;
                                if (box.Text == "All")
                                {
                                    box.IsChecked = false;
                                    break;
                                }
                            }
                        }
                        CheckBoxUpdating = false;
                    });
                }
            }

            context.HideIcon = true;
            context.InputBindings.Add(input.Id, new Func <string>(() =>
            {
                if (input.IsMultiSelect)
                {
                    string value = string.Empty;
                    foreach (var item in stackLayout.Children)
                    {
                        AdaptiveChoice dataContext = item.BindingContext as AdaptiveChoice;
                        var isChecked = (item as CheckBox).IsChecked;
                        if (!isChecked)//(isChecked.GetValueOrDefault() ? !isChecked.HasValue : true))
                        {
                            continue;
                        }
                        value = string.Concat(value, (value == string.Empty ? "" : ";"), dataContext.Value);
                    }
                    return(value);
                }
                return(string.Empty);
            }));

            return(stackLayout);
        }
        public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            if (context.Config.SupportsInteractivity)
            {
                var uiGrid = new Grid();
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = GridLength.Auto
                });
                uiGrid.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(1, GridUnitType.Star)
                });

                var uiComboBox = new ComboBox();
                uiComboBox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox");
                uiComboBox.DataContext = input;

                var uiChoices = new ListBox();
                ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled);
                var itemsPanelTemplate = new ItemsPanelTemplate();
                var factory            = new FrameworkElementFactory(typeof(WrapPanel));
                itemsPanelTemplate.VisualTree = factory;
                uiChoices.ItemsPanel          = itemsPanelTemplate;
                uiChoices.DataContext         = input;
                uiChoices.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput");

                foreach (var choice in input.Choices)
                {
                    if (input.IsMultiSelect == true)
                    {
                        var uiCheckbox = new CheckBox();
                        uiCheckbox.Content     = choice.Title;
                        uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                        uiCheckbox.DataContext = choice;
                        uiCheckbox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox");
                        uiChoices.Items.Add(uiCheckbox);
                    }
                    else
                    {
                        if (input.Style == AdaptiveChoiceInputStyle.Compact)
                        {
                            var uiComboItem = new ComboBoxItem();
                            uiComboItem.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem");
                            uiComboItem.Content     = choice.Title;
                            uiComboItem.DataContext = choice;
                            uiComboBox.Items.Add(uiComboItem);
                            if (chosen.Contains(choice.Value))
                            {
                                uiComboBox.SelectedItem = uiComboItem;
                            }
                        }
                        else
                        {
                            var uiRadio = new RadioButton();
                            uiRadio.Content     = choice.Title;
                            uiRadio.IsChecked   = chosen.Contains(choice.Value);
                            uiRadio.GroupName   = input.Id;
                            uiRadio.DataContext = choice;
                            uiRadio.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio");
                            uiChoices.Items.Add(uiRadio);
                        }
                    }
                }
                context.InputBindings.Add(input.Id, () =>
                {
                    if (input.IsMultiSelect == true)
                    {
                        string values = string.Empty;
                        foreach (var item in uiChoices.Items)
                        {
                            CheckBox checkBox             = (CheckBox)item;
                            AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice;
                            if (checkBox.IsChecked == true)
                            {
                                values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value;
                            }
                        }
                        return(values);
                    }
                    else
                    {
                        if (input.Style == AdaptiveChoiceInputStyle.Compact)
                        {
                            ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                            if (item != null)
                            {
                                AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice;
                                return(adaptiveChoice.Value);
                            }
                            return(null);
                        }
                        else
                        {
                            foreach (var item in uiChoices.Items)
                            {
                                RadioButton radioBox          = (RadioButton)item;
                                AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice;
                                if (radioBox.IsChecked == true)
                                {
                                    return(adaptiveChoice.Value);
                                }
                            }
                            return(null);
                        }
                    }
                });
                if (input.Style == AdaptiveChoiceInputStyle.Compact)
                {
                    Grid.SetRow(uiComboBox, 1);
                    uiGrid.Children.Add(uiComboBox);
                    return(uiGrid);
                }
                else
                {
                    Grid.SetRow(uiChoices, 1);
                    uiGrid.Children.Add(uiChoices);
                    return(uiGrid);
                }
            }

            string choiceText = XamlUtilities.GetFallbackText(input);

            if (choiceText == null)
            {
                List <string> choices = input.Choices.Select(choice => choice.Title).ToList();
                if (input.Style == AdaptiveChoiceInputStyle.Compact)
                {
                    if (input.IsMultiSelect)
                    {
                        choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " and ")}";
                    }
                    else
                    {
                        choiceText = $"Choices: {RendererUtilities.JoinString(choices, ", ", " or ")}";
                    }
                }
                else // if (adaptiveChoiceSetInput.Style == ChoiceInputStyle.Expanded)
                {
                    choiceText = $"* {RendererUtilities.JoinString(choices, "\n* ", "\n* ")}";
                }
            }
            AdaptiveContainer container = AdaptiveTypedElementConverter.CreateElement <AdaptiveContainer>();

            container.Spacing   = input.Spacing;
            container.Separator = input.Separator;
            AdaptiveTextBlock textBlock = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();

            textBlock.Text = choiceText;
            textBlock.Wrap = true;
            container.Items.Add(textBlock);

            textBlock       = AdaptiveTypedElementConverter.CreateElement <AdaptiveTextBlock>();
            textBlock.Text  = RendererUtilities.JoinString(input.Choices.Where(c => chosen.Contains(c.Value)).Select(c => c.Title).ToList(), ", ", " and ");
            textBlock.Color = AdaptiveTextColor.Accent;
            textBlock.Wrap  = true;
            container.Items.Add(textBlock);
            return(context.Render(container));
        }
Esempio n. 11
0
        public static async Task GetProductInfo(CRMWebAPI api, ITurnContext <IMessageActivity> context, string product)
        {
            var isTeams = context.Activity.ChannelId.ToLowerInvariant() == "msteams";
            var isSkype = context.Activity.ChannelId.ToLowerInvariant() == "skypeforbusiness";
            await Task.Run(async() =>
            {
                var card      = new HeroCard();
                var adaptCard = new AdaptiveCard(new AdaptiveSchemaVersion());
                var factSet   = new AdaptiveChoiceSetInput()
                {
                    Choices = new List <AdaptiveChoice>(), Spacing = AdaptiveSpacing.Medium
                };
                //card.Body.Add(factSet);

                var names        = new List <string>();
                string fetchXml  = @"<fetch mapping='logical'>
                                        <entity name='product'> 
                                          <attribute name='productid'/> 
                                          <attribute name='name'/> 
                                        <filter type='and'> 
                                            <condition attribute='name' operator='eq' value='{0}' /> 
                                        </filter> 
                                       </entity> 
                                </fetch>";
                fetchXml         = string.Format(fetchXml, product);
                var fetchResults = await api.GetList("products", QueryOptions: new CRMGetListOptions()
                {
                    FetchXml = fetchXml
                });

                foreach (var item in fetchResults.List)
                {
                    IDictionary <string, object> propertyValues = item;

                    foreach (var property in propertyValues.Keys)
                    {
                        string text = $"*{property}* : {propertyValues[property].ToString()}";
                        if (isTeams || isSkype)
                        {
                            card.Buttons.Add(new CardAction()
                            {
                                Text = text, Value = text, Type = ActionTypes.MessageBack
                            });
                        }
                        else
                        {
                            adaptCard.Body.Add(new AdaptiveTextBlock()
                            {
                                Text = text
                            });
                        }
                    }
                }
                if (isTeams || isSkype)
                {
                    await DisplayMessage(card, context);
                }
                else
                {
                    await DisplayMessage(adaptCard, context);
                }
            });
        }
Esempio n. 12
0
        private void AddInputColumn(string title)
        {
            //Create a column
            var col = new AdaptiveColumn();

            col.Items.Add(new AdaptiveTextBlock
            {
                Text = title,
                Size = TextSize.Large,
            });

            col.Items.Add(new AdaptiveDateInput
            {
                Id          = "Date",
                Placeholder = "Enter a date"
            });

            col.Items.Add(new AdaptiveNumberInput
            {
                Id          = "Number",
                Placeholder = "Enter a number",
            });

            col.Items.Add(new AdaptiveTextInput
            {
                Id          = "Text",
                Placeholder = "Enter some text"
            });

            col.Items.Add(new AdaptiveTimeInput
            {
                Id          = "Time",
                Placeholder = "Enter a time",
            });

            col.Items.Add(new AdaptiveToggleInput
            {
                Id       = "Toggle",
                Title    = "toggle on or off",
                ValueOn  = "On",
                ValueOff = "Off"
            });
            // Create a collection for the choice input set.
            var choiceSet = new AdaptiveChoiceSetInput
            {
                Id            = "ChoiceSet",
                IsMultiSelect = true,
            };

            // Create the individual choices.
            choiceSet.Choices.Add(new AdaptiveChoiceInput
            {
                Title = "Choice 1",
                Value = "10"
            });
            choiceSet.Choices.Add(new AdaptiveChoiceInput
            {
                Title = "Choice 2",
                Value = "20"
            });
            choiceSet.Choices.Add(new AdaptiveChoiceInput
            {
                Title = "Choice 3",
                Value = "30"
            });

            // Add the choice set to the column.
            col.Items.Add(choiceSet);

            // Add the column to the column set.
            _mainColumnSet.Columns.Add(col);
        }
Esempio n. 13
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            //var adaptiveCardAttachment = CardsDemoWithTypes();
            //await turnContext.SendActivityAsync(MessageFactory.Attachment(adaptiveCardAttachment));

            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                // Check if user submitted AdaptiveCard input
                if (turnContext.Activity.Value != null)
                {
                    //var activityValue = turnContext.Activity.AsMessageActivity().Value as Newtonsoft.Json.Linq.JObject;
                    //if (activityValue != null)
                    //{
                    //    var categorySelection = activityValue.ToObject<CategorySelection>();
                    //    var category = categorySelection.Category;
                    //    await turnContext.SendActivityAsync(category);
                    //}

                    // Convert String to JObject
                    String  value   = turnContext.Activity.Value.ToString();
                    JObject results = JObject.Parse(value);

                    // Get type from input field
                    String submitType = results.GetValue("Type").ToString().Trim();
                    switch (submitType)
                    {
                    case "email":
                        IMessageActivity message = Activity.CreateMessageActivity();
                        message.Type       = ActivityTypes.Message;
                        message.Text       = "email \n <br> sent";
                        message.Locale     = "en-Us";
                        message.TextFormat = TextFormatTypes.Plain;
                        await turnContext.SendActivityAsync(message, cancellationToken);

                        /* */
                        return;

                    default:
                        await turnContext.SendActivityAsync("No Action Logic Written for this button", cancellationToken : cancellationToken);

                        break;
                    }

                    String name = results.GetValue("Type").ToString().Trim();
                    //String actionText = results.GetValue("ActionText").ToString();
                    //await turnContext.SendActivityAsync("Respond to user " + actionText, cancellationToken: cancellationToken);

                    // Get Keywords from input field
                    String userInputKeywords = "";
                    //                    if (name == "GetPPT") {
                    if (name == "ViewProfile")
                    {
                        //String DisplayVal = results.GetValue("DisplayText").ToString();
                        //await turnContext.SendActivityAsync(MessageFactory.Text(DisplayVal), cancellationToken);

                        userInputKeywords = "View Profile";

                        AdaptiveCard ViewcardAttachment = null;
                        ViewcardAttachment = AdaptiveCardBotHelper.ViewProfile();

                        var attachment = new Attachment
                        {
                            ContentType = AdaptiveCard.ContentType,
                            Content     = ViewcardAttachment
                        };

                        if (attachment != null)
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Attachment(attachment), cancellationToken);

                            //await turnContext.SendActivityAsync(MessageFactory.Text("Please enter any text to see another card."), cancellationToken);
                        }
                    }
                    else if (name == "UpdateProfile")
                    {
                        userInputKeywords = "Update Profile";

                        AdaptiveCard UpdatecardAttachment = null;
                        UpdatecardAttachment = AdaptiveCardBotHelper.UpdateProfile();

                        var attachment = new Attachment
                        {
                            ContentType = AdaptiveCard.ContentType,
                            Content     = UpdatecardAttachment
                        };

                        if (attachment != null)
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Attachment(attachment), cancellationToken);

                            //await turnContext.SendActivityAsync(MessageFactory.Text("Please enter any text to see another card."), cancellationToken);
                        }

                        //userInputKeywords = results.GetValue("GetUserInputKeywords").ToString();
                    }
                    else if (name == "SendIssue")
                    {
                        AdaptiveCard IssuecardAttachment = null;
                        IssuecardAttachment = AdaptiveCardBotHelper.ReportIssue();

                        var attachment = new Attachment
                        {
                            ContentType = AdaptiveCard.ContentType,
                            Content     = IssuecardAttachment
                        };

                        if (attachment != null)
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Attachment(attachment), cancellationToken);

                            //await turnContext.SendActivityAsync(MessageFactory.Text("Please enter any text to see another card."), cancellationToken);
                        }

                        userInputKeywords = "Report Issue";
                    }
                    else if (name == "Update")
                    {
                        userInputKeywords = "Update Info";
                        userInputKeywords = results.GetValue("GetUserInputKeywords").ToString();
                    }
                    //

                    // Make Http request to api with paramaters
                    //String myUrl = $"http://myurl.com/api/{userInputKeywords}";

                    //...

                    // Respond to user
                    await turnContext.SendActivityAsync("Respond to user" + userInputKeywords, cancellationToken : cancellationToken);
                }
                else
                {
                    //Conversation Text:- hi, "*****@*****.**", "i want to raise an issue", "hardware", "software"
                    turnContext.Activity.RemoveRecipientMention();
                    var text = turnContext.Activity.Text.Trim().ToLower();
                    Body.Text    = text;
                    apiHelperObj = new BotAPIHelper();
                    CreateResponseBody responseBody = apiHelperObj.CreateApiPostCall(Body);
                    if (responseBody != null)
                    {
                        if (responseBody.OutputStack != null && responseBody.OutputStack.Count() > 0)
                        {
                            foreach (var OutputStack in responseBody.OutputStack)
                            {
                                if (!string.IsNullOrEmpty(OutputStack.Text))
                                {
                                    await turnContext.SendActivityAsync(MessageFactory.Text(OutputStack.Text), cancellationToken);

                                    //IMessageActivity message = Activity.CreateMessageActivity();
                                    //message.Type = ActivityTypes.Message;
                                    //message.Text = "your \n <br> text";
                                    //message.Locale = "en-Us";
                                    //message.TextFormat = TextFormatTypes.Plain;
                                    //await turnContext.SendActivityAsync(message);
                                }
                                else
                                {
                                    var mainCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
                                    if (OutputStack.Data.type == "buttons")
                                    {
                                        //===========================Add DropDownList
                                        //AdaptiveChoiceSetInput choiceSet = AdaptiveCardBotHelper.AddDropDownList();
                                        AdaptiveChoiceSetInput choiceSet = AdaptiveCardHelper.AddDropDownToAdaptiveCard(OutputStack);
                                        mainCard.Body.Add(choiceSet);

                                        //=========================== Add Button
                                        var adaptiveButtonList = AdaptiveCardHelper.AddButtonsToAdaptiveCard(OutputStack);
                                        if (adaptiveButtonList != null && adaptiveButtonList.Count() > 0)
                                        {
                                            mainCard.Body.Add(AdaptiveCardHelper.AddTextBlock(OutputStack.Data._cognigy._default._buttons.text));
                                            mainCard.Actions = adaptiveButtonList;
                                        }
                                        //var card = AdaptiveCardBotHelper.GetCard(OutputStack);
                                    }
                                    if (mainCard != null)
                                    {
                                        var cardAttachment = new Attachment()
                                        {
                                            ContentType = AdaptiveCard.ContentType,
                                            Content     = mainCard,
                                            Name        = "CardName"
                                        };
                                        await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment), cancellationToken);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public static async Task <AdaptiveCard> GetFileDetailCard(string accessToken, string fileId)
        {
            var client = GetAuthenticatedClient(accessToken);

            // Get the file with thumbnails
            var file = await client.Me.Drive.Items[fileId].Request()
                       .Expand("thumbnails")
                       .GetAsync();

            // Get people user interacts with regularly
            var potentialApprovers = await client.Me.People.Request()
                                     // Only want organizational users, and do not want to send back to bot
                                     .Filter("personType/subclass eq 'OrganizationUser' and displayName ne 'Approval Bot'")
                                     .Top(10)
                                     .GetAsync();

            var fileCard = new AdaptiveCard();

            fileCard.Body.Add(new AdaptiveTextBlock()
            {
                Text   = "Get approval for this file?",
                Size   = AdaptiveTextSize.Large,
                Weight = AdaptiveTextWeight.Bolder
            });

            fileCard.Body.Add(new AdaptiveTextBlock()
            {
                Text   = file.Name,
                Weight = AdaptiveTextWeight.Bolder
            });

            fileCard.Body.Add(new AdaptiveFactSet()
            {
                Facts = new List <AdaptiveFact>()
                {
                    new AdaptiveFact("Size", $"{file.Size / 1024} KB"),
                    new AdaptiveFact("Last modified", TimeZoneHelper.GetAdaptiveDateTimeString(file.LastModifiedDateTime.Value)),
                    new AdaptiveFact("Last modified by", file.LastModifiedBy.User.DisplayName)
                }
            });

            if (file.Thumbnails != null && file.Thumbnails.Count > 0)
            {
                fileCard.Body.Add(new AdaptiveImage()
                {
                    Size    = AdaptiveImageSize.Stretch,
                    AltText = "File thumbnail",
                    Url     = new Uri(file.Thumbnails[0].Large.Url)
                });
            }

            var recipientPromptCard = new AdaptiveCard();

            recipientPromptCard.Body.Add(new AdaptiveTextBlock()
            {
                Text   = "Who should I ask for approval?",
                Weight = AdaptiveTextWeight.Bolder
            });

            var recipientPicker = new AdaptiveChoiceSetInput()
            {
                Id            = "approvers",
                IsMultiSelect = true,
                Style         = AdaptiveChoiceInputStyle.Compact
            };

            foreach (var potentialApprover in potentialApprovers)
            {
                recipientPicker.Choices.Add(new AdaptiveChoice()
                {
                    Title = potentialApprover.DisplayName,
                    Value = potentialApprover.ScoredEmailAddresses.First().Address
                });
            }

            recipientPromptCard.Body.Add(recipientPicker);

            recipientPromptCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title    = "Send Request",
                DataJson = $@"{{ ""cardAction"": ""{CardActionTypes.SendApprovalRequest}"", ""selectedFile"": ""{fileId}"" }}"
            });

            fileCard.Actions.Add(new AdaptiveShowCardAction()
            {
                Title = "Yes",
                Card  = recipientPromptCard
            });

            fileCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title    = "No",
                DataJson = $@"{{ ""cardAction"": ""{CardActionTypes.WrongFile}"" }}"
            });

            return(fileCard);
        }
Esempio n. 15
0
        private AdaptiveCard SetCard()
        {
            AdaptiveCard _card = new AdaptiveCard("1.0");

            var _container = new AdaptiveContainer();

            var colum = new AdaptiveColumnSet();

            var _columnImage = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Auto
            };

            _columnImage.Items.Add(new AdaptiveImage()
            {
                Url     = new Uri(this.UrlImage),
                Size    = AdaptiveImageSize.Small,
                Style   = AdaptiveImageStyle.Person,
                AltText = "Bootty"
            });

            var _columnContent = new AdaptiveColumn()
            {
                Width = AdaptiveColumnWidth.Stretch
            };

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text    = "Booty",
                Size    = AdaptiveTextSize.Medium,
                Weight  = AdaptiveTextWeight.Default,
                Color   = AdaptiveTextColor.Default,
                Wrap    = true,
                Spacing = AdaptiveSpacing.Default
            });

            _columnContent.Items.Add(new AdaptiveTextBlock()
            {
                Text     = DateTime.Now.ToString(),
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Wrap     = true,
                IsSubtle = true,
                Spacing  = AdaptiveSpacing.None
            });

            var _textMessage = new AdaptiveTextBlock()
            {
                Text     = this.Title,
                Size     = AdaptiveTextSize.Medium,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Bolder,
                Wrap     = true,
                IsSubtle = false
            };

            var _textMessage2 = new AdaptiveTextBlock()
            {
                Text     = this.Description,
                Size     = AdaptiveTextSize.Small,
                Color    = AdaptiveTextColor.Default,
                Weight   = AdaptiveTextWeight.Default,
                Wrap     = true,
                IsSubtle = false
            };


            colum.Columns.Add(_columnImage);
            colum.Columns.Add(_columnContent);
            _container.Items.Add(colum);

            _card.Body.Add(_container);
            _card.Body.Add(_textMessage);
            _card.Body.Add(_textMessage2);

            //Form

            var _texDataSubtitle = new AdaptiveTextBlock()
            {
                Text   = "Tus Datos",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Bolder,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left
            };


            var _textTitleName = new AdaptiveTextBlock()
            {
                Text   = "Tú Nombre",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textName = new AdaptiveTextInput()
            {
                Id          = "UserName",
                Placeholder = "Apellido, Nombre"
            };

            var _textTitleEmail = new AdaptiveTextBlock()
            {
                Text   = "Dirección de correo",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textEmail = new AdaptiveTextInput()
            {
                Id          = "Email",
                Placeholder = "correo electronico"
            };

            var _texDatesSubtitle = new AdaptiveTextBlock()
            {
                Text   = "Fechas",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Bolder,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left
            };

            var _textTitleDeparture = new AdaptiveTextBlock()
            {
                Text   = "Fecha de salida",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textDeparture = new AdaptiveDateInput()
            {
                Id = "Departure"
            };

            var _textTitleArrival = new AdaptiveTextBlock()
            {
                Text   = "Fecha de regreso",
                Size   = AdaptiveTextSize.Small,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };

            var _textArrival = new AdaptiveDateInput()
            {
                Id = "Arrival"
            };

            var _texOptionsSubtitle = new AdaptiveTextBlock()
            {
                Text   = "Tipo de viaje",
                Size   = AdaptiveTextSize.Normal,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Bolder,
                HorizontalAlignment = AdaptiveHorizontalAlignment.Left
            };

            var _textTrasportOpciones = new AdaptiveTextBlock()
            {
                Text   = "Tipo de transporte",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };
            //traport
            var _transportChoice = new AdaptiveChoiceSetInput();

            _transportChoice.Id    = "TransporChoice";
            _transportChoice.Value = "bus";
            _transportChoice.Style = AdaptiveChoiceInputStyle.Expanded;
            _transportChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Omnibus",
                Value = "Omnibus"
            });
            _transportChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Avion",
                Value = "Avion"
            });

            var _textClassOpciones = new AdaptiveTextBlock()
            {
                Text   = "Clase",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };
            //traport
            var _classChoice = new AdaptiveChoiceSetInput();

            _classChoice.Id    = "ClassChoice";
            _classChoice.Value = "Economica";
            _classChoice.Style = AdaptiveChoiceInputStyle.Expanded;
            _classChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Economica",
                Value = "Economica"
            });
            _classChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Primera",
                Value = "Primera"
            });

            var _textCashOpciones = new AdaptiveTextBlock()
            {
                Text   = "¿Forma de Pago?",
                Size   = AdaptiveTextSize.Medium,
                Color  = AdaptiveTextColor.Default,
                Weight = AdaptiveTextWeight.Default
            };
            //traport
            var _cashChoice = new AdaptiveChoiceSetInput();

            _cashChoice.Id    = "CashChoice";
            _cashChoice.Value = "Efectivo";
            _cashChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Efectivo",
                Value = "Efectivo"
            });
            _cashChoice.Choices.Add(new AdaptiveChoice()
            {
                Title = "Tarjeta de Credito",
                Value = "Tarjeta de Credito"
            });

            var _checkConditions = new AdaptiveToggleInput()
            {
                Id    = "checkConditions",
                Value = "accept",
                Title = "Acepto los terminos y condiciones."
            };

            var _submitButton = new AdaptiveSubmitAction()
            {
                Title    = "Contratar",
                DataJson = JsonConvert.SerializeObject(new JsonDataAux()
                {
                    From   = TypeCards.FORM.ToString(),
                    Action = "MDZFORM"
                })
            };

            _card.Body.Add(_texDataSubtitle);
            _card.Body.Add(_textTitleName);
            _card.Body.Add(_textName);
            _card.Body.Add(_textTitleEmail);
            _card.Body.Add(_textEmail);
            _card.Body.Add(_texDatesSubtitle);
            _card.Body.Add(_textTitleDeparture);
            _card.Body.Add(_textDeparture);
            _card.Body.Add(_textTitleArrival);
            _card.Body.Add(_textArrival);

            _card.Body.Add(_texOptionsSubtitle);
            _card.Body.Add(_textTrasportOpciones);
            _card.Body.Add(_transportChoice);
            _card.Body.Add(_textClassOpciones);
            _card.Body.Add(_classChoice);
            _card.Body.Add(_textCashOpciones);
            _card.Body.Add(_cashChoice);

            _card.Body.Add(_checkConditions);

            _card.Actions.Add(_submitButton);

            return(_card);
        }
        /// <summary>
        /// Return the appropriate status choices based on the state and information in the ticket.
        /// </summary>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <returns>An adaptive element which contains the drop down choices.</returns>
        private AdaptiveChoiceSetInput GetAdaptiveChoiceSetInput(IStringLocalizer <Strings> localizer)
        {
            AdaptiveChoiceSetInput choiceSet = new AdaptiveChoiceSetInput
            {
                Id            = nameof(ChangeTicketStatus.Action),
                IsMultiSelect = false,
                Style         = AdaptiveChoiceInputStyle.Compact,
            };

            if (this.ticket.TicketStatus == (int)TicketState.Atanmamış)
            {
                choiceSet.Value   = ChangeTicketStatus.AssignToSelfAction;
                choiceSet.Choices = new List <AdaptiveChoice>
                {
                    new AdaptiveChoice
                    {
                        Title = localizer.GetString("AssignToMeActionChoiceTitle"),
                        Value = ChangeTicketStatus.AssignToSelfAction,
                    },
                    new AdaptiveChoice
                    {
                        Title = localizer.GetString("CloseActionChoiceTitle"),
                        Value = ChangeTicketStatus.CloseAction,
                    },
                };
            }
            else if (this.ticket.TicketStatus == (int)TicketState.Kapatılmış)
            {
                choiceSet.Value   = localizer.GetString("ReopenActionChoiceTitle");
                choiceSet.Choices = new List <AdaptiveChoice>
                {
                    new AdaptiveChoice
                    {
                        Title = localizer.GetString("ReopenActionChoiceTitle"),
                        Value = ChangeTicketStatus.ReopenAction,
                    },
                    new AdaptiveChoice
                    {
                        Title = localizer.GetString("ReopenAssignToMeActionChoiceTitle"),
                        Value = ChangeTicketStatus.AssignToSelfAction,
                    },
                };
            }
            else if (this.ticket.TicketStatus == (int)TicketState.Atanmış)
            {
                choiceSet.Value   = localizer.GetString("CloseActionChoiceTitle");
                choiceSet.Choices = new List <AdaptiveChoice>
                {
                    new AdaptiveChoice
                    {
                        Title = localizer.GetString("UnassignActionChoiceTitle"),
                        Value = ChangeTicketStatus.ReopenAction,
                    },
                    new AdaptiveChoice
                    {
                        Title = localizer.GetString("CloseActionChoiceTitle"),
                        Value = ChangeTicketStatus.CloseAction,
                    },
                };
            }

            return(choiceSet);
        }
Esempio n. 17
0
        /// <summary>
        /// Generate ToAdaptiveCardAttachment.
        /// </summary>
        /// <param name="todos">To Do activities.</param>
        /// <param name="allTaskCount">all tasks count.</param>
        /// <param name="botResponse1">the bot response 1.</param>
        /// <param name="botResponse2">the bot response 2.</param>
        /// <returns>Generated adaptive card attachment.</returns>
        public static Microsoft.Bot.Schema.Attachment ToAdaptiveCardAttachmentForShowToDos(
            List <ToDoTaskActivityModel> todos,
            int allTaskCount,
            BotResponse botResponse1,
            BotResponse botResponse2)
        {
            var toDoCard  = new AdaptiveCard();
            var speakText = Format(botResponse1.Reply.Speak, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });

            if (botResponse2 != null)
            {
                speakText += Format(botResponse2.Reply.Speak, new StringDictionary()
                {
                    { "taskCount", todos.Count.ToString() }
                });
            }

            var showText = Format(botResponse1.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });

            toDoCard.Speak = speakText;
            var body      = new List <AdaptiveElement>();
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);
            var choiceSet = new AdaptiveChoiceSetInput();

            choiceSet.IsMultiSelect = true;
            string value = Guid.NewGuid().ToString() + ",";
            int    index = 0;

            foreach (var todo in todos)
            {
                var choice = new AdaptiveChoice();
                choice.Title = todo.Topic;
                choice.Value = todo.Id;
                choiceSet.Choices.Add(choice);
                if (todo.IsCompleted)
                {
                    value += todo.Id + ",";
                }

                toDoCard.Speak += (++index) + "." + todo.Topic + " ";
            }

            value           = value.Remove(value.Length - 1);
            choiceSet.Value = value;
            body.Add(choiceSet);
            toDoCard.Body = body;

            var attachment = new Microsoft.Bot.Schema.Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = toDoCard,
            };

            return(attachment);
        }
Esempio n. 18
0
        protected Microsoft.Bot.Schema.Attachment ToAdaptiveCardAttachmentForOtherFlows(
            List <TaskItem> todos,
            int allTaskCount,
            string taskContent,
            BotResponse botResponse1,
            BotResponse botResponse2)
        {
            var toDoCard = new AdaptiveCard();
            var showText = Format(botResponse2.Reply.Text, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });
            var speakText = Format(botResponse1.Reply.Speak, new StringDictionary()
            {
                { "taskContent", taskContent }
            })
                            + Format(botResponse2.Reply.Speak, new StringDictionary()
            {
                { "taskCount", allTaskCount.ToString() }
            });

            toDoCard.Speak = speakText;

            var body      = new List <AdaptiveElement>();
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);
            var choiceSet = new AdaptiveChoiceSetInput
            {
                IsMultiSelect = true,
            };
            var value = Guid.NewGuid().ToString() + ",";

            foreach (var todo in todos)
            {
                var choice = new AdaptiveChoice
                {
                    Title = todo.Topic,
                    Value = todo.Id,
                };
                choiceSet.Choices.Add(choice);
                if (todo.IsCompleted)
                {
                    value += todo.Id + ",";
                }
            }

            value           = value.Remove(value.Length - 1);
            choiceSet.Value = value;
            body.Add(choiceSet);
            toDoCard.Body = body;

            var attachment = new Microsoft.Bot.Schema.Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = toDoCard,
            };

            return(attachment);
        }
        public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            var uiGrid = new Grid();

            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });

            var uiComboBox = new ComboBox();

            uiComboBox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox");
            uiComboBox.DataContext = input;

            var uiChoices = new ListBox();

            ScrollViewer.SetHorizontalScrollBarVisibility(uiChoices, ScrollBarVisibility.Disabled);
            var itemsPanelTemplate = new ItemsPanelTemplate();
            var factory            = new FrameworkElementFactory(typeof(WrapPanel));

            itemsPanelTemplate.VisualTree = factory;
            uiChoices.ItemsPanel          = itemsPanelTemplate;
            uiChoices.DataContext         = input;
            uiChoices.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput");

            foreach (var choice in input.Choices)
            {
                if (input.IsMultiSelect == true)
                {
                    var uiCheckbox = new CheckBox();
                    uiCheckbox.Content     = choice.Title;
                    uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                    uiCheckbox.DataContext = choice;
                    uiCheckbox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox");
                    uiChoices.Items.Add(uiCheckbox);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        var uiComboItem = new ComboBoxItem();
                        uiComboItem.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem");
                        uiComboItem.Content     = choice.Title;
                        uiComboItem.DataContext = choice;
                        uiComboBox.Items.Add(uiComboItem);

                        // If multiple values are specified, no option is selected
                        if (chosen.Contains(choice.Value) && chosen.Count == 1)
                        {
                            uiComboBox.SelectedItem = uiComboItem;
                        }
                    }
                    else
                    {
                        var uiRadio = new RadioButton();
                        uiRadio.Content = choice.Title;

                        // When isMultiSelect is false, only 1 specified value is accepted.
                        // Otherwise, don't set any option
                        if (chosen.Count == 1)
                        {
                            uiRadio.IsChecked = chosen.Contains(choice.Value);
                        }
                        uiRadio.GroupName   = input.Id;
                        uiRadio.DataContext = choice;
                        uiRadio.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio");
                        uiChoices.Items.Add(uiRadio);
                    }
                }
            }
            context.InputBindings.Add(input.Id, () =>
            {
                if (input.IsMultiSelect == true)
                {
                    string values = string.Empty;
                    foreach (var item in uiChoices.Items)
                    {
                        CheckBox checkBox             = (CheckBox)item;
                        AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice;
                        if (checkBox.IsChecked == true)
                        {
                            values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value;
                        }
                    }
                    return(values);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                        if (item != null)
                        {
                            AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice;
                            return(adaptiveChoice.Value);
                        }
                        return(null);
                    }
                    else
                    {
                        foreach (var item in uiChoices.Items)
                        {
                            RadioButton radioBox          = (RadioButton)item;
                            AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice;
                            if (radioBox.IsChecked == true)
                            {
                                return(adaptiveChoice.Value);
                            }
                        }
                        return(null);
                    }
                }
            });
            if (input.Style == AdaptiveChoiceInputStyle.Compact)
            {
                Grid.SetRow(uiComboBox, 1);
                uiGrid.Children.Add(uiComboBox);
                return(uiGrid);
            }
            else
            {
                Grid.SetRow(uiChoices, 1);
                uiGrid.Children.Add(uiChoices);
                return(uiGrid);
            }
        }
Esempio n. 20
0
 public static HtmlTag CallChoiceSetInputRender(AdaptiveChoiceSetInput element, AdaptiveRenderContext context)
 {
     return(ChoiceSetRender(element, context));
 }
Esempio n. 21
0
        public async Task <IActionResult> GetShippingCardJson(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("GetInventoryCardJson function processed a request.");
            int orderId = Convert.ToInt32(req.Query["orderId"]);

            var order = await ApplicationDbContext.Order.Include(x => x.Items).FirstAsync(x => x.Id == orderId);

            AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

            // add the heading
            card.Body.Add(new AdaptiveTextBlock()
            {
                Text   = $"Order #{orderId} Received",
                Size   = AdaptiveTextSize.Large,
                Weight = AdaptiveTextWeight.Bolder
            });

            // add the call to action
            card.Body.Add(new AdaptiveTextBlock()
            {
                Text   = $"Inventory verified. Please ship:",
                Weight = AdaptiveTextWeight.Bolder
            });

            // show the items in the order and their quantities
            var cartItemFactSet = new AdaptiveFactSet();

            foreach (var cartItem in order.Items)
            {
                var product = ApplicationDbContext.Products.Find(cartItem.ProductId);
                cartItemFactSet.Facts.Add(new AdaptiveFact
                {
                    Title = product.Name,
                    Value = cartItem.Quantity.ToString()
                });
            }
            card.Body.Add(cartItemFactSet);

            // add the choices
            var choices = new AdaptiveChoiceSetInput()
            {
                Id = "ShipmentConfirmed"
            };

            choices.Choices.Add(new AdaptiveChoice {
                Title = "Yes", Value = "true"
            });
            choices.Choices.Add(new AdaptiveChoice {
                Title = "No", Value = "false"
            });
            card.Body.Add(choices);

            // add the submit button
            card.Actions.Add(new AdaptiveSubmitAction
            {
                Id    = "ShipmentConfirmedOkButton",
                Title = "OK",
                Data  = new {
                    OrderId = order.Id
                }
            });

            // get the json for the card
            var json = card.ToJson();

            return(new OkObjectResult(json));
        }
Esempio n. 22
0
        public static FrameworkElement Render(AdaptiveChoiceSetInput input, AdaptiveRenderContext context)
        {
            var chosen = input.Value?.Split(',').Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToList() ?? new List <string>();

            var uiGrid = new Grid();

            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            uiGrid.RowDefinitions.Add(new RowDefinition()
            {
                Height = new GridLength(1, GridUnitType.Star)
            });

            var uiComboBox = new ComboBox();

            uiComboBox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBox");
            uiComboBox.DataContext = input;

            var uiChoices = new StackPanel();

            uiChoices.DataContext = input;
            uiChoices.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput");

            foreach (var choice in input.Choices)
            {
                if (input.IsMultiSelect == true)
                {
                    var uiCheckbox = new CheckBox();
                    SetContent(uiCheckbox, choice.Title, input.Wrap);
                    uiCheckbox.IsChecked   = chosen.Contains(choice.Value);
                    uiCheckbox.DataContext = choice;
                    uiCheckbox.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.CheckBox");
                    uiChoices.Children.Add(uiCheckbox);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        var uiComboItem = new ComboBoxItem();
                        uiComboItem.HorizontalAlignment = HorizontalAlignment.Stretch;
                        uiComboItem.Style = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.ComboBoxItem");

                        TextBlock content = SetContent(uiComboItem, choice.Title, input.Wrap);
                        // The content TextBlock is binded to the width of the comboBox container
                        if (input.Wrap && content != null)
                        {
                            BindingOperations.SetBinding(content, TextBlock.MaxWidthProperty,
                                                         new Binding("ActualWidth")
                            {
                                Source = uiComboBox
                            });
                        }

                        uiComboItem.DataContext = choice;

                        uiComboBox.Items.Add(uiComboItem);

                        // If multiple values are specified, no option is selected
                        if (chosen.Contains(choice.Value) && chosen.Count == 1)
                        {
                            uiComboBox.SelectedItem = uiComboItem;
                        }
                    }
                    else
                    {
                        var uiRadio = new RadioButton();
                        SetContent(uiRadio, choice.Title, input.Wrap);

                        // When isMultiSelect is false, only 1 specified value is accepted.
                        // Otherwise, don't set any option
                        if (chosen.Count == 1)
                        {
                            uiRadio.IsChecked = chosen.Contains(choice.Value);
                        }
                        uiRadio.GroupName   = input.Id;
                        uiRadio.DataContext = choice;
                        uiRadio.Style       = context.GetStyle("Adaptive.Input.AdaptiveChoiceSetInput.Radio");
                        uiChoices.Children.Add(uiRadio);
                    }
                }
            }
            context.InputBindings.Add(input.Id, () =>
            {
                if (input.IsMultiSelect == true)
                {
                    string values = string.Empty;
                    foreach (var item in uiChoices.Children)
                    {
                        CheckBox checkBox             = (CheckBox)item;
                        AdaptiveChoice adaptiveChoice = checkBox.DataContext as AdaptiveChoice;
                        if (checkBox.IsChecked == true)
                        {
                            values += (values == string.Empty ? "" : ",") + adaptiveChoice.Value;
                        }
                    }
                    return(values);
                }
                else
                {
                    if (input.Style == AdaptiveChoiceInputStyle.Compact)
                    {
                        ComboBoxItem item = uiComboBox.SelectedItem as ComboBoxItem;
                        if (item != null)
                        {
                            AdaptiveChoice adaptiveChoice = item.DataContext as AdaptiveChoice;
                            return(adaptiveChoice.Value);
                        }
                        return(null);
                    }
                    else
                    {
                        foreach (var item in uiChoices.Children)
                        {
                            RadioButton radioBox          = (RadioButton)item;
                            AdaptiveChoice adaptiveChoice = radioBox.DataContext as AdaptiveChoice;
                            if (radioBox.IsChecked == true)
                            {
                                return(adaptiveChoice.Value);
                            }
                        }
                        return(null);
                    }
                }
            });

            if (!input.IsMultiSelect && input.Style == AdaptiveChoiceInputStyle.Compact)
            {
                Grid.SetRow(uiComboBox, 1);
                uiGrid.Children.Add(uiComboBox);
                return(uiGrid);
            }
            else
            {
                Grid.SetRow(uiChoices, 1);
                uiGrid.Children.Add(uiChoices);
                return(uiGrid);
            }
        }
Esempio n. 23
0
        private async Task HandleSelectAnswerFromCard(Microsoft.Bot.Connector.Activity activity)
        {
            ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

            // get question details
            int questionId = Convert.ToInt32((activity.Value as dynamic)["questionId"]);
            var question   = SQLService.GetQuestion(questionId);

            // get user details
            var channelData = activity.GetChannelData <Microsoft.Bot.Connector.Teams.Models.TeamsChannelData>();
            var members     = await connector.Conversations.GetConversationMembersAsync(channelData.Team.Id);

            var teamsMembers = members.AsTeamsChannelAccounts();
            var currentUser  = teamsMembers.Where(x => x.ObjectId == activity.From.Properties["aadObjectId"].ToString()).FirstOrDefault();
            var studentUPN   = currentUser.UserPrincipalName;

            // var isUserAdmin = SharePointServices.IsUserAdmin(studentUPN);
            var isUserAdmin = SQLService.IsUserAdmin(studentUPN);

            // check if user can set question status
            if (isUserAdmin || (studentUPN == question.OriginalPoster.Email) || (studentUPN == question.OriginalPoster.UserName))
            {
                // find replies
                string teamId         = (activity.ChannelData as dynamic)["team"]["id"].ToString();
                string channelId      = (activity.ChannelData as dynamic)["channel"]["id"].ToString();
                var    conversationId = activity.Conversation.Id;
                string messageId      = conversationId.Split('=')[1];

                // update old activity
                Microsoft.Bot.Connector.Activity updatedReply = activity.CreateReply();

                var replies = await GetAllReplies(question.GroupId, channelId, messageId);

                var adaptiveCardChoices = new List <AdaptiveChoice>();
                if (replies != null && replies.Count > 0)
                {
                    foreach (var reply in replies)
                    {
                        adaptiveCardChoices.Add(new AdaptiveChoice()
                        {
                            Title = MicrosoftTeamsChannelHelper.StripMentionAndHtml(reply.Body.Content),
                            Value = JsonConvert.SerializeObject(reply),
                        });
                    }

                    var bodyTextBlock = new AdaptiveTextBlock()
                    {
                        Text = "Select an answer"
                    };
                    var bodyChoice = new AdaptiveChoiceSetInput()
                    {
                        Id            = "Answer",
                        Style         = AdaptiveChoiceInputStyle.Compact,
                        IsMultiSelect = false,
                        Choices       = adaptiveCardChoices,
                    };

                    var adaptiveCardAnswerSubmit = new AdaptiveCardAnswerSubmit(Constants.ACTIVITY_MARKED_ANSWERED, bodyChoice.Value, questionId.ToString());
                    var adaptiveCardAnswerString = JsonConvert.SerializeObject(adaptiveCardAnswerSubmit);
                    var actionJson = "{\"type\":\"" + Constants.ACTIVITY_SELECT_ANSWER + "\",\"questionId\": \"" + questionId.ToString() + "\"}";

                    var adaptiveCard = new AdaptiveCard()
                    {
                        Actions = new List <AdaptiveAction>()
                        {
                            new AdaptiveSubmitAction()
                            {
                                Title    = "Save",
                                DataJson = adaptiveCardAnswerString,
                            },
                            new AdaptiveSubmitAction()
                            {
                                Title    = "Refresh",
                                DataJson = actionJson,
                            },
                        },
                    };

                    adaptiveCard.Body.Add(bodyTextBlock);
                    adaptiveCard.Body.Add(bodyChoice);

                    var attachment = new Attachment()
                    {
                        ContentType = AdaptiveCard.ContentType,
                        Content     = adaptiveCard,
                    };

                    updatedReply.Attachments.Add(attachment);

                    try
                    {
                        // await connector.Conversations.UpdateActivityAsync(updatedReply);
                        updatedReply.Id = activity.ReplyToId;
                        var response = await connector.Conversations.UpdateActivityAsync(activity.Conversation.Id, activity.ReplyToId, updatedReply);
                    }
                    catch (Exception e)
                    {
                        Trace.TraceError(e.ToString());
                    }
                }
            }
        }
Esempio n. 24
0
 public virtual void Visit(AdaptiveChoiceSetInput adaptiveChoiceSetInput)
 {
 }
Esempio n. 25
0
        protected Attachment ToAdaptiveCardForPreviousPage(
            List <TaskItem> todos,
            int toBeReadTasksCount)
        {
            var toDoCard  = new AdaptiveCard();
            var speakText = Format(ShowToDoResponses.ShowPreviousToDoTasks.Reply.Speak, new StringDictionary()
            {
            })
                            + Format(ShowToDoResponses.FirstToDoTasks.Reply.Speak, new StringDictionary()
            {
                { "taskCount", toBeReadTasksCount.ToString() }
            });

            toDoCard.Speak = speakText;

            var body     = new List <AdaptiveElement>();
            var showText = Format(ShowToDoResponses.ShowPreviousToDoTasks.Reply.Text, new StringDictionary()
            {
            });
            var textBlock = new AdaptiveTextBlock
            {
                Text = showText,
            };

            body.Add(textBlock);

            var choiceSet = new AdaptiveChoiceSetInput
            {
                IsMultiSelect = true,
            };

            var value = Guid.NewGuid().ToString() + ",";
            var index = 0;

            foreach (var todo in todos)
            {
                var choice = new AdaptiveChoice
                {
                    Title = todo.Topic,
                    Value = todo.Id,
                };
                choiceSet.Choices.Add(choice);
                if (todo.IsCompleted)
                {
                    value += todo.Id + ",";
                }

                if (index < toBeReadTasksCount)
                {
                    toDoCard.Speak += (++index) + " " + todo.Topic + " ";
                }
            }

            value           = value.Remove(value.Length - 1);
            choiceSet.Value = value;
            body.Add(choiceSet);
            toDoCard.Body = body;

            var attachment = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = toDoCard,
            };

            return(attachment);
        }