| page_type | sample | ||||
|---|---|---|---|---|---|
| description | Sample which demonstrates how to archive groupchat messages and send it to user as a file using bot. | ||||
| products |
|
||||
| languages |
|
||||
| extensions |
|
||||
| urlFragment | officedev-microsoft-teams-samples-bot-archive-groupchat-messages-csharp |
Using this C# sample, a bot can archive chat messages of groupchat and send it to user.
This feature shown in this sample is currently available in Public Developer Preview only.
- Teams SSO (bots)
- Adaptive Cards
- Graph API
-
.NET Core SDK version 6.0
determine dotnet version
dotnet --version
-
dev tunnel or Ngrok (For local environment testing) latest version (any other tunneling software can also be used)
-
Teams Microsoft Teams is installed and you have an account
-
Register a new application in the Microsoft Entra ID – App Registrations portal.
Enter the following to Click Expose An API Menu and add a scope details to configure the admin and user consent prompts with values that are appropriate for the access_as_user scope.
- Added the WebApplication Info Resource and Application ID URI in expose and API like: api://Tunnelbaseurl/App-id"
- Admin consent display name: Teams can access the user’s profile.
- Admin consent description: Teams can call the app’s web APIs as the current user.
- User consent display name: Teams can access your profile and make requests on your behalf.
- User consent description: Teams can call this app’s APIs with the same rights as you have.
-
In the Azure portal, select your resource group from the dashboard.
-
Select your bot channel registration link.
-
Open the resource page and select Configuration under Settings.
-
Select Add OAuth Connection Settings.
-
Complete the form as follows:
-
Name: Enter a name for the connection. You'll use this name in your bot in the appsettings.json file. For example BotTeamsAuthADv1.
-
Service Provider: Select Azure Active Directory V2. Once you select this, the Azure AD-specific fields will be displayed.
-
Client id: Enter the Application (client) ID .
-
Client secret: Enter the Application (client) secret.
-
Provide Scopes like "User.Read Chat.ReadWrite ChatMessage.Read"
- Select 'Accounts in any organizational directory (Any Azure AD directory - Multitenant)' under Supported account types and click "+Add a platform".
- On the flyout menu, Select "Web"
- Add
https://token.botframework.com/.auth/web/redirectunder Redirect URLs and click Configure button. - Once the flyout menu close, scroll bottom to section 'Implicit Grant' and select check boxes "Access tokens" and "ID tokens" and click "Save" at the top bar.
-
Setup for Bot
- Also, register a bot with Azure Bot Service, following the instructions here
- Ensure that you've enabled the Teams Channel
- While registering the bot, use
https://<your_tunnel_domain>/api/messagesas the messaging endpoint.
NOTE: When you create your app registration, you will create an App ID and App password - make sure you keep these for later.
-
Setup NGROK
-
Run ngrok - point to port 3978
ngrok http 3978 --host-header="localhost:3978"Alternatively, you can also use the
dev tunnels. Please follow Create and host a dev tunnel and host the tunnel with anonymous user access command as shown below:devtunnel host -p 3978 --allow-anonymous
- Setup for code
-
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
-
Modify the
/appsettings.jsonand fill in the following details: -
{{MICROSOFT-APP-ID}}- Generated from Step 1 while doing Microsoft Entra ID app registration in Azure portal. -
{{ MICROSOFT-APP-PASSWORD}}- Generated from Step 1, also referred to as Client secret -
{{ Connection Name }}- Generated from Step 1, also referred as Instruction on setting connection. -
From a terminal, navigate to
samples/bot-archive-groupchat-messages/csharp# run the bot dotnet runOr from Visual Studio - Launch Visual Studio - File -> Open -> Project/Solution - Navigate to
bot-archive-groupchat-messages/csharpfolder - SelectFetchGroupChatMessages.slnfile - PressF5to run the project
- Setup Manifest for Teams
-
This step is specific to Teams.
-
Edit the
manifest.jsoncontained in the ./AppManifest folder to replace your Microsoft App Id (that was created when you registered your app registration earlier) everywhere you see the place holder string{{Microsoft-App-Id}}(depending on the scenario the Microsoft App Id may occur multiple times in themanifest.json) -
Edit the
manifest.jsonforvalidDomainsand replace{{domain-name}}with base Url of your domain. E.g. if you are using ngrok it would behttps://1234.ngrok-free.appthen your domain-name will be1234.ngrok-free.app. -
Edit the
manifest.jsonfor"webApplicationInfo"resource"api://botid-<<MICROSOFT-APP-ID>>"with base Url of your domain. E.g. if you are using ngrok it would behttps://1234.ngrok-free.appthen your resource will beapi://botid-<<MICROSOFT-APP-ID>>.- Zip up the contents of the
AppManifestfolder to create amanifest.zip(Make sure that zip file does not contains any subfolder otherwise you will get error while uploading your .zip package)
- Zip up the contents of the
-
-
Upload the manifest.zip to Teams (in the Apps view click "Upload a custom app")
- Go to Microsoft Teams. From the lower left corner, select Apps
- From the lower left corner, choose Upload a custom App
- Go to your project directory, the ./AppManifest folder, select the zip folder, and choose Open.
- Select Add in the pop-up dialog box. Your app is uploaded to Teams.
-
Note: If you are facing any issue in your app, please uncomment this line and put your debugger for local debug.
- Sending archive chat messages text file of a groupchat to user
Select a groupchat and add the bot to chat.
Send getchat message to the bot, you will recieve a consent card by the bot in your personal scope.
To learn more about deploying a bot to Azure, see Deploy your bot to Azure for a complete list of deployment instructions.





