{"id":10,"date":"2022-01-12T18:33:34","date_gmt":"2022-01-12T18:33:34","guid":{"rendered":"https:\/\/blogs.oregonstate.edu\/coucoulr\/?p=10"},"modified":"2022-01-12T18:37:56","modified_gmt":"2022-01-12T18:37:56","slug":"creating-a-microsoft-teams-bot-part-2-setup","status":"publish","type":"post","link":"https:\/\/blogs.oregonstate.edu\/coucoulr\/2022\/01\/12\/creating-a-microsoft-teams-bot-part-2-setup\/","title":{"rendered":"Creating a Microsoft Teams Bot &#8211; Part 2: Setup"},"content":{"rendered":"\n<p> This is the second post in a series of posts documenting the creation of BeaverHours, a Microsoft Teams bot which handles office hours queueing. <\/p>\n\n\n\n<p>With the decision to make a chatbot made, the next step was to find out how to create the bot and set up the appropriate development environment. Luckily, Microsoft makes quickly starting up a project for Microsoft Teams very convenient with the use of <a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=TeamsDevApp.ms-teams-vscode-extension\">Teams Toolkit<\/a>, an extension for Visual Studio Code which spins up preconfigured Teams projects much in the way of tools like <a href=\"https:\/\/create-react-app.dev\/\">Create React App<\/a>. After following the easy <a href=\"https:\/\/docs.microsoft.com\/en-us\/microsoftteams\/platform\/sbs-gs-javascript\">quick start tutorial in Microsoft&#8217;s docs<\/a>, we were able to generate a scaffolded Node.js app in TypeScript.<\/p>\n\n\n\n<p>While the Teams Toolkit makes it easy to get a project up and running and even provides a seamless way to run locally developed bots on test servers, it actually pulls together several services to get a development bot running on Teams. The core functionality is the bot itself, which, by inspection of the code, is simply a REST API wrapping some bot processing logic. The following code snippet makes this clear:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/ Create the bot that will handle incoming messages.\nconst bot = new TeamsBot();\n\n\/\/\u00a0Create\u00a0HTTP\u00a0server.\nconst\u00a0server\u00a0=\u00a0restify.createServer();\nserver.listen(process.env.port\u00a0||\u00a0process.env.PORT\u00a0||\u00a03978,\u00a0()\u00a0=&gt;\u00a0{\n  console.log(`\\nBot\u00a0Started,\u00a0${server.name}\u00a0listening\u00a0to\u00a0${server.url}`);\n});\n\n\/\/\u00a0Listen\u00a0for\u00a0incoming\u00a0requests.\nserver.post(\"\/api\/messages\",\u00a0async\u00a0(req,\u00a0res)\u00a0=&gt;\u00a0{\n\u00a0\u00a0await\u00a0adapter.processActivity(req,\u00a0res,\u00a0async\u00a0(context)\u00a0=&gt;\u00a0{\n\u00a0\u00a0\u00a0\u00a0await\u00a0bot.run(context);\n  });\n});<\/pre>\n\n\n\n<p>Teams Toolkit configures the development environment to deploy the bot locally to a Teams workspace by simply running the debugging workflow: in Visual Studio Code, that&#8217;s set off by pressing F5. In doing this, a series of actions is fired off, as evidenced by the resulting terminal windows which open, shown in the picture below.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/osu-wams-blogs-uploads.s3.amazonaws.com\/blogs.dir\/5205\/files\/2022\/01\/image-3.png\" alt=\"\" class=\"wp-image-12\" width=\"264\" height=\"89\" \/><figcaption>The Tasks which are run when debugging.<\/figcaption><\/figure><\/div>\n\n\n\n<p>These tasks, in sequential order, are starting <a href=\"https:\/\/ngrok.com\/\">ngrok<\/a>, which exposes a public endpoint to the REST server in the code snippet above, authorizing the bot to the target Microsoft Teams workspace, and starting the bot (i.e., server) itself.<\/p>\n\n\n\n<p>At this stage, it&#8217;s clear that the desired bot logic should be defined by altering the <code>TeamsBot<\/code> class, as the REST server is simply a wrapper for the <code>TeamsBot.run()<\/code> method. We&#8217;ll dive into that in the next installment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second post in a series of posts documenting the creation of BeaverHours, a Microsoft Teams bot which handles office hours queueing. With the decision to make a chatbot made, the next step was to find out how to create the bot and set up the appropriate development environment. Luckily, Microsoft makes quickly &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blogs.oregonstate.edu\/coucoulr\/2022\/01\/12\/creating-a-microsoft-teams-bot-part-2-setup\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Creating a Microsoft Teams Bot &#8211; Part 2: Setup&#8221;<\/span><\/a><\/p>\n","protected":false},"author":12039,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/users\/12039"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":3,"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"predecessor-version":[{"id":15,"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/posts\/10\/revisions\/15"}],"wp:attachment":[{"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.oregonstate.edu\/coucoulr\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}