{"id":11173,"date":"2022-08-09T10:00:18","date_gmt":"2022-08-09T17:00:18","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/?p=11173"},"modified":"2022-08-18T10:28:10","modified_gmt":"2022-08-18T17:28:10","slug":"post-notifications-to-microsoft-teams-with-net-using-teams-toolkit-for-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/post-notifications-to-microsoft-teams-with-net-using-teams-toolkit-for-visual-studio\/","title":{"rendered":"Post notifications to Microsoft Teams with .NET using Teams Toolkit for Visual Studio, now generally available"},"content":{"rendered":"<p>Building and extending Microsoft Teams with apps can feel overwhelming. Or maybe you\u2019re just learning that it\u2019s possible to extend Teams with embedded UI content, custom search, and more.\u00a0 There\u2019s a lot to absorb around what Teams has to offer, and there are so many tools and technologies to help you build the right app. You might want to re-use what you\u2019re familiar with, and if you\u2019re anything like me, that\u2019s .NET and Visual Studio. Keep reading this article to learn how simple it is to get started building apps for Teams using Teams Toolkit for Visual Studio.<\/p>\n<h2>Get Teams Toolkit for Visual Studio, now generally available<\/h2>\n<p>We are thrilled to announce the generally availability of Teams Toolkit for Visual Studio! If you don\u2019t have it already, you need to <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/\">download and install Visual Studio 2022<\/a>. Once installed, modify your installation to include the ASP.NET web development workload and be sure to select the checkbox for <strong>Microsoft Teams development tools<\/strong> \u2013 that will add Teams Toolkit to Visual Studio. See the example below.<\/p>\n<h2><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture1.png\"><img decoding=\"async\" class=\"size-full wp-image-11184 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture1.png\" alt=\"Image showing Visual Studio enterprise selecting Microsoft Teams development tools\" width=\"936\" height=\"468\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture1.png 936w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture1-300x150.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture1-768x384.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/h2>\n<h2>Create your Microsoft Teams app project<\/h2>\n<p>After Teams Toolkit is installed, start by <strong>Creating a new project<\/strong> in Visual Studio 2022 and selecting the <strong>Microsoft Teams App<\/strong> project template.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11185\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture2.png\" alt=\"Microsoft Teams Toolkit creating a new project in Visual Studio 2022\" width=\"936\" height=\"600\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture2.png 936w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture2-300x192.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Picture2-768x492.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<p>After you name the project and select next, you have a few application types to choose from. You can always adjust your Teams app later to include other options, but these will help you start in the right direction for the solution you have in mind.<\/p>\n<p>For example, I want to post a message in a channel each day with my assigned GitHub issues, so I select the <strong>Notification Bot <\/strong>option with the <strong>Timer Trigger.<\/strong><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Time-trigger.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11187\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Time-trigger.png\" alt=\"Create a new Teams application with Timer Trigger\" width=\"936\" height=\"542\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Time-trigger.png 936w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Time-trigger-300x174.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Time-trigger-768x445.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Finish by selecting <strong>Create<\/strong>, and Visual Studio will load the solution.<\/p>\n<h2>Run and debug your app inside a Teams web client<\/h2>\n<p>At this point, only the solution is created. You still need to configure an app registration in the Teams organization in which you want to develop. Without the toolkit, you would need to navigate between the Teams Developer Portal, Azure Portal, and Bot Framework Portal to configure this app. You also need a way for Bot Framework (cloud resource) to communicate with your localhost project \u2013 typically done with a network tunneling solution. Currently, we recommend using ngrok. After you <a href=\"https:\/\/ngrok.com\/download\">download and install ngrok<\/a>, run <code>ngrok http 5130<\/code> to start the tunnel.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/ngrok-tunnel.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11180\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/ngrok-tunnel.png\" alt=\"Image of the installation of ngrok tunnel\" width=\"854\" height=\"400\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/ngrok-tunnel.png 854w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/ngrok-tunnel-300x141.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/ngrok-tunnel-768x360.png 768w\" sizes=\"(max-width: 854px) 100vw, 854px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Next, Teams Toolkit can help with the app registration and configuration between portals. Right-click on the <strong>Azure Function<\/strong> that was created and select the <strong>Teams Toolkit<\/strong> &gt; <strong>Prepare Teams App Dependencies<\/strong> menu item.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-app-dependencies.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11186\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-app-dependencies.png\" alt=\"Image of preparing Teams app dependencies\" width=\"801\" height=\"448\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-app-dependencies.png 801w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-app-dependencies-300x168.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Teams-app-dependencies-768x430.png 768w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>A dialog is displayed where you can decide which Teams organization this app will be developed in. Select the corresponding Microsoft 365 account for that organization. I\u2019m using my free <a href=\"https:\/\/developer.microsoft.com\/microsoft-365\/dev-program\">Microsoft 365 Developer Program<\/a> account to develop this app in a pre-configured, sandboxed Teams organization.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Microsoft-365-account.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11179\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Microsoft-365-account.png\" alt=\"Image of the Microsoft 365 account set up to create a Teams app\" width=\"534\" height=\"405\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Microsoft-365-account.png 534w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Microsoft-365-account-300x228.png 300w\" sizes=\"(max-width: 534px) 100vw, 534px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>After selecting or adding your Microsoft 365 account, select Continue. The <strong>Output <\/strong>&gt; <strong>Teams Toolkit<\/strong> window shows the progress of registering and configure the app.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/output-to-configure-your-app.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11183\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/output-to-configure-your-app.png\" alt=\"Image showing output with Teams Toolkit window\" width=\"923\" height=\"399\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/output-to-configure-your-app.png 923w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/output-to-configure-your-app-300x130.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/output-to-configure-your-app-768x332.png 768w\" sizes=\"(max-width: 923px) 100vw, 923px\" \/><\/a><\/p>\n<p>Now that the app is registered in my Teams organization and configured in Bot Framework, I can run and debug using the <strong>Debug<\/strong> &gt; <strong>Start Debugging<\/strong> menu or pressing the F5 key. Visual Studio will launch a browser that opens Teams with my app installation dialog.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11178\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications.png\" alt=\"GitHub notifications window launched from Visual Studio\" width=\"936\" height=\"688\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications.png 936w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-300x221.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-768x565.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Selecting the <strong>Add <\/strong>button will continue to add my app to Teams as a personal app \u2013 viewable only to me. I selected the Timer Trigger, which defaults to sending a notification every 30 seconds and can be customized.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-new-event.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11177\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-new-event.png\" alt=\"Adding your app to Teams as a personal app\" width=\"793\" height=\"372\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-new-event.png 793w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-new-event-300x141.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/GitHub-notifications-new-event-768x360.png 768w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Customize the data<\/h2>\n<p>Now that I have my notification posting where I want, I can customize what is displayed. I\u2019d like to show my assigned GitHub issues each morning as a reminder to triage them.<\/p>\n<p>There are three files I\u2019ve begun to customize, <code>NotifyTrigger.cs<\/code>, <code>NotificationDefault.json<\/code>, and <code>NotificationDefaultModel.cs<\/code>.<\/p>\n<p>In <code>NotifyTrigger.cs<\/code>, I\u2019m using octokit.net, a .NET library for interacting with the GitHub API to grab issues in a repository I want to monitor.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/notifytimetrigger-code.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11182\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/notifytimetrigger-code.png\" alt=\"notifytimetrigger code\" width=\"936\" height=\"552\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/notifytimetrigger-code.png 936w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/notifytimetrigger-code-300x177.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/notifytimetrigger-code-768x453.png 768w\" sizes=\"(max-width: 936px) 100vw, 936px\" \/><\/a><\/p>\n<p>The <code>NotificationDefault.json<\/code> file is an Adaptive Card, which creates the UI for the notification you saw earlier. I\u2019ve customized this so I can list each issue with a link to make it easy to triage.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/adaptive-cards-code.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11175\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/adaptive-cards-code.png\" alt=\"The NotificationDefault.json file is an Adaptive Card, which creates the UI for the notification \" width=\"644\" height=\"938\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/adaptive-cards-code.png 644w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/adaptive-cards-code-206x300.png 206w\" sizes=\"(max-width: 644px) 100vw, 644px\" \/><\/a><\/p>\n<p>Next, I modified the <code>NotificationDefaultModel.cs<\/code> to match my new Adaptive Card definition. This makes it nice to work with in C# and easily bind the values and data.<\/p>\n<p>&nbsp;<\/p>\n<p>I can modify the cadence of this notification by changing the <code>TimerTrigger<\/code> attribute in NotifyTimerTrigger.cs.<\/p>\n<p><code>public async Task Run([TimerTrigger(\"0 0 7 * * *\")]<\/code><\/p>\n<p>Now when I run my app again, I see my customized notification showing that I have two assigned issues in this repository!<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Customized-notification-in-two-repositories.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-11176\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Customized-notification-in-two-repositories.png\" alt=\"Customized notification in two repositories\" width=\"572\" height=\"281\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Customized-notification-in-two-repositories.png 572w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2022\/08\/Customized-notification-in-two-repositories-300x147.png 300w\" sizes=\"(max-width: 572px) 100vw, 572px\" \/><\/a><\/p>\n<h2>Create your notification<\/h2>\n<p>That\u2019s it! By following along, you\u2019ve seen all there is to creating a complete Teams application using .NET, Visual Studio, and Teams Toolkit.<\/p>\n<p>In just a few edits I was able to set up a daily reminder for my assigned GitHub issues and display it how I wanted. From here, you could further extend this and collect info from more repositories or make a totally different type of notification.<\/p>\n<h2>Resources<\/h2>\n<ul>\n<li>Get the <a href=\"https:\/\/github.com\/therealjohn\/TeamsToolkit-GitHubNotifications-Sample\" target=\"_blank\" rel=\"noopener\">GitHub code<\/a><\/li>\n<li><a href=\"https:\/\/developer.microsoft.com\/en-us\/microsoft-teams\" target=\"_blank\" rel=\"noopener\">Learn more about getting started with Microsoft Teams development<\/a><\/li>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/microsoftteams\/platform\/toolkit\/teams-toolkit-fundamentals\" target=\"_blank\" rel=\"noopener\">Teams Toolkit documentation<\/a><\/li>\n<\/ul>\n<p>I\u2019d love to hear what you\u2019re creating and how Teams Toolkit can help you build solutions \u2013 <a href=\"https:\/\/twitter.com\/jmillerdev\">reach out on Twitter<\/a> to chat so we can build better tools together!<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Building and extending Microsoft Teams with apps can feel overwhelming. Or maybe you\u2019re just learning that it\u2019s possible to extend Teams with embedded UI content, custom search, and more.\u00a0 There\u2019s a lot to absorb around what Teams has to offer, and there are so many tools and technologies to help you build the right app. [&hellip;]<\/p>\n","protected":false},"author":97712,"featured_media":11201,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[8,128],"tags":[23,55,44],"class_list":["post-11173","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-adaptive-cards","category-microsoft-teams","tag-teams-toolkit","tag-visual-studio","tag-visual-studio-code"],"acf":[],"blog_post_summary":"<p>Building and extending Microsoft Teams with apps can feel overwhelming. Or maybe you\u2019re just learning that it\u2019s possible to extend Teams with embedded UI content, custom search, and more.\u00a0 There\u2019s a lot to absorb around what Teams has to offer, and there are so many tools and technologies to help you build the right app. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/11173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/97712"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=11173"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/11173\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/11201"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=11173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=11173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=11173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}