From 1de233a94dcacc731c5578f8469315c1a36b8cb2 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Fri, 6 Sep 2019 14:35:27 -0700 Subject: [PATCH 1/3] initial commit on msg ext --- .../Microsoft.Bot.Builder.Teams.csproj | 1 + .../AdapterWithErrorHandler.cs | 25 ++ .../Bots/MessagingExtensionsBot.cs | 62 +++ .../Controllers/BotController.cs | 35 ++ .../MessagingExtensions.csproj | 24 + .../Scenarios/MessagingExtensions/Program.cs | 20 + .../Properties/launchSettings.json | 28 ++ .../Scenarios/MessagingExtensions/Startup.cs | 55 +++ .../TeamsAppManifest/color.png | Bin 0 -> 1229 bytes .../TeamsAppManifest/color.zip | Bin 0 -> 2329 bytes .../TeamsAppManifest/manifest.json | 42 ++ .../TeamsAppManifest/outline.png | Bin 0 -> 383 bytes .../appsettings.Development.json | 9 + .../MessagingExtensions/appsettings.json | 4 + .../MessagingExtensions/wwwroot/default.html | 418 ++++++++++++++++++ .../csharp-dotnetcore/Scenarios/Scenarios.sln | 6 + 16 files changed, 729 insertions(+) create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/AdapterWithErrorHandler.cs create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Controllers/BotController.cs create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/MessagingExtensions.csproj create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Program.cs create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Properties/launchSettings.json create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.png create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.zip create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/manifest.json create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/outline.png create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/appsettings.Development.json create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/appsettings.json create mode 100644 experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/wwwroot/default.html diff --git a/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/Microsoft.Bot.Builder.Teams.csproj b/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/Microsoft.Bot.Builder.Teams.csproj index ff9e28915d..ce19521538 100644 --- a/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/Microsoft.Bot.Builder.Teams.csproj +++ b/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/Microsoft.Bot.Builder.Teams.csproj @@ -11,6 +11,7 @@ + diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/AdapterWithErrorHandler.cs b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/AdapterWithErrorHandler.cs new file mode 100644 index 0000000000..ccc0838cbb --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/AdapterWithErrorHandler.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.Bot.Builder.Integration.AspNet.Core; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace Microsoft.BotBuilderSamples +{ + public class AdapterWithErrorHandler : BotFrameworkHttpAdapter + { + public AdapterWithErrorHandler(IConfiguration configuration, ILogger logger) + : base(configuration, logger) + { + OnTurnError = async (turnContext, exception) => + { + // Log any leaked exception from the application. + logger.LogError($"Exception caught : {exception.Message}"); + + // Send a catch-all apology to the user. + await turnContext.SendActivityAsync("Sorry, it looks like something went wrong."); + }; + } + } +} diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs new file mode 100644 index 0000000000..5f847d17b8 --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Bot.Builder; +using Microsoft.Bot.Builder.Teams; +using Microsoft.Bot.Schema; +using Microsoft.Bot.Schema.Teams; +using Newtonsoft.Json.Linq; + +namespace Microsoft.BotBuilderSamples.Bots +{ + public class MessagingExtensionsBot : TeamsActivityHandler + { + protected override async Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) + { + //await turnContext.SendActivityAsync(MessageFactory.Text($"MessagingExtensions echo: {turnContext.Activity.Text}"), cancellationToken); + + ITeamsContext teamsContext = turnContext.TurnState.Get(); + + + + string actualText = teamsContext.GetActivityTextWithoutMentions(); + if (actualText.Equals("Cards", StringComparison.OrdinalIgnoreCase)) + { + // Demo card 1 - adaptive card with bot bulder actions + AdaptiveCards.AdaptiveCard adaptiveCard = new AdaptiveCards.AdaptiveCard(); + adaptiveCard.Body.Add(new AdaptiveCards.AdaptiveTextBlock("Bot Builder actions")); + + var action1 = new CardAction("imback", "imBack", null, null, null, "text"); + var action2 = new CardAction("messageBack", "message back", null, "text received by bots", "text display to users", JObject.Parse(@"{ ""key"" : ""value"" }")); + var action3 = new CardAction("invoke", "invoke", null, null, null, JObject.Parse(@"{ ""key"" : ""value"" }")); + adaptiveCard.Actions.Add(action1.ToAdaptiveCardAction()); + adaptiveCard.Actions.Add(action2.ToAdaptiveCardAction()); + adaptiveCard.Actions.Add(action3.ToAdaptiveCardAction()); + + // Task module action + var taskModuleAction = new TaskModuleAction("Launch Task Module", @"{ ""hiddenKey"": ""hidden value from task module launcher"" }"); + + // Demo card 2 - launch task module from adaptive card + AdaptiveCards.AdaptiveCard taskModuleCard1 = new AdaptiveCards.AdaptiveCard(); + taskModuleCard1.Body.Add(new AdaptiveCards.AdaptiveTextBlock("Task Module Adaptive Card")); + taskModuleCard1.Actions.Add(taskModuleAction.ToAdaptiveCardAction()); + + // Demo card 3 - launch task module from hero card (or any bot-builder framework card) + HeroCard taskModuleCard2 = new HeroCard("Launch Task Module", null, null, null, new List { taskModuleAction }); + + + var replyActivity = MessageFactory.Attachment(new Attachment[] { adaptiveCard.ToAttachment(), taskModuleCard1.ToAttachment(), taskModuleCard2.ToAttachment() }); + + await turnContext.SendActivityAsync(replyActivity, cancellationToken); + } + else + { + await turnContext.SendActivityAsync(MessageFactory.Text($"You said: {turnContext.Activity.Text}"), cancellationToken); + } + } + } +} diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Controllers/BotController.cs b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Controllers/BotController.cs new file mode 100644 index 0000000000..35514d52ea --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Controllers/BotController.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Bot.Builder; +using Microsoft.Bot.Builder.Integration.AspNet.Core; + +namespace Microsoft.BotBuilderSamples.Controllers +{ + // This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot + // implementation at runtime. Multiple different IBot implementations running at different endpoints can be + // achieved by specifying a more specific type for the bot constructor argument. + [Route("api/messages")] + [ApiController] + public class BotController : ControllerBase + { + private readonly IBotFrameworkHttpAdapter Adapter; + private readonly IBot Bot; + + public BotController(IBotFrameworkHttpAdapter adapter, IBot bot) + { + Adapter = adapter; + Bot = bot; + } + + [HttpPost] + public async Task PostAsync() + { + // Delegate the processing of the HTTP POST to the adapter. + // The adapter will invoke the bot. + await Adapter.ProcessAsync(Request, Response, Bot); + } + } +} diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/MessagingExtensions.csproj b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/MessagingExtensions.csproj new file mode 100644 index 0000000000..10ba10ad5f --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/MessagingExtensions.csproj @@ -0,0 +1,24 @@ + + + + netcoreapp2.1 + latest + + + + + + + + + + + + + + + Always + + + + diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Program.cs b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Program.cs new file mode 100644 index 0000000000..8a3b6c4a16 --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Program.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.AspNetCore; +using Microsoft.AspNetCore.Hosting; + +namespace Microsoft.BotBuilderSamples +{ + public class Program + { + public static void Main(string[] args) + { + CreateWebHostBuilder(args).Build().Run(); + } + + public static IWebHostBuilder CreateWebHostBuilder(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup(); + } +} diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Properties/launchSettings.json b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Properties/launchSettings.json new file mode 100644 index 0000000000..0c45c8b745 --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:3978", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "EchoBot": { + "commandName": "Project", + "launchBrowser": true, + "applicationUrl": "https://localhost:3979;http://localhost:3978", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs new file mode 100644 index 0000000000..c8a8daea18 --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Bot.Builder; +using Microsoft.Bot.Builder.Integration.AspNet.Core; +using Microsoft.BotBuilderSamples.Bots; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; + +namespace Microsoft.BotBuilderSamples +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + + // Create the Bot Framework Adapter with error handling enabled. + services.AddSingleton(); + + // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. + services.AddTransient(); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseHsts(); + } + + app.UseDefaultFiles(); + app.UseStaticFiles(); + + //app.UseHttpsRedirection(); + app.UseMvc(); + } + } +} diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.png b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.png new file mode 100644 index 0000000000000000000000000000000000000000..48a2de13303e1e8a25f76391f4a34c7c4700fd3d GIT binary patch literal 1229 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGojKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCe1|JzX3_D&pSWuFnWfl{x;g|9jrEYf8Vqrkk2Ba|%ol3OT){=#|7ID~|e{ zODQ{kU&ME#@`*-tm%Tukt_gFr+`F?$dx9wg-jad`^gsMn2_%Kh%WH91&SjKq5 zgkdI|!exdOVgw@>>=!Tjnk6q)zV*T8$FdgRFYC{kQ7``NOcl@R(_%_8e5e0E;>v0G zEM9kb)2itgOTSfH7M=b3-S61B?PiazMdwXZwrS)^5UUS#HQjaoua5h_{Gx*_Zz|XK z$tf0mZ&=tpf2!!Q)!A_l&o_$g*|JM$VZa~F^0{x1T{=QFu*x$`=V%~jUW=G`iqqp=lquB-`P{Qjw`=zEu3cMc_x7m2f#9m}uoFBMMQ^+%cOL)F_)N@JZ}Axoxi1y= zeebq`y==e!nl+?cK-PhOec!3%|IupShHrcjW8sSt)F1>NW*{ zW%ljk2)nk%-}+F&?gi=7^$L#VeX3@kp%f{n}fR z`}uZK<*n9P0FDAnmg6up^SuS?}R_a&Dl z_uN7uFXnZ>jo1v$ws-o@_kDfmbpGdgp8x+j&vX9gJkRgBINI(OlmP$$LV!P_g&lg| z?Ol%(1OU4DB+S=(VQ*rCGy?-Li(=n#v(wKeu6cTnuQLOMcl8M$>1^1mqTHoU0U(|< zn=He{7Q5SP1%q7sln6@l2X$FEp7r%TK^=xDMbi@#V`IfVLiWk}+)^HXtlZCrTK_tg zq=^%;lN8af%biPZQaKs_Bh40MkP?nPl!iv-SJMOUea9}o@qcwFs#BLDxB0G$M>u@fjZnzpzwr&&dQ|MPr<1R~c zWAm+`n_3QS*R>`>TwB6F#$HuR{pfvP=9=I!;1UqLMN$R3)UP+pw3f-yz>7UEoxt2B zJK3K3{%bZmQEzz06Q6uGHLiq(_vg<8ZK*CuxpWSDbY-ZTj(%EfK5Oq>yRNaf3EcFw_E#r^d8Z_mD%37`a!vCts46jbyju# z&2l#JhyI_kEy4!zV-lh(S5BAH^21jLC~^hGv+q-^l8x|Qg*OtGJ-?(AEo$QD3z(IU zFh&XsL-8u|%innJFdIN5|?JMh)LHY%Wi{w15MoaTBF@*<^O+4VJ>n*{d{eMew>Y|%R?+v8D< zQY{)fhMfzMc0t~`=pi@p+1gqoFQOii$hm|l*S+a+Xc!3D`f@B}_q5P*Y(&_L!Vy>) z4^s8WCG%b;b18Hi;|AjL_UTb+QJgLVo2Dgch}#gYE8yA~!2@kMwVX|1p3aGk@DG)9 zwX0@Y4R6n*;+hSjf?4t}l8E{>gsqWsdx{^6QH(UXHA zTlVnt$we?Z*mkJ(s{1j#XHTudpy>>-Gzza$hc)gP{Ya}O6)W#Id=@a$Fy_@KqZyjn zc+X@@&C>lsT$zAZkKf=E{Inu_mX1v@Jn50Vo~Xwr{8g9@v8#&A8D)>JS1!`Vh;WGL zx0(+Kd3G;QEof)kjwwJI&rOm2E8bM%uo6P8L!w1988LLJ} zPH2}C1Ijq~*KN&ON&uMMj6`Qn81}CER`IzE@-;-3IG6h{GKJw?^*s= z1ANflxL{3R95$fR+1_tNOR{d?n(`B5Wd3v)nt}>i+!u5B**Tv`5I$kL*RANfaNLq= zEN3NI<6FUbb>`=~LJo5*HD$J!F>UUYL{1EObtA$#DIK>LyYT*=RF1Ca!vmeZUq+-} zyNDB@o*d~A4|A!3{ck@;*8Xd7eYBG!r*%MHrKE%6tZI&L5Eu#xv9v)Zx)8y~*-cPWK$<x?;El(y z5LMx5wQ{c>^uQ{Z_wMm6!I{C6xU>&1LJfcMVCdgutZ6c;%p!qD_v_Tac zd=f?kE&<@@nq>RTvMeXWKySxIq;ldAPDhV2TE;4kGCif!?j)EGk%{Q3*s=6TU-&sB z%p_yCJ5RixD{pCLJXm-z!rJs-!+a0}BkNs=X8ZpMvj32}+EM&|@C0Cw|F L0bjZb?Y#a0M$S#< literal 0 HcmV?d00001 diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/manifest.json b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/manifest.json new file mode 100644 index 0000000000..a3467dff14 --- /dev/null +++ b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/manifest.json @@ -0,0 +1,42 @@ +{ + "$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.3/MicrosoftTeams.schema.json", + "manifestVersion": "1.3", + "version": "1.0.0", + "id": "528d4825-cca3-420a-bb88-712fbf54e6ca", + "packageName": "com.teams.sample.echobot", + "developer": { + "name": "Add & Remove Bot", + "websiteUrl": "https://www.microsoft.com", + "privacyUrl": "https://www.teams.com/privacy", + "termsOfUseUrl": "https://www.teams.com/termsofuser" + }, + "icons": { + "color": "color.png", + "outline": "outline.png" + }, + "name": { + "short": "Team Member Add & Remove", + "full": "Team Member Add & Remove" + }, + "description": { + "short": "Team Member Add & Remove", + "full": "Team Member Add & Remove" + }, + "accentColor": "#FFFFFF", + "bots": [ + { + "botId": "528d4825-cca3-420a-bb88-712fbf54e6ca", + "scopes": [ + "groupchat", + "team" + ], + "supportsFiles": false, + "isNotificationOnly": false + } + ], + "permissions": [ + "identity", + "messageTeamMembers" + ], + "validDomains": [] +} \ No newline at end of file diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/outline.png b/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/outline.png new file mode 100644 index 0000000000000000000000000000000000000000..dbfa9277299d36542af02499e06e3340bc538fe7 GIT binary patch literal 383 zcmV-_0f7FAP)Px$IY~r8R5%gMlrc`jP!L3IloKFoq~sFFH5|cdklX=R08T)}71BhaN8$`AsNf0_ zq>WNhAtCd|-nBlTU=y5zl_vXlXZ~bkuaYENMp>3QSQ_#zuYZ+eQh*OIHRxP~s(}ic zN2J4$u=AQcPt)|>F3zZLsjtP;Tajkugx;NcYED2~JVBlVO>{`uAY?Q4O|AA z=16}CJieK^5P_TKnou!zGR`$!PUC)DqtkO;?!`p!+9v3lP_mu=%Vt3BkoWsq%;FN1sp58w*zfr-z^7tIb*q>!yncCjrzLuOk3N+d&~^Cxd| z + + + + + + EchoBot + + + + + +
+
+
+
EchoBot
+
+
+
+
+
Your bot is ready!
+
You can test your bot in the Bot Framework Emulator
+ by connecting to http://localhost:3978/api/messages.
+ +
Visit Azure + Bot Service to register your bot and add it to
+ various channels. The bot's endpoint URL typically looks + like this:
+
https://your_bots_hostname/api/messages
+
+
+
+
+ +
+ + + diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln b/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln index abbc08f683..dede2bad5f 100644 --- a/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln +++ b/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln @@ -17,6 +17,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamsFileBot", "FileUpload\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roster", "Roster\Roster.csproj", "{AEE5C25E-74CC-48D9-815D-BE5C17D16737}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagingExtensions", "MessagingExtensions\MessagingExtensions.csproj", "{3A56D237-3AF4-441A-90AC-3021361EE38F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -51,6 +53,10 @@ Global {AEE5C25E-74CC-48D9-815D-BE5C17D16737}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEE5C25E-74CC-48D9-815D-BE5C17D16737}.Release|Any CPU.ActiveCfg = Release|Any CPU {AEE5C25E-74CC-48D9-815D-BE5C17D16737}.Release|Any CPU.Build.0 = Release|Any CPU + {3A56D237-3AF4-441A-90AC-3021361EE38F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A56D237-3AF4-441A-90AC-3021361EE38F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A56D237-3AF4-441A-90AC-3021361EE38F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A56D237-3AF4-441A-90AC-3021361EE38F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 4de881d16d50461f2c3b43c3adfb8c602228ed7b Mon Sep 17 00:00:00 2001 From: John Taylor Date: Fri, 6 Sep 2019 16:18:48 -0700 Subject: [PATCH 2/3] CardActions --- .../AdapterWithErrorHandler.cs | 0 .../Bots/CardActionsBot.cs} | 22 ++++++++++++++---- .../CardActions.csproj} | 0 .../Controllers/BotController.cs | 0 .../Program.cs | 0 .../Properties/launchSettings.json | 0 .../Startup.cs | 2 +- .../TeamsAppManifest/color.png | Bin .../TeamsAppManifest/color.zip | Bin .../TeamsAppManifest/manifest.json | 0 .../TeamsAppManifest/outline.png | Bin .../appsettings.Development.json | 0 .../appsettings.json | 0 .../wwwroot/default.html | 0 .../csharp-dotnetcore/Scenarios/Scenarios.sln | 10 ++++---- 15 files changed, 23 insertions(+), 11 deletions(-) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/AdapterWithErrorHandler.cs (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions/Bots/MessagingExtensionsBot.cs => CardActions/Bots/CardActionsBot.cs} (71%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions/MessagingExtensions.csproj => CardActions/CardActions.csproj} (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/Controllers/BotController.cs (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/Program.cs (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/Properties/launchSettings.json (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/Startup.cs (96%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/TeamsAppManifest/color.png (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/TeamsAppManifest/color.zip (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/TeamsAppManifest/manifest.json (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/TeamsAppManifest/outline.png (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/appsettings.Development.json (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/appsettings.json (100%) rename experimental/teams/csharp-dotnetcore/Scenarios/{MessagingExtensions => CardActions}/wwwroot/default.html (100%) diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/AdapterWithErrorHandler.cs b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/AdapterWithErrorHandler.cs similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/AdapterWithErrorHandler.cs rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/AdapterWithErrorHandler.cs diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Bots/CardActionsBot.cs similarity index 71% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Bots/CardActionsBot.cs index 5f847d17b8..c598470f53 100644 --- a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Bots/MessagingExtensionsBot.cs +++ b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Bots/CardActionsBot.cs @@ -6,22 +6,25 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Bot.Builder; -using Microsoft.Bot.Builder.Teams; +using Microsoft.Bot.Builder.Teams.Internal; +using Microsoft.Bot.Connector; +using Microsoft.Bot.Connector.Teams; using Microsoft.Bot.Schema; using Microsoft.Bot.Schema.Teams; using Newtonsoft.Json.Linq; namespace Microsoft.BotBuilderSamples.Bots { - public class MessagingExtensionsBot : TeamsActivityHandler + public class CardActionsBot : TeamsActivityHandler { protected override async Task OnMessageActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) { //await turnContext.SendActivityAsync(MessageFactory.Text($"MessagingExtensions echo: {turnContext.Activity.Text}"), cancellationToken); - ITeamsContext teamsContext = turnContext.TurnState.Get(); - - + var connectorClient = turnContext.TurnState.Get(); + var teamsConnectorClient = new TeamsConnectorClient(connectorClient.Credentials); + teamsConnectorClient.BaseUri = new Uri(turnContext.Activity.ServiceUrl); + var teamsContext = new TeamsContext(turnContext, teamsConnectorClient); string actualText = teamsContext.GetActivityTextWithoutMentions(); if (actualText.Equals("Cards", StringComparison.OrdinalIgnoreCase)) @@ -33,9 +36,13 @@ protected override async Task OnMessageActivityAsync(ITurnContext OnInvokeActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) + { + return base.OnInvokeActivityAsync(turnContext, cancellationToken); + } } } diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/MessagingExtensions.csproj b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/CardActions.csproj similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/MessagingExtensions.csproj rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/CardActions.csproj diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Controllers/BotController.cs b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Controllers/BotController.cs similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Controllers/BotController.cs rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Controllers/BotController.cs diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Program.cs b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Program.cs similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Program.cs rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Program.cs diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Properties/launchSettings.json b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Properties/launchSettings.json similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Properties/launchSettings.json rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Properties/launchSettings.json diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Startup.cs similarity index 96% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Startup.cs index c8a8daea18..afdc83a2b5 100644 --- a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/Startup.cs +++ b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/Startup.cs @@ -30,7 +30,7 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton(); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. - services.AddTransient(); + services.AddTransient(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.png b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/color.png similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.png rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/color.png diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.zip b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/color.zip similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/color.zip rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/color.zip diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/manifest.json b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/manifest.json similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/manifest.json rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/manifest.json diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/outline.png b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/outline.png similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/TeamsAppManifest/outline.png rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/TeamsAppManifest/outline.png diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/appsettings.Development.json b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/appsettings.Development.json similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/appsettings.Development.json rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/appsettings.Development.json diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/appsettings.json b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/appsettings.json similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/appsettings.json rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/appsettings.json diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/wwwroot/default.html b/experimental/teams/csharp-dotnetcore/Scenarios/CardActions/wwwroot/default.html similarity index 100% rename from experimental/teams/csharp-dotnetcore/Scenarios/MessagingExtensions/wwwroot/default.html rename to experimental/teams/csharp-dotnetcore/Scenarios/CardActions/wwwroot/default.html diff --git a/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln b/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln index dede2bad5f..27b25fd1f1 100644 --- a/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln +++ b/experimental/teams/csharp-dotnetcore/Scenarios/Scenarios.sln @@ -17,7 +17,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TeamsFileBot", "FileUpload\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roster", "Roster\Roster.csproj", "{AEE5C25E-74CC-48D9-815D-BE5C17D16737}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagingExtensions", "MessagingExtensions\MessagingExtensions.csproj", "{3A56D237-3AF4-441A-90AC-3021361EE38F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CardActions", "CardActions\CardActions.csproj", "{8A654F21-A762-4317-963E-8F112758C9A8}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -53,10 +53,10 @@ Global {AEE5C25E-74CC-48D9-815D-BE5C17D16737}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEE5C25E-74CC-48D9-815D-BE5C17D16737}.Release|Any CPU.ActiveCfg = Release|Any CPU {AEE5C25E-74CC-48D9-815D-BE5C17D16737}.Release|Any CPU.Build.0 = Release|Any CPU - {3A56D237-3AF4-441A-90AC-3021361EE38F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3A56D237-3AF4-441A-90AC-3021361EE38F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3A56D237-3AF4-441A-90AC-3021361EE38F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3A56D237-3AF4-441A-90AC-3021361EE38F}.Release|Any CPU.Build.0 = Release|Any CPU + {8A654F21-A762-4317-963E-8F112758C9A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8A654F21-A762-4317-963E-8F112758C9A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8A654F21-A762-4317-963E-8F112758C9A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8A654F21-A762-4317-963E-8F112758C9A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 9e66c1df0a91a7170f243ddbecd4bf42351f2e8c Mon Sep 17 00:00:00 2001 From: John Taylor Date: Fri, 6 Sep 2019 16:19:29 -0700 Subject: [PATCH 3/3] CardActions teamsactivity --- .../TeamsActivityHandler.cs | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/TeamsActivityHandler.cs b/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/TeamsActivityHandler.cs index 6b8259a75d..6b5fc495f8 100644 --- a/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/TeamsActivityHandler.cs +++ b/experimental/teams/csharp-dotnetcore/Microsoft.Bot.Builder.Teams/TeamsActivityHandler.cs @@ -49,40 +49,52 @@ public class TeamsActivityHandler : ActivityHandler protected virtual Task OnInvokeActivityAsync(ITurnContext turnContext, CancellationToken cancellationToken) { - switch (turnContext.Activity.Name) + if (turnContext.Activity.Name == null) { - case "signin/verifyState": - return OnSigninVerifyStateAsync(turnContext, cancellationToken); + return OnCardActionInvokeAsync(turnContext, cancellationToken); + } + else + { + switch (turnContext.Activity.Name) + { + case "signin/verifyState": + return OnSigninVerifyStateAsync(turnContext, cancellationToken); - case "fileConsent/invoke": - return OnFileConsent(turnContext, JObject.FromObject(turnContext.Activity.Value).ToObject(), cancellationToken); + case "fileConsent/invoke": + return OnFileConsent(turnContext, JObject.FromObject(turnContext.Activity.Value).ToObject(), cancellationToken); - case "composeExtension/query": - return OnMessagingExtensionQueryAsync(turnContext, JObject.FromObject(turnContext.Activity.Value).ToObject(), cancellationToken); + case "composeExtension/query": + return OnMessagingExtensionQueryAsync(turnContext, JObject.FromObject(turnContext.Activity.Value).ToObject(), cancellationToken); - case "actionableMessage/executeAction": - return OnO365ConnectorCardActionAsync(turnContext, cancellationToken); + case "actionableMessage/executeAction": + return OnO365ConnectorCardActionAsync(turnContext, cancellationToken); - case "composeExtension/queryLink": - return OnAppBasedLinkQueryAsync(turnContext, cancellationToken); + case "composeExtension/queryLink": + return OnAppBasedLinkQueryAsync(turnContext, cancellationToken); - case "composeExtension/fetchTask": - return OnMessagingExtensionFetchTaskAsync(turnContext, cancellationToken); + case "composeExtension/fetchTask": + return OnMessagingExtensionFetchTaskAsync(turnContext, cancellationToken); - case "composeExtension/submitAction": - return OnMessagingExtensionSubmitActionAsync(turnContext, cancellationToken); + case "composeExtension/submitAction": + return OnMessagingExtensionSubmitActionAsync(turnContext, cancellationToken); - case "task/fetch": - return OnTaskModuleFetchAsync(turnContext, cancellationToken); + case "task/fetch": + return OnTaskModuleFetchAsync(turnContext, cancellationToken); - case "task/submit": - return OnTaskModuleSubmitAsync(turnContext, cancellationToken); + case "task/submit": + return OnTaskModuleSubmitAsync(turnContext, cancellationToken); - default: - return Task.FromResult(null); + default: + return Task.FromResult(null); + } } } + protected virtual Task OnCardActionInvokeAsync(ITurnContext turnContext, CancellationToken cancellationToken) + { + return Task.FromResult(null); + } + protected virtual Task OnSigninVerifyStateAsync(ITurnContext turnContext, CancellationToken cancellationToken) { return Task.FromResult(null);