public void TabRequestInits(TabEntityContext tabEntityContext, TabContext tabContext, string state) { var tabRequest = new TabRequest() { TabEntityContext = tabEntityContext, Context = tabContext, State = state, }; Assert.NotNull(tabRequest); Assert.IsType <TabRequest>(tabRequest); Assert.Equal(tabEntityContext, tabRequest.TabEntityContext); Assert.Equal(tabContext, tabRequest.Context); Assert.Equal(state, tabRequest.State); }
/// <summary> /// Override this in a derived class to provide logic for when a tab is fetched. /// </summary> /// <param name="turnContext">A strongly-typed context object for this turn.</param> /// <param name="tabRequest">The tab invoke request value payload.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects /// or threads to receive notice of cancellation.</param> /// <returns>A Tab Response for the request.</returns> protected virtual Task <TabResponse> OnTeamsTabFetchAsync(ITurnContext <IInvokeActivity> turnContext, TabRequest tabRequest, CancellationToken cancellationToken) { throw new InvokeResponseException(HttpStatusCode.NotImplemented); }
/// <summary> /// Invoked when an fetch activity is recieved for tab. /// </summary> /// <param name="turnContext"></param> /// <param name="tabRequest"></param> /// <param name="cancellationToken"></param> /// <returns>Tab response.</returns> protected override async Task <TabResponse> OnTeamsTabFetchAsync(ITurnContext <IInvokeActivity> turnContext, TabRequest tabRequest, CancellationToken cancellationToken) { var userTokenClient = turnContext.TurnState.Get <UserTokenClient>(); if (tabRequest.TabEntityContext.TabEntityId == "homeTab") { // Check the state value var state = JsonConvert.DeserializeObject <AdaptiveCardAction>(turnContext.Activity.Value.ToString()); var tokenResponse = await GetTokenResponse(turnContext, state.State, cancellationToken); if (tokenResponse == null || string.IsNullOrEmpty(tokenResponse.Token)) { // There is no token, so the user has not signed in yet. var resource = await userTokenClient.GetSignInResourceAsync(_connectionName, turnContext.Activity as Activity, null, cancellationToken); // Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions var signInLink = resource.SignInLink; return(new TabResponse { Tab = new TabResponsePayload { Type = "auth", SuggestedActions = new TabSuggestedActions { Actions = new List <CardAction> { new CardAction { Type = ActionTypes.OpenUrl, Value = signInLink, Title = "Sign in to this app", }, }, }, }, }); } var client = new SimpleGraphClient(tokenResponse.Token); var profile = await client.GetUserProfile(); var userPhoto = await client.GetPublicURLForProfilePhoto(_applicationBaseUrl); return(new TabResponse { Tab = new TabResponsePayload { Type = "continue", Value = new TabResponseCards { Cards = new List <TabResponseCard> { new TabResponseCard { Card = CardHelper.GetSampleAdaptiveCard1(userPhoto, profile.DisplayName) }, new TabResponseCard { Card = CardHelper.GetSampleAdaptiveCard2() }, }, }, }, }); } else { return(new TabResponse { Tab = new TabResponsePayload { Type = "continue", Value = new TabResponseCards { Cards = new List <TabResponseCard> { new TabResponseCard { Card = CardHelper.GetSampleAdaptiveCard3() }, }, }, }, }); } }