page_type | description | products | languages | extensions | urlFragment | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
This sample illustrates usage of incoming webhook. |
|
|
|
officedev-microsoft-teams-samples-incoming-webhook-csharp |
This sample demos UI to type in Incoming Webhook URL and message card payload, which send the card in the team also demonstrates the HttpPOST action in the card.
- HttpPOST action response
- Note: To see Post action please set target as
https://{{base-url}}/api/save
-
.NET Core SDK version 3.1
# determine dotnet version dotnet --version
-
Ngrok (For local environment testing) Latest (any other tunneling software can also be used)
# run ngrok locally ngrok http -host-header=localhost 3978
-
Teams Microsoft Teams is installed and you have an account
-
Create a incoming webhook. Create incoming webhooks. Keep this webhook URL handy while running the sample.
-
Clone the repository
git clone https://github.com/OfficeDev/Microsoft-Teams-Samples.git
-
In a terminal, navigate to
samples/incoming-webhook/csharp
# change into project folder cd # IncomingWebhook
-
Run ngrok - point to port 3978
# ngrok http -host-header=rewrite 3978
-
Modify the
manifest.json
in the/AppPackage
folder and replace the following details<<App-ID>>
with some unique GUID<<BASE-URL>>
with your application's base url, e.g. https://1234.ngrok.io<<VALID DOMAIN>>
with your app domain e.g. *.ngrok.io
-
Zip the contents of
AppPackage
folder into amanifest.zip
, and use themanifest.zip
to deploy in app store or add to Teams. -
Run the app from a terminal or from Visual Studio, choose option A or B.
A) From a terminal
# run the app
dotnet run
B) Or from Visual Studio
- Launch Visual Studio
- File -> Open -> Project/Solution
- Navigate to
IncomingWebhook
folder - Select
IncomingWebhook.csproj
file - Press
F5
to run the project
- 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 ./AppPackage folder, select the zip folder, and choose Open.
- Open Incoming webhook tab.
- Update webhook URL in
Enter webhook URL
input field and card payload inCard payload editor
. - Click on send button. You will get a card from webhook in the team where incoming webhook is added.