コード例 #1
0
        private async Task SendOpenPositionsMessage(IDialogContext context)
        {
            var openPositions = new OpenPositionsDataController().ListOpenPositions(5);

            IMessageActivity reply = context.MakeMessage();

            reply.Attachments = new List <Attachment>();
            reply.Text        = $"Hi {context.Activity.From.Name}! You have {openPositions.Count} active postings right now:";

            foreach (OpenPosition position in openPositions)
            {
                ThumbnailCard card = CardHelper.CreateCardForPosition(position);
                reply.Attachments.Add(card.ToAttachment());
            }

            ThumbnailCard buttonsCard = new ThumbnailCard();

            buttonsCard.Buttons = new List <CardAction>()
            {
                new CardAction("openUrl", "View details", null, "https://www.microsoft.com"),
                new CardAction("messageBack", "Add new job posting", null, null, $"new job posting", "New job posting")
            };
            reply.Attachments.Add(buttonsCard.ToAttachment());
            await context.PostAsync(reply);
        }
コード例 #2
0
        private async Task SendNewPostingConfirmationMessage(IDialogContext context, OpenPosition pos)
        {
            IMessageActivity reply = context.MakeMessage();

            reply.Attachments = new List <Attachment>();
            reply.Text        = $"Your position has been created. Please also upload the job description now.";

            ThumbnailCard positionCard = CardHelper.CreateCardForPosition(pos, false);

            reply.Attachments.Add(positionCard.ToAttachment());

            await context.PostAsync(reply);
        }
コード例 #3
0
        /// <summary>
        /// Helper method to generate a the messaging extension response.
        ///
        /// Note that for this sample, we are returning generated positions for illustration purposes only.
        /// </summary>
        /// <returns></returns>
        public ComposeExtensionResponse CreateResponse()
        {
            ComposeExtensionResponse response = null;

            var     query = activity.GetComposeExtensionQueryData();
            JObject data  = activity.Value as JObject;

            // Check if this is a task module invocation.
            if (data != null && data["type"] != null)
            {
                // Handle other types of Invoke activities here, e.g. CardActions
                if (data["type"].ToString() == TaskModuleCommandType && data["command"].ToString() == CreatePostingCommand)
                {
                    response = CreateTaskModuleResponse();
                }
            }
            else
            {
                //Check to make sure a query was actually made:
                if (query.CommandId == null || query.Parameters == null)
                {
                    return(null);
                }
                else if (query.Parameters.Count > 0)
                {
                    // query.Parameters has the parameters sent by client
                    var results = new ComposeExtensionResult()
                    {
                        AttachmentLayout = "list",
                        Type             = "result",
                        Attachments      = new List <ComposeExtensionAttachment>(),
                    };

                    if (query.CommandId == "searchPositions")
                    {
                        OpenPositionsDataController controller = new OpenPositionsDataController();
                        IEnumerable <OpenPosition>  positions;

                        if (query.Parameters[0].Name == "initialRun")
                        {
                            // Default query => list all
                            positions = controller.ListOpenPositions(10);
                        }
                        else
                        {
                            // Basic search.
                            string title = query.Parameters[0].Value.ToString().ToLower();
                            positions = controller.ListOpenPositions(10).Where(x => x.Title.ToLower().Contains(title));
                        }

                        // Generate cards for the response.
                        foreach (OpenPosition pos in positions)
                        {
                            var card = CardHelper.CreateCardForPosition(pos, true);

                            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment();
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }
                    else if (query.CommandId == "searchCandidates")
                    {
                        string name = query.Parameters[0].Value.ToString();
                        CandidatesDataController controller = new CandidatesDataController();

                        foreach (Candidate c in controller.GetTopCandidates("ABCD1234"))
                        {
                            c.Name = c.Name.Split(' ')[0] + " " + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(name);
                            var card = CardHelper.CreateSummaryCardForCandidate(c);

                            var composeExtensionAttachment = card.ToAttachment().ToComposeExtensionAttachment(CardHelper.CreatePreviewCardForCandidate(c).ToAttachment());
                            results.Attachments.Add(composeExtensionAttachment);
                        }
                    }

                    response = new ComposeExtensionResponse()
                    {
                        ComposeExtension = results
                    };
                }
            }
            return(response);
        }