private async Task <InvokeResponse> ProcessTeamsInvokeActivityAsync(ITurnContext turnContext)
        {
            ITeamsContext teamsContext = turnContext.TurnState.Get <ITeamsContext>();

            if (teamsContext.IsRequestMessagingExtensionQuery())
            {
                return(await this.invokeActivityHandler.HandleMessagingExtensionActionAsync(new MessagingExtensionActivityAction
                {
                    MessagingExtensionQuery = teamsContext.GetMessagingExtensionQueryData(),
                    TurnContext = turnContext,
                }).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestO365ConnectorCardActionQuery())
            {
                return(await this.invokeActivityHandler.HandleO365ConnectorCardActionAsync(new O365ConnectorCardActivityAction
                {
                    CardActionQuery = teamsContext.GetO365ConnectorCardActionQueryData(),
                    TurnContext = turnContext,
                }).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestSigninStateVerificationQuery())
            {
                return(await this.invokeActivityHandler.HandleSigninStateVerificationActionAsync(new SigninStateVerificationActivityAction
                {
                    TurnContext = turnContext,
                    VerificationQuery = teamsContext.GetSigninStateVerificationQueryData(),
                }).ConfigureAwait(false));
            }

            return(await this.invokeActivityHandler.HandleInvokeTaskAsync(turnContext).ConfigureAwait(false));
        }
Ejemplo n.º 2
0
        public async Task OnTurnAsync(ITurnContext turnCtx, CancellationToken cancellationToken)
        {
            try
            {
                if (turnCtx.Activity != null && turnCtx.Activity.Type != null && turnCtx.Activity.Type == ActivityTypes.Invoke)
                {
                    ITeamsContext teamsContext = turnCtx.TurnState.Get <ITeamsContext>();

                    MessagingExtensionQuery meQuery = null;
                    if (teamsContext.IsRequestMessagingExtensionQuery())
                    {
                        meQuery = teamsContext.GetMessagingExtensionQueryData();
                    }

                    InvokeResponse ir = new InvokeResponse
                    {
                        Body = new MessagingExtensionResponse
                        {
                            ComposeExtension = await searchHandler.GetSearchResultAsync(meQuery.Parameters[0].Value.ToString())
                        },
                        Status = 200,
                    };

                    await turnCtx.SendActivityAsync(
                        new Activity
                    {
                        Value = ir,
                        Type  = ActivityTypesEx.InvokeResponse,
                    }).ConfigureAwait(false);
                }
                else
                {
                    await turnCtx.SendActivityAsync(string.Format("Sorry! As of now I'm only support an invoke command, but you're trying to execute {0}", (turnCtx.Activity != null && turnCtx.Activity.Type != null) ? turnCtx.Activity.Type.ToString() : "empty activity"));
                }
            }
            catch (Exception ex)
            {
                await turnCtx.SendActivityAsync($"Oppps, seems like an error: {ex.InnerException}. Try again or contact your IT admin");
            }
        }
        private async Task <InvokeResponse> ProcessTeamsInvokeActivityAsync(ITurnContext turnContext)
        {
            ITeamsContext teamsContext = turnContext.TurnState.Get <ITeamsContext>();

            if (teamsContext.IsRequestO365ConnectorCardActionQuery())
            {
                return(await this.invokeActivityHandler.HandleO365ConnectorCardActionAsync(turnContext, teamsContext.GetO365ConnectorCardActionQueryData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestSigninStateVerificationQuery())
            {
                return(await this.invokeActivityHandler.HandleSigninStateVerificationActionAsync(turnContext, teamsContext.GetSigninStateVerificationQueryData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestFileConsentResponse())
            {
                return(await this.invokeActivityHandler.HandleFileConsentResponseAsync(turnContext, teamsContext.GetFileConsentQueryData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestMessagingExtensionQuery())
            {
                return(await this.invokeActivityHandler.HandleMessagingExtensionQueryAsync(turnContext, teamsContext.GetMessagingExtensionQueryData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestAppBasedLinkQuery())
            {
                return(await this.invokeActivityHandler.HandleAppBasedLinkQueryAsync(turnContext, teamsContext.GetAppBasedLinkQueryData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestMessagingExtensionFetchTask())
            {
                return(await this.invokeActivityHandler.HandleMessagingExtensionFetchTaskAsync(turnContext, teamsContext.GetMessagingExtensionActionData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestMessagingExtensionSubmitAction())
            {
                return(await this.invokeActivityHandler.HandleMessagingExtensionSubmitActionAsync(turnContext, teamsContext.GetMessagingExtensionActionData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestTaskModuleFetch())
            {
                return(await this.invokeActivityHandler.HandleTaskModuleFetchAsync(turnContext, teamsContext.GetTaskModuleRequestData()).ConfigureAwait(false));
            }

            if (teamsContext.IsRequestTaskModuleSubmit())
            {
                return(await this.invokeActivityHandler.HandleTaskModuleSubmitAsync(turnContext, teamsContext.GetTaskModuleRequestData()).ConfigureAwait(false));
            }

            return(await this.invokeActivityHandler.HandleInvokeTaskAsync(turnContext).ConfigureAwait(false));
        }