Example #1
0
        public async Task NotifyRecruiterAboutNewOpenPosition(
            Position position,
            CancellationToken cancellationToken = default)
        {
            var recruiter = await _recruiterService.GetById(position.HiringManagerId, cancellationToken);

            if (recruiter?.ConversationData is null)
            {
                return;
            }

            var staticTabEntityId = "OpenPositionsTab"; // you can find this value in manifest definition
            var staticTabName     = "Potential candidates";

            PositionTemplateModel positionsTemplate = new PositionTemplateModel
            {
                Items = new List <Position> {
                    position
                },
                ButtonActions = new List <AdaptiveAction>
                {
                    new AdaptiveOpenUrlAction
                    {
                        Title = "Show all assigned positions",
                        Url   = new Uri(string.Format(CommonConstants.DeepLinkUrlFormat, _appSettings.MicrosoftAppId, staticTabEntityId, staticTabName))
                    }
                }
            };

            var attachments = (await _positionsTemplate.RenderTemplate(null, null, TemplateConstants.PositionAsAdaptiveCardWithMultipleItems, positionsTemplate)).Attachments;

            await SendToConversation("You have a new position assigned to you.", attachments, recruiter.ConversationData, cancellationToken);
        }
Example #2
0
        public async Task <IMessageActivity> OpenPositionAsync(
            ITurnContext turnContext,
            CancellationToken cancellationToken)
        {
            var commandData = JsonConvert.DeserializeObject <PositionCreateCommand>(turnContext.Activity.Value?.ToString());

            if (commandData is null)
            {
                return(null);
            }

            var position = await _positionService.AddNewPosition(commandData, cancellationToken);

            var positionsTemplate = new PositionTemplateModel
            {
                Items = new List <Position> {
                    position
                }
            };

            var messageActivity = await _positionsTemplate.RenderTemplate(turnContext, null, TemplateConstants.PositionAsAdaptiveCardWithMultipleItems, positionsTemplate);

            return(messageActivity);
        }
Example #3
0
        public async Task <InvokeResponse> HandleMessagingExtensionQueryAsync(
            ITurnContext turnContext,
            MessagingExtensionQuery query,
            CancellationToken cancellationToken)
        {
            var initialRunParameter = GetQueryParameterByName(query, "initialRun");

            // situation where the incoming payload was received from the config popup
            if (!string.IsNullOrEmpty(query.State))
            {
                initialRunParameter = bool.TrueString;
            }

            var isInitialRun = string.Equals(initialRunParameter, bool.TrueString, StringComparison.OrdinalIgnoreCase);
            var maxResults   = isInitialRun ? 5 : query.QueryOptions.Count ?? 25;

            var attachments = new List <MessagingExtensionAttachment>();
            var searchText  = GetQueryParameterByName(query, MessagingExtensionCommands.SearchTextParameterName);

            switch (query.CommandId)
            {
            case MessagingExtensionCommands.SearchPositions:
                var positions = await _positionService.Search(searchText, maxResults, cancellationToken);

                foreach (var position in positions)
                {
                    var positionsTemplate = new PositionTemplateModel
                    {
                        Items = new List <Position> {
                            position
                        },
                    };

                    var mainCard = await _positionsTemplate.RenderTemplate(turnContext, null, TemplateConstants.PositionAsAdaptiveCardWithMultipleItems, positionsTemplate);

                    var previewCard = await _positionsTemplate.RenderTemplate(turnContext, null, TemplateConstants.PositionAsThumbnailCardWithMultipleItems, positionsTemplate);

                    attachments.Add(mainCard.Attachments.First().ToMessagingExtensionAttachment(previewCard.Attachments.First()));
                }

                break;

            case MessagingExtensionCommands.SearchCandidates:
                var candidates = await _candidateService.Search(searchText, maxResults, cancellationToken);

                var interviewers = await _recruiterService.GetAllInterviewers(cancellationToken);

                foreach (var candidate in candidates)
                {
                    var templateModel = new CandidateTemplateModel
                    {
                        Items = new List <Candidate> {
                            candidate
                        },
                        Interviewers = interviewers,
                        AppSettings  = _appSettings,
                    };

                    var mainCard = await _candidatesTemplate.RenderTemplate(turnContext, null, TemplateConstants.CandidateAsAdaptiveCardWithMultipleItems, templateModel);

                    var previewCard = await _candidatesTemplate.RenderTemplate(turnContext, null, TemplateConstants.CandidateAsThumbnailCardWithMultipleItems, templateModel);

                    attachments.Add(mainCard.Attachments.First().ToMessagingExtensionAttachment(previewCard.Attachments.First()));
                }

                break;
            }

            return(_mapper.Map <MessagingExtensionAttachment[], InvokeResponse>(attachments.ToArray()));
        }