protected override async Task <MessagingExtensionActionResponse> OnTeamsMessagingExtensionBotMessagePreviewSendAsync(ITurnContext <IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
        {
            var        submitData       = action.ToSubmitExampleData();
            var        adaptiveCard     = submitData.ToAdaptiveCard();
            var        responseActivity = Activity.CreateMessageActivity();
            Attachment attachment       = new Attachment()
            {
                ContentType = AdaptiveCard.ContentType,
                Content     = adaptiveCard,
            };

            responseActivity.Attachments.Add(attachment);
            try
            {
                // Send to channel where messaging extension invoked.
                var channelId = turnContext.Activity.TeamsGetChannelId();
                await turnContext.TeamsCreateConversationAsync(channelId, responseActivity);

                // Send card to "General" channel.
                var teamDetails = await TeamsInfo.GetTeamDetailsAsync(turnContext);

                await turnContext.TeamsCreateConversationAsync(teamDetails.Id, responseActivity);
            }
            catch (Exception ex)
            {
                // In group chat or personal scope..
                await turnContext.SendActivityAsync($"In Group Chat or Personal Teams scope. Sending card to compose-only.");
            }

            return(adaptiveCard.ToComposeExtensionResultResponse());
        }
示例#2
0
        protected override async Task <MessagingExtensionActionResponse> OnTeamsMessagingExtensionBotMessagePreviewSendAsync(ITurnContext <IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
        {
            // The data has been returned to the bot in the action structure.
            var activityPreview   = action.BotActivityPreview[0];
            var attachmentContent = activityPreview.Attachments[0].Content;
            var previewedCard     = JsonConvert.DeserializeObject <AdaptiveCard>(attachmentContent.ToString(), new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });

            var exampleData = AdaptiveCardHelper.CreateExampleData(previewedCard);

            // This is a send so we are done and we will create the adaptive card editor.
            var adaptiveCard = AdaptiveCardHelper.CreateAdaptiveCard(exampleData);

            var message = MessageFactory.Attachment(new Attachment {
                ContentType = AdaptiveCard.ContentType, Content = adaptiveCard
            });

            // THIS WILL WORK IF THE BOT IS INSTALLED. (GetMembers() will NOT throw if the bot is installed.)
            // (The application should fail gracefully.)
            var channelId = turnContext.Activity.TeamsGetChannelId();
            await turnContext.TeamsCreateConversationAsync(channelId, message, cancellationToken);

            return(null);
        }
示例#3
0
        public static Task <(ConversationReference conversationReference, string activityId)> TeamsSendToGeneralChannelAsync(this ITurnContext turnContext, IActivity activity, CancellationToken cancellationToken = default)
        {
            // The Team Id is also the Id of the general channel
            var teamId = turnContext.Activity.TeamsGetTeamId();

            if (string.IsNullOrEmpty(teamId))
            {
                throw new Exception("The current Activity was not sent from a Teams Team.");
            }

            return(turnContext.TeamsCreateConversationAsync(teamId, activity, cancellationToken));
        }
示例#4
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var teamChannelId = turnContext.Activity.TeamsGetChannelId();
            var message       = MessageFactory.Text("good morning");

            var(conversationReference, activityId) = await turnContext.TeamsCreateConversationAsync(teamChannelId, message, cancellationToken);

            await((BotFrameworkAdapter)turnContext.Adapter).ContinueConversationAsync(
                _botId,
                conversationReference,
                async(t, ct) =>
            {
                await t.SendActivityAsync(MessageFactory.Text("good afternoon"), ct);
                await t.SendActivityAsync(MessageFactory.Text("good night"), ct);
            },
                cancellationToken);
        }