Sharepoint List Bot
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.
Interaction with app
Prerequisites
.NET Core SDK version 6.0
# determine dotnet version dotnet --version
Run the app (Using Microsoft 365 Agents Toolkit for Visual Studio)
The simplest way to run this sample in Teams is to use Microsoft 365 Agents Toolkit for Visual Studio.
- Install Visual Studio 2022 Version 17.14 or higher Visual Studio
- Install Microsoft 365 Agents Toolkit for Visual Studio Microsoft 365 Agents 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.
- Right-click the 'M365Agent' project in Solution Explorer and select Microsoft 365 Agents Toolkit > Select Microsoft 365 Account
- Sign in to Microsoft 365 Agents Toolkit with a Microsoft 365 work or school account
- Set
Startup Item
asMicrosoft Teams (browser)
. - Press F5, or select Debug > Start Debugging menu in Visual Studio to start your app
- In the opened web browser, select Add button to install the app in Teams
If you do not have permission to upload custom apps (uploading), Microsoft 365 Agents 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.
To try this sample
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
Step 1: Register a new app
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.Step 2: Know your Tenant ID and Resource ID
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
.
Step 3: Update your appSetting.json
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>>
Step 4: Grant permissions
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.
This steps is specific to Microsoft Teams
- 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
Interaction with the 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.
Screenshots
Upload the custom app in Teams
Interaction with the Bot
Ping the Bot
Further reading
- Conversational bots in teams
- Conversation Basics
- Granting Access using sharepoint app only
- Sharepoint using Application Context
- Sharepoint API basic operations