protected override async Task <InvokeResponse> OnInvokeActivityAsync(ITurnContext <IInvokeActivity> turnContext, CancellationToken cancellationToken) { if (AdaptiveCardInvokeValidator.IsAdaptiveCardAction(turnContext)) { var userSA = _userState.CreateProperty <User>(nameof(User)); var user = await userSA.GetAsync(turnContext, () => new User() { Id = turnContext.Activity.From.Id }); try { AdaptiveCardInvoke request = AdaptiveCardInvokeValidator.ValidateRequest(turnContext); var cardOptions = AdaptiveCardInvokeValidator.ValidateAction <CardOptions>(request); if (request.Action.Verb == "order") { // process action var responseBody = await ProcessOrderAction(user, cardOptions); return(CreateInvokeResponse(HttpStatusCode.OK, responseBody)); } if (request.Action.Verb == "err") { var responseBody = await ProcessErrAction(user, cardOptions); return(CreateInvokeResponse(HttpStatusCode.OK, responseBody)); } else { AdaptiveCardActionException.VerbNotSupported(request.Action.Type); } } catch (AdaptiveCardActionException e) { return(CreateInvokeResponse(HttpStatusCode.OK, e.Response)); } } return(null); }
protected override async Task <InvokeResponse> OnInvokeActivityAsync(ITurnContext <IInvokeActivity> turnContext, CancellationToken cancellationToken) { if (AdaptiveCardInvokeValidator.IsAdaptiveCardAction(turnContext) && (turnContext.Activity.Name == "adaptiveCard/action")) { var userSA = _userState.CreateProperty <User>(nameof(User)); var user = await userSA.GetAsync(turnContext, () => new User() { Id = turnContext.Activity.From.Id }); try { AdaptiveCardInvoke request = AdaptiveCardInvokeValidator.ValidateRequest(turnContext); if (request.Action.Verb == "initialRefresh") { var members = new List <TeamsChannelAccount>(); string continuationToken = null; do { var currentPage = await TeamsInfo.GetPagedMembersAsync(turnContext, 100, continuationToken, cancellationToken); continuationToken = currentPage.ContinuationToken; members.AddRange(currentPage.Members); }while (continuationToken != null); foreach (var member in members) { if (member.AadObjectId != turnContext.Activity.From.AadObjectId) { var newMemberInfo = new MemberDetails { value = member.Id, title = member.Name }; memberDetails.Add(newMemberInfo); } } var cardOptions = AdaptiveCardInvokeValidator.ValidateAction <InitialCardOptions>(request); var responseBody = await ProcessCreateIncident(cardOptions, turnContext); return(CreateInvokeResponse(responseBody)); } else if (request.Action.Verb == "createIncident") { var cardOptions = AdaptiveCardInvokeValidator.ValidateAction <CreateIncidentCardOptions>(request); var responseBody = await ProcessReviewIncident(cardOptions, turnContext); return(CreateInvokeResponse(responseBody)); } else if (request.Action.Verb == "editOrResolveIncident") { var cardOptions = AdaptiveCardInvokeValidator.ValidateAction <ReviewIncidentCardOptions>(request); if (cardOptions.createdByUserID == turnContext.Activity.From.Id) { var responseBody = await ProcessCancelOrResolveIncident("CancelIncident.json", cardOptions, turnContext); return(CreateInvokeResponse(responseBody)); } else if (cardOptions.assignedToUserID == turnContext.Activity.From.Id) { var responseBody = await ProcessCancelOrResolveIncident("ResolveIncident.json", cardOptions, turnContext); return(CreateInvokeResponse(responseBody)); } } else if (request.Action.Verb == "cancelIncident" || request.Action.Verb == "resolveIncident") { var cardOptions = AdaptiveCardInvokeValidator.ValidateAction <CancelOrResolveIncidentOptions>(request); var responseBody = await CloseIncident(request.Action.Verb, cardOptions, turnContext); return(CreateInvokeResponse(responseBody)); } else { AdaptiveCardActionException.VerbNotSupported(request.Action.Type); } } catch (AdaptiveCardActionException e) { return(CreateInvokeResponse(HttpStatusCode.OK, e.Response)); } } return(null); }