示例#1
0
        /// <summary>
        /// Handle adaptive card submit in channel.
        /// Updates the ticket status based on the user submission.
        /// </summary>
        /// <param name="message">A message in a conversation.</param>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="ticketDetailStorageProvider">Provider to store ticket details to Azure Table Storage.</param>
        /// <param name="cardConfigurationStorageProvider">Provider to search card configuration details in Azure Table Storage.</param>
        /// <param name="logger">Sends logs to the Application Insights service.</param>
        /// <param name="appBaseUrl">Represents the Application base Uri.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>A task that represents the work queued to execute.</returns>
        internal static async Task OnAdaptiveCardSubmitInChannelAsync(
            IMessageActivity message,
            ITurnContext <IMessageActivity> turnContext,
            ITicketDetailStorageProvider ticketDetailStorageProvider,
            ICardConfigurationStorageProvider cardConfigurationStorageProvider,
            ILogger logger,
            string appBaseUrl,
            IStringLocalizer <Strings> localizer,
            CancellationToken cancellationToken)
        {
            string             smeNotification;
            IMessageActivity   userNotification;
            ChangeTicketStatus payload = ((JObject)message.Value).ToObject <ChangeTicketStatus>();

            payload.Action = payload.RequestType == null ? payload.Action : RequestTypeText;
            logger.LogInformation($"Received submit:  action={payload.Action} ticketId={payload.TicketId}");

            // Get the ticket from the data store.
            TicketDetail ticketData = await ticketDetailStorageProvider.GetTicketAsync(payload.TicketId);

            if (ticketData == null)
            {
                await turnContext.SendActivityAsync($"Ticket {payload.TicketId} was not found in the data store");

                logger.LogInformation($"Ticket {payload.TicketId} was not found in the data store");
                return;
            }

            // Update the ticket based on the payload.
            switch (payload.Action)
            {
            case ChangeTicketStatus.ReopenAction:
                ticketData.TicketStatus       = (int)TicketState.Atanmamış;
                ticketData.AssignedToName     = null;
                ticketData.AssignedToObjectId = null;
                ticketData.ClosedOn           = null;
                smeNotification  = localizer.GetString("SmeUnassignedStatus", message.From.Name);
                userNotification = MessageFactory.Text(localizer.GetString("ReopenedTicketUserNotification", ticketData.TicketId));
                break;

            case ChangeTicketStatus.CloseAction:
                ticketData.TicketStatus = (int)TicketState.Kapatılmış;
                ticketData.ClosedByName = message.From.Name;
                ticketData.ClosedOn     = message.From.AadObjectId;
                smeNotification         = localizer.GetString("SmeClosedStatus", message.From.Name);
                userNotification        = MessageFactory.Text(localizer.GetString("ClosedTicketUserNotification", ticketData.TicketId));
                break;

            case ChangeTicketStatus.AssignToSelfAction:
                ticketData.TicketStatus       = (int)TicketState.Atanmış;
                ticketData.AssignedToName     = message.From.Name;
                ticketData.AssignedToObjectId = message.From.AadObjectId;
                ticketData.ClosedOn           = null;
                smeNotification  = localizer.GetString("SmeAssignedStatus", message.From.Name);
                userNotification = MessageFactory.Text(localizer.GetString("AssignedTicketUserNotification", ticketData.TicketId));
                break;

            case ChangeTicketStatus.RequestTypeAction:
                ticketData.Severity    = (int)(TicketSeverity)Enum.Parse(typeof(TicketSeverity), payload.RequestType);
                ticketData.RequestType = payload.RequestType;
                logger.LogInformation($"Received submit:  action={payload.RequestType} ticketId={payload.TicketId}");
                smeNotification  = localizer.GetString("SmeSeverityStatus", ticketData.RequestType, message.From.Name);
                userNotification = MessageFactory.Text(localizer.GetString("RequestActionTicketUserNotification", ticketData.TicketId));
                break;

            default:
                logger.LogInformation($"Unknown status command {payload.Action}", SeverityLevel.Warning);
                return;
            }

            ticketData.LastModifiedByName     = message.From.Name;
            ticketData.LastModifiedByObjectId = message.From.AadObjectId;
            ticketData.LastModifiedOn         = DateTime.UtcNow;

            await ticketDetailStorageProvider.UpsertTicketAsync(ticketData);

            logger.LogInformation($"Ticket {ticketData.TicketId} updated to status ({ticketData.TicketStatus}, {ticketData.AssignedToObjectId}) in store");

            // Get card item element mappings
            var cardElementMapping = await cardConfigurationStorageProvider.GetCardItemElementMappingAsync(ticketData.CardId);

            // Update the card in the SME team.
            Activity updateCardActivity = new Activity(ActivityTypes.Message)
            {
                Id           = ticketData.SmeTicketActivityId,
                Conversation = new ConversationAccount {
                    Id = ticketData.SmeConversationId
                },
                Attachments = new List <Attachment> {
                    new SmeTicketCard(ticketData).GetTicketDetailsForSMEChatCard(cardElementMapping, ticketData, appBaseUrl, localizer)
                },
            };
            ResourceResponse updateResponse = await turnContext.UpdateActivityAsync(updateCardActivity, cancellationToken);

            logger.LogInformation($"Card for ticket {ticketData.TicketId} updated to status ({ticketData.TicketStatus}, {ticketData.AssignedToObjectId}), activityId = {updateResponse.Id}");

            // Post update to user and SME team thread.
            if (!string.IsNullOrEmpty(smeNotification))
            {
                ResourceResponse smeResponse = await turnContext.SendActivityAsync(smeNotification);

                logger.LogInformation($"SME team notified of update to ticket {ticketData.TicketId}, activityId = {smeResponse.Id}");
            }

            if (userNotification != null)
            {
                userNotification.Conversation = new ConversationAccount {
                    Id = ticketData.RequesterConversationId
                };
                ResourceResponse[] userResponse = await turnContext.Adapter.SendActivitiesAsync(turnContext, new Activity[] { (Activity)userNotification }, cancellationToken);

                logger.LogInformation($"User notified of update to ticket {ticketData.TicketId}, activityId = {userResponse.FirstOrDefault()?.Id}");
            }
        }
示例#2
0
 private ActionList getActions(Ticket ticket)
 {
     return(new ActionList(ChangeTicketStatus.Button(ticket)));
 }