Skip to content

Commit

Permalink
Remove adaptive cards ref from teams samples (microsoft#2296)
Browse files Browse the repository at this point in the history
* Remove AdaptiveCards reference from TeamsTaskModule sample

* Remove AdaptiveCard reference from TeamsMessagingExtensionsSearchAuthConfig
  • Loading branch information
Eric Dahlvang authored Apr 24, 2020
1 parent b8c0b5d commit 54559a6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveCards;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Schema.Teams;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.BotBuilderSamples.Bots
Expand Down Expand Up @@ -251,15 +252,7 @@ protected override async Task<MessagingExtensionActionResponse> OnTeamsMessaging
{
Value = new TaskModuleTaskInfo
{
Card = new Attachment
{
Content = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
{
Body = new List<AdaptiveElement>() { new AdaptiveTextBlock() { Text = "You have been signed out." } },
Actions = new List<AdaptiveAction>() { new AdaptiveSubmitAction() { Title = "Close" } },
},
ContentType = AdaptiveCard.ContentType,
},
Card = CreateAdaptiveCardAttachment(),
Height = 200,
Width = 400,
Title = "Adaptive Card: Inputs",
Expand All @@ -270,6 +263,20 @@ protected override async Task<MessagingExtensionActionResponse> OnTeamsMessaging
return null;
}

private static Attachment CreateAdaptiveCardAttachment()
{
// combine path for cross platform support
string[] paths = { ".", "Resources", "adaptiveCard.json" };
var adaptiveCardJson = File.ReadAllText(Path.Combine(paths));

var adaptiveCardAttachment = new Attachment()
{
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCardJson),
};
return adaptiveCardAttachment;
}

// Generate a set of substrings to illustrate the idea of a set of results coming back from a query.
private async Task<IEnumerable<(string, string, string, string, string)>> FindPackages(string text)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "You have been signed out.",
"isSubtle": false
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Close"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.8.0" />
<PackageReference Include="Microsoft.Graph" Version="1.21.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Licensed under the MIT License.

using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using AdaptiveCards;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Teams;
using Microsoft.Bot.Schema;
Expand Down Expand Up @@ -38,7 +38,7 @@ protected override async Task<TaskModuleResponse> OnTeamsTaskModuleFetchAsync(IT
{
Value = new TaskModuleTaskInfo()
{
Card = this.GetTaskModuleAdaptiveCard(),
Card = CreateAdaptiveCardAttachment(),
Height = 200,
Width = 400,
Title = "Adaptive Card: Inputs",
Expand Down Expand Up @@ -74,32 +74,18 @@ private Attachment GetTaskModuleHeroCard()
}.ToAttachment();
}

private Attachment GetTaskModuleAdaptiveCard()
private static Attachment CreateAdaptiveCardAttachment()
{
var card = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
{
Body = new List<AdaptiveElement>()
{
new AdaptiveTextBlock() { Text = "Enter Text Here" },
new AdaptiveTextInput()
{
Id = "usertext",
Spacing = AdaptiveSpacing.None,
IsMultiline = true,
Placeholder = "add some text and submit",
},
},
Actions = new List<AdaptiveAction>()
{
new AdaptiveSubmitAction() { Title = "Submit" },
},
};
// combine path for cross platform support
string[] paths = { ".", "Resources", "adaptiveCard.json" };
var adaptiveCardJson = File.ReadAllText(Path.Combine(paths));

return new Attachment
var adaptiveCardAttachment = new Attachment()
{
Content = card,
ContentType = AdaptiveCards.AdaptiveCard.ContentType,
ContentType = "application/vnd.microsoft.card.adaptive",
Content = JsonConvert.DeserializeObject(adaptiveCardJson),
};
return adaptiveCardAttachment;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0",
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "Enter Text Here",
"weight": "bolder",
"isSubtle": false
},
{
"type": "Input.Text",
"id": "usertext",
"spacing": "none",
"isMultiLine": "true",
"placeholder": "add some text and submit"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Submit"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AdaptiveCards" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.8.0" />
</ItemGroup>
Expand Down

0 comments on commit 54559a6

Please sign in to comment.