Beispiel #1
0
        private static AdaptiveCard HolidayListAdaptiveCard(List <string> date, List <string> description)
        {
            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
            List <AdaptiveColumn> columns = new List <AdaptiveColumn>();
            AdaptiveColumn        column  = AdaptiveCardHelper.AddAdaptiveColumn();
            AdaptiveColumn        column1 = AdaptiveCardHelper.AddAdaptiveColumn();
            AdaptiveColumn        column2 = AdaptiveCardHelper.AddAdaptiveColumn();

            AdaptiveCardHelper.AddItemToAdaptiveColumn(column, AdaptiveCardHelper.AddTextBlock("Sr. No", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Accent));
            AdaptiveCardHelper.AddItemToAdaptiveColumn(column1, AdaptiveCardHelper.AddTextBlock("Date", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Good));
            AdaptiveCardHelper.AddItemToAdaptiveColumn(column2, AdaptiveCardHelper.AddTextBlock("Description", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Dark));

            for (int i = 0; i < date.Count; i++)
            {
                AdaptiveCardHelper.AddItemToAdaptiveColumn(column, AdaptiveCardHelper.AddTextBlock((i + 1).ToString()));
                AdaptiveCardHelper.AddItemToAdaptiveColumn(column1, AdaptiveCardHelper.AddTextBlock((date[i]).ToString()));
                AdaptiveCardHelper.AddItemToAdaptiveColumn(column2, AdaptiveCardHelper.AddTextBlock((description[i]).ToString()));
            }

            var columnSet = new AdaptiveColumnSet();

            columnSet.Columns.Add(column);
            columnSet.Columns.Add(column1);
            columnSet.Columns.Add(column2);
            var container = new AdaptiveContainer();

            container.Style = AdaptiveContainerStyle.Emphasis;
            container.Items.Add(columnSet);
            card.Body.Add(container);
            return(card);
        }
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.Type == ActivityTypes.Message)
            {
                // Check if user submitted AdaptiveCard input
                if (turnContext.Activity.Value != null)
                {
                    // Convert String to JObject
                    String  value   = turnContext.Activity.Value.ToString();
                    JObject results = JObject.Parse(value);

                    // Get type from input field
                    String name = results.GetValue("Type").ToString();
                    //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 = 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 = 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 = 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
                {
                    //// Send user AdaptiveCard
                    ////var cardAttachment = GetUserInputForCustomPPT();
                    ////var reply = turnContext.Activity.CreateReply();
                    ////reply.Attachments = new List<Attachment>() { cardAttachment };
                    ////await turnContext.SendActivityAsync(reply, cancellationToken);

                    //var cardAttachment = GetUserInputForCustomPPT();
                    ////await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment), cancellationToken);
                    //await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment), cancellationToken);
                    //await turnContext.SendActivityAsync(MessageFactory.Text("Please enter any text to see another card."), cancellationToken);

                    //2.
                    turnContext.Activity.RemoveRecipientMention();
                    var        text           = turnContext.Activity.Text.Trim().ToLower();
                    var        attachments    = new List <Attachment>();
                    var        reply          = MessageFactory.Attachment(attachments);
                    Attachment cardAttachment = null;
                    //if (text.Contains("testdc"))
                    if (text.Contains("hi"))
                    {
                        RequestBody        Body         = CreateBody(text);
                        CreateResponseBody responseBody = CreateAPIPostCall(Body);
                        if (responseBody != null)
                        {
                            await turnContext.SendActivityAsync(MessageFactory.Text(responseBody.Text), cancellationToken);
                        }
                    }

                    if (text.Contains("*****@*****.**") || text.Contains("i want to raise an issue"))
                    {
                        RequestBody        Body         = CreateBody(text);
                        CreateResponseBody responseBody = CreateAPIPostCall(Body);
                        if (responseBody != null)
                        {
                            string test = string.Empty;
                            if (responseBody.OutputStack != null && responseBody.OutputStack.Count() > 0)
                            {
                                foreach (var OutputStack in responseBody.OutputStack)
                                {
                                    if (!string.IsNullOrEmpty(OutputStack.Text))
                                    {
                                        test = OutputStack.Text;
                                        await turnContext.SendActivityAsync(MessageFactory.Text(test), cancellationToken);
                                    }
                                    else
                                    {
                                        //if(OutputStack.Data._cognigy._default._buttons.type=="buttons")
                                        if (OutputStack.Data.type == "buttons")
                                        {
                                            string btnText = OutputStack.Data._cognigy._default._buttons.text;
                                            if (OutputStack.Data._cognigy._default._buttons.buttons != null && OutputStack.Data._cognigy._default._buttons.buttons.Count() > 0)
                                            {
                                                var mainCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
                                                //add textblock to the button
                                                // Add text to the card.
                                                mainCard.Body.Add(AdaptiveCardHelper.AddTextBlock(btnText));

                                                foreach (var button in OutputStack.Data._cognigy._default._buttons.buttons)
                                                {
                                                    string btnActionText = button.title;
                                                    //double btnId = button.id;
                                                    string btnId      = Guid.NewGuid().ToString();
                                                    string btnpayload = button.payload;

                                                    mainCard.Actions.Add(AddButtonToAdaptiveCard(btnId, btnActionText, btnpayload));
                                                }
                                                cardAttachment = new Attachment()
                                                {
                                                    ContentType = AdaptiveCard.ContentType,
                                                    Content     = mainCard
                                                };
                                                if (cardAttachment != null)
                                                {
                                                    await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment), cancellationToken);

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

                            //AdaptiveCard card = CreateAdaptiveCard_WithDynamicContent1();
                            AdaptiveCard card = DisplayActionCards();
                            cardAttachment = new Attachment()
                            {
                                ContentType = AdaptiveCard.ContentType,
                                Content     = card
                            };
                            reply.Attachments.Add(cardAttachment);
                        }
                    }
                    if (cardAttachment != null)
                    {
                        await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment), cancellationToken);

                        //await turnContext.SendActivityAsync(MessageFactory.Text("Please enter any text to see another card."), cancellationToken);
                    }
                }
            }
        }
Beispiel #3
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);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        private static AdaptiveCard HolidayListAdaptiveCardMoreDynamic(List <string> date, List <string> description)
        {
            var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
            List <AdaptiveColumn> columns = new List <AdaptiveColumn>();
            AdaptiveColumn        column  = AdaptiveCardHelper.AddAdaptiveColumn();
            AdaptiveColumn        column1 = AdaptiveCardHelper.AddAdaptiveColumn();
            AdaptiveColumn        column2 = AdaptiveCardHelper.AddAdaptiveColumn();

            AdaptiveCardHelper.AddTextBlockWithColumn(column, "Sr.No", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Accent);
            AdaptiveCardHelper.AddTextBlockWithColumn(column1, "Date", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Good);
            AdaptiveCardHelper.AddTextBlockWithColumn(column2, "Description", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Dark);

            for (int i = 0; i < date.Count; i++)
            {
                AdaptiveCardHelper.AddItemToAdaptiveColumn(column, AdaptiveCardHelper.AddTextBlock((i + 1).ToString()));
                AdaptiveCardHelper.AddItemToAdaptiveColumn(column1, AdaptiveCardHelper.AddTextBlock((date[i]).ToString()));
                AdaptiveCardHelper.AddItemToAdaptiveColumn(column2, AdaptiveCardHelper.AddTextBlock((description[i]).ToString()));
            }

            var columnSet = new AdaptiveColumnSet();

            columnSet.Columns.Add(column);
            columnSet.Columns.Add(column1);
            columnSet.Columns.Add(column2);
            AdaptiveContainer container = AdaptiveCardHelper.AddAdaptiveContainer(columnSet);

            card.Body.Add(container);
            return(card);


            ////++++++++++++++++++++++++++++++++++++++++++++
            ///https://stackoverflow.com/questions/11632816/can-i-count-properties-before-i-create-an-object-in-the-constructor
            /////https://stackoverflow.com/questions/27335689/creating-objects-within-a-loop
            ///https://social.msdn.microsoft.com/Forums/SECURITY/en-US/d7e26819-2731-402a-90a5-b512cb11eca5/how-do-i-create-a-loop-that-creates-multiple-objects-of-a-class?forum=csharpgeneral
            //var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));
            //List<AdaptiveColumn> columns = new List<AdaptiveColumn>();
            ////AdaptiveColumn column = AdaptiveCardHelper.AddAdaptiveColumn();
            ////AdaptiveColumn column1 = AdaptiveCardHelper.AddAdaptiveColumn();
            ////AdaptiveColumn column2 = AdaptiveCardHelper.AddAdaptiveColumn();
            //for (int i = 0; i < 2; i++)
            //{
            //    columns.Add(new AdaptiveColumn());
            //}

            //AdaptiveCardHelper.AddTextBlockWithColumn(columns[0], "Sr.No", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Accent);
            //AdaptiveCardHelper.AddTextBlockWithColumn(columns[1], "Date", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Good);
            //AdaptiveCardHelper.AddTextBlockWithColumn(columns[2], "Description", AdaptiveTextWeight.Bolder, AdaptiveTextSize.Large, AdaptiveTextColor.Dark);

            //for (int i = 0; i < date.Count; i++)
            //{
            //    //for (int i1 = 0; i1 < 2; i1++)
            //    //{
            //    //    AdaptiveCardHelper.AddItemToAdaptiveColumn(columns[i1], AdaptiveCardHelper.AddTextBlock((i + 1).ToString()));
            //    //    AdaptiveCardHelper.AddItemToAdaptiveColumn(columns[i1+1], AdaptiveCardHelper.AddTextBlock((date[i]).ToString()));
            //    //    AdaptiveCardHelper.AddItemToAdaptiveColumn(columns[i1+2], AdaptiveCardHelper.AddTextBlock((description[i]).ToString()));
            //    //}
            //    AdaptiveCardHelper.AddItemToAdaptiveColumn(columns[0], AdaptiveCardHelper.AddTextBlock((i + 1).ToString()));
            //    AdaptiveCardHelper.AddItemToAdaptiveColumn(columns[1], AdaptiveCardHelper.AddTextBlock((date[i]).ToString()));
            //    AdaptiveCardHelper.AddItemToAdaptiveColumn(columns[2], AdaptiveCardHelper.AddTextBlock((description[i]).ToString()));
            //}

            //var columnSet = new AdaptiveColumnSet();
            //columnSet.Columns.Add(columns[0]);
            //columnSet.Columns.Add(columns[1]);
            //columnSet.Columns.Add(columns[2]);
            //AdaptiveContainer container = AdaptiveCardHelper.AddAdaptiveContainer(columnSet);
            //card.Body.Add(container);
            //return card;
        }