{"id":28524956,"url":"https://github.com/microsoftgraph/msgraph-sample-botframework","last_synced_at":"2025-07-06T11:30:58.223Z","repository":{"id":44610048,"uuid":"292878795","full_name":"microsoftgraph/msgraph-sample-botframework","owner":"microsoftgraph","description":"This sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from Microsoft Bot Framework bots.","archived":false,"fork":false,"pushed_at":"2024-04-22T11:46:49.000Z","size":1134,"stargazers_count":6,"open_issues_count":4,"forks_count":6,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-04-24T06:31:58.628Z","etag":null,"topics":["bot-framework","devxsample","microsoft-graph"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microsoftgraph.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-04T15:09:53.000Z","updated_at":"2024-04-29T12:27:44.885Z","dependencies_parsed_at":"2024-04-15T12:27:34.342Z","dependency_job_id":"fd098562-6c52-4802-be00-3d6302a97eff","html_url":"https://github.com/microsoftgraph/msgraph-sample-botframework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoftgraph%2Fmsgraph-sample-botframework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoftgraph%2Fmsgraph-sample-botframework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoftgraph%2Fmsgraph-sample-botframework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoftgraph%2Fmsgraph-sample-botframework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microsoftgraph","download_url":"https://codeload.github.com/microsoftgraph/msgraph-sample-botframework/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microsoftgraph%2Fmsgraph-sample-botframework/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258866230,"owners_count":22769971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot-framework","devxsample","microsoft-graph"],"created_at":"2025-06-09T11:12:28.415Z","updated_at":"2025-07-06T11:30:58.217Z","avatar_url":"https://github.com/microsoftgraph.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\npage_type: sample\ndescription: This sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from Bot Framework bots.\nproducts:\n- ms-graph\n- office-exchange-online\nlanguages:\n- csharp\n---\n\n# Microsoft Graph Bot Framework sample\n\n[![.NET](https://github.com/microsoftgraph/msgraph-training-botframework/actions/workflows/dotnet.yml/badge.svg)](https://github.com/microsoftgraph/msgraph-training-botframework/actions/workflows/dotnet.yml) ![License.](https://img.shields.io/badge/license-MIT-green.svg)\n\nThis sample demonstrates how to use the Microsoft Graph .NET SDK to access data in Office 365 from Microsoft Bot Framework bots.\n\n\u003e **NOTE:** This sample was originally built from a tutorial published on the [Microsoft Graph tutorials](https://docs.microsoft.com/graph/tutorials) page. That tutorial has been removed.\n\n## Prerequisites\n\nTo run the completed project in this folder, you need the following:\n\n- The [.NET Core SDK](https://dotnet.microsoft.com/download) 6.x installed on your development machine.\n- [Bot Framework Emulator](https://github.com/microsoft/BotFramework-Emulator)\n- [ngrok](https://ngrok.com/)\n- Either a personal Microsoft account with a mailbox on Outlook.com, or a Microsoft work or school account with an Exchange Online mailbox.\n- An Azure subscription and an account with the **Application developer**, **Application administrator**, **Cloud application administrator**, or **Global administrator** role.\n\nIf you don't have a Microsoft account, there are a couple of options to get a free account:\n\n- You can [sign up for a new personal Microsoft account](https://signup.live.com/signup?wa=wsignin1.0\u0026rpsnv=12\u0026ct=1454618383\u0026rver=6.4.6456.0\u0026wp=MBI_SSL_SHARED\u0026wreply=https://mail.live.com/default.aspx\u0026id=64855\u0026cbcxt=mai\u0026bk=1454618383\u0026uiflavor=web\u0026uaid=b213a65b4fdc484382b6622b3ecaa547\u0026mkt=E-US\u0026lc=1033\u0026lic=1).\n- You can [sign up for the Microsoft 365 Developer Program](https://developer.microsoft.com/microsoft-365/dev-program) to get a free Office 365 subscription.\n\nIf you don't have an Azure subscription, you can [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).\n\n## Create an Azure Bot in Azure portal\n\n1. Open a browser and navigate to the [Azure Portal](https://portal.azure.com). Login using the account associated with your Azure subscription.\n\n1. Select the upper-left menu, then select **Create a resource**.\n\n1. On the **New** page, search for `Azure Bot` and select **Azure Bot**.\n\n1. On the **Azure Bot** page, select **Create**.\n\n1. Fill in the required fields. The **Bot handle** field must be unique. Be sure to review the different pricing tiers and select what makes sense for your scenario. If this is just a learning exercise, you may want to select the free option.\n\n1. For **Type of App**, select **Multi Tenant**.\n\n1. For **Creation type**, select **Create new Microsoft App ID**.\n\n1. Select **Review + create**. Once validation completes, select **Create**.\n\n1. Once deployment has finished, select **Go to resource**.\n\n1. Under **Settings**, select **Configuration**. Select the **Manage** link next to **Microsoft App ID**.\n\n1. Select **New client secret**. Add a description and choose an expiration, then select **Add**.\n\n1. Copy the client secret value before you leave this page. You will need it in the following steps.\n\n    \u003e [!IMPORTANT]\n    \u003e This client secret is never shown again, so make sure you copy it now. You will need to enter this value in multiple places so keep it safe.\n\n1. Select **Overview** in the left-hand menu. Copy the value of the **Application (client) ID** and save it, you will need it in the following steps.\n\n### Create a web app registration\n\n1. Return to the home page of the Azure portal, then select **Azure Active Directory**.\n\n1. Select **App registrations**.\n\n1. Select **New registration**. On the **Register an application** page, set the values as follows.\n\n    - Set **Name** to `Graph Calendar Bot Auth`.\n    - Set **Supported account types** to **Accounts in any organizational directory and personal Microsoft accounts**.\n    - Under **Redirect URI**, set the first drop-down to `Web` and set the value to `https://token.botframework.com/.auth/web/redirect`.\n\n    \u003e **NOTE:** `https://token.botframework.com/.auth/web/redirect` is the default Bot Framework OAuth redirect URL for the public Azure cloud with no data residency requirements. Depending on your environment, you may need to use a different redirect URL. See [OAuth URL support in Azure Bot Service](https://docs.microsoft.com/azure/bot-service/ref-oauth-redirect-urls?view=azure-bot-service-4.0) for more information.\n\n1. Select **Register**. On the **Graph Calendar Bot Auth** page, copy the value of the **Application (client) ID** and save it, you will need it in the following steps.\n\n1. Select **Certificates \u0026 secrets** under **Manage**. Select the **New client secret** button. Enter a value in **Description** and select one of the options for **Expires** and select **Add**.\n\n1. Copy the client secret value before you leave this page. You will need it in the following steps.\n\n1. Select **API permissions**, then select **Add a permission**.\n\n1. Select **Microsoft Graph**, then select **Delegated permissions**.\n\n1. Select the following permissions, then select **Add permissions**.\n\n    - **openid**\n    - **profile**\n    - **Calendars.ReadWrite**\n    - **MailboxSettings.Read**\n\n## Configure the sample\n\n1. Create a new file in the **GraphCalendarBot** directory named **appsettings.Development.json** and add the following code.\n\n    ```json\n    {\n      \"MicrosoftAppId\": \"YOUR_BOT_APP_ID_HERE\",\n      \"MicrosoftAppPassword\": \"YOUR_BOT_PASSWORD_HERE\"\n    }\n    ```\n\n1. Replace `YOUR_BOT_APP_ID_HERE` with the **Application (client) ID** of your bot. (Step 13 of [Create an Azure Bot in Azure portal](#create-an-azure-bot-in-azure-portal))\n\n1. Replace `YOUR_BOT_PASSWORD_HERE` with the client secret of your bot. (Step 12 of [Create an Azure Bot in Azure portal](#create-an-azure-bot-in-azure-portal))\n\n## Running the sample\n\nYou can run this sample from your command-line interface (CLI), Visual Studio Code, or Visual Studio.\n\n### CLI\n\n1. In your CLI, navigate to the **GraphCalendarBot** directory.\n1. Run the bot with the following command.\n\n    ```bash\n    dotnet run\n    ```\n\n### Visual Studio Code\n\n1. In Visual Studio Code, select **File**, then **Open Folder...**.\n1. Browse to the folder where you cloned this repository and select **Select Folder**.\n1. Select **Run**, then **Start Debugging**. (or press **F5**)\n\n### Visual Studio\n\n1. Open the **GraphCalendarBot.csproj** file in Visual Studio.\n1. Press `F5` to run the project.\n\n## Testing the bot using Bot Framework Emulator\n\n1. Open the Bot Framework Emulator. Select the gear icon \u0026#9881; on the bottom left.\n\n1. Enter the local path to your installation of ngrok, and enable the **Bypass ngrok for local addresses** and **Run ngrok when the Emulator starts up** options.\n\n1. Enable the **Use a sign-in verification code for OAuthCards** option. Select **Save**.\n\n1. Select the **File** menu, then **New Bot Configuration...**.\n\n1. Fill in the fields as follows.\n\n    - **Bot name:** `CalendarBot`\n    - **Endpoint URL:** `http://localhost:3978/api/messages`\n    - **Microsoft App ID:** the application ID of your **Graph Calendar Bot** app registration\n    - **Microsoft App password:** your **Graph Calendar Bot** client secret\n    - **Encrypt keys stored in your bot configuration:** Enabled\n\n1. Select **Save and connect**. After the emulator connects, you should see `Welcome to Microsoft Graph CalendarBot. Type anything to get started.`\n\n1. Type some text and send it to the bot. The bot responds with a login prompt.\n\n1. Select the **Login** button. The emulator prompts you to confirm the URL that starts with `oauthlink://https://token.botframeworkcom`. Select **Confirm** to continue.\n\n1. In the pop-up window, login with your Microsoft 365 account. Review the requested permissions and accept.\n\n1. Once authentication and consent are complete, the pop-up window provides a validation code. Copy the code and close the window.\n\n1. Enter the validation code in the chat window to complete the login.\n\n1. Try the options presented by the bot after login.\n\n![A screenshot of the bot in Bot Framework Emulator](emulator.png)\n\n## Code of conduct\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n\n## Disclaimer\n\n**THIS CODE IS PROVIDED _AS IS_ WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoftgraph%2Fmsgraph-sample-botframework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrosoftgraph%2Fmsgraph-sample-botframework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrosoftgraph%2Fmsgraph-sample-botframework/lists"}