page_type | description | products | languages | extensions | urlFragment | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
This Teams bot collects user input via adaptive cards and saves it to a SharePoint list. |
|
|
|
officedev-microsoft-teams-samples-bot-sharepoint-list-csharp |
Bot Framework v4 SPListBot sample.
This bot has been created using Bot Framework, This Microsoft Teams bot sample demonstrates how to capture user input through adaptive cards and store it in a SharePoint list. Built on the Bot Framework, it offers a seamless way to manage data directly from the Teams interface. The setup includes SharePoint registration, permissions configuration, and deployment in Teams, allowing easy integration and data handling within your Teams environment.
-
.NET Core SDK version 6.0
# determine dotnet version dotnet --version
The simplest way to run this sample in Teams is to use Teams Toolkit for Visual Studio.
- Install Visual Studio 2022 Version 17.10 Preview 4 or higher Visual Studio
- Install Teams Toolkit for Visual Studio Teams Toolkit extension
- In the debug dropdown menu of Visual Studio, select Dev Tunnels > Create A Tunnel (set authentication type to Public) or select an existing public dev tunnel.
- In the debug dropdown menu of Visual Studio, select default startup project > Microsoft Teams (browser)
- In Visual Studio, right-click your TeamsApp project and Select Teams Toolkit > Prepare Teams App Dependencies
- Using the extension, sign in with your Microsoft 365 account where you have permissions to upload custom apps.
- Select Debug > Start Debugging or F5 to run the menu in Visual Studio.
- In the browser that launches, select the Add button to install the app to Teams.
If you do not have permission to upload custom apps (sideloading), Teams Toolkit will recommend creating and using a Microsoft 365 Developer Program account - a free program to get your own dev environment sandbox that includes Teams.
-
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
-
Run the bot from a terminal or from Visual Studio:
A) From a terminal, navigate to
samples/bot-sharepoint-list/csharp
folder# run the bot dotnet run
B) Or from Visual Studio
- Launch Visual Studio
- File -> Open -> Project/Solution
- Navigate to
samples/bot-sharepoint-list/csharp
folder - Select
SPListBot.csproj
file - Press
F5
to run the project
You need to register a new addin/app in your Sharepoint site, this will generate a ClientID and a Client Secret, which we will use to authenticate. Lets see how to do it.
Go to
_layouts/15/appregnew.aspx
under the SP Online site which you want to use as document repository.It is very important to know your tenant ID for triggering any kind of service calls. You can get your Tenant ID, Resource Id by following below points:
- Navigate to
https//{SharePointDomain}/_layouts/15/appprincipals.aspx
- You will see Site Collection App Permissions under site settings.
- You can check your any App and get the Tenant Id and Resource Id from
App Identifier
. The part after "@" is yourtenant ID
and the part before @ isResource ID
.
MicrosoftAppId:
<<Your Microsoft Bot_Id>>
"MicrosoftAppPassword":
<<Your Microsoft Bot_Secret>>
"BaseUrl":
<<Bot_endpoint_url>>
"TenantID":
<<Sharepoint Tenant Id>>
"ResourceID":
<<SP_Resource_ID>>
"TenantName":
<<sahrepoint Tenant Name>>
"SiteName":
<<Shareppint site name>>
"ListName":
<<Custom list name which created at site>>
"AppClientID":
<<Custom Client App ID created at sharepoint App>>
"AppSecret":
<<App Secret Id for sharepoint App>>
New Client app has been created in SP Online site, now its time to decide what permissions this app should have on your site. You can grant Site collection, web or even at list level read or write permissions.
Go to
/_layouts/15/appinv.aspx
and serach with ClientID we generated earlier. The application will fetch all other details based on your ClientID.
- Navigate to
appPackage
folder - Select the
Manifest.json
and update it with yourYour Bot Id
- Now zip the manifest.json along with icons
- Go to teams and do
Upload a Custom App
- Add the Bot to Microsoft Teams
- Start the conversation with Bot
- Ping the bot in 1:1 or channel scope
- Bot will send an Adaptive card having two fields name and address.
- Enter the values in Adaptive Card and click on Save button.
- Bot will save the card data in SharePoint List.
Note: If you are facing any issue in your app, please uncomment this line and put your debugger for local debug.
Upload the custom app in Teams
Interaction with the Bot
Ping the Bot