Microsoft Teams webhook on TFS

5.3k views Asked by At

I have discovered Microsoft Teams and I like it. I am now trying to trigger pullrequest messages from TFS to Microsoft Teams. I have a Teams Group webhook url that works fine with curl. But when I test it with TFS (Service Hooks -> Web Hooks) then I only get bad requests. Do any of you have an idea why that could be?

2

There are 2 answers

3
PatrickLu-MSFT On BEST ANSWER

If you are using VSTS, you could directly use the Connectors in Microsoft Teams to achieve what you need.

  1. Open the Connectors from Teams-General.
  2. Add Visual Studio Team Service

  3. Add related configuration such as blow picture enter image description here

  4. Create a pull request in related VSTS project, will get a message in Microsoft Teams

enter image description here

If you are using TFS, there is no related add-in for now. Seems you are using Incoming Webhook connector .

For Incoming Webhook, it's only support posts cards. More details about how that card is built, please refer this link: Actionable Messages Reference.

However, for Web Hooks in TFS, the sent JSON representation is not using the "card type". The sample JSON looks like below:

{
    "event.type": "git.push",
    ...
    "messsages": {
        "text": "...",
        "html": "...",
        "markdown": "..."
    },
    "detailedMesssages": {
        "text": "...",
        "html": "...",
        "markdown": "..."
    },
    "resource": {
        "id": "...",
        "url": "https://...",
        "name": "...",
        "field1:": "..."
    }
}

So you will get a fail message with bag request(400).

2
Ocherif ch On

Maybe you figure it out by now cause obviously the question was asked 3 years ago, but I wanted to post my answer in order to help other people in the future. There actually a way to hook TFS with Microsoft Teams yay!! From TFS go to Service Hooks --> office 365 instead of (Service Hooks -> Web Hooks) because "Microsoft teams" is part of the suite 365 and as easy as that :).

PS: Of course you need to create a channel on Teams first, then click on the 3 dots --> Connectors --> Incoming Webhooks(configure) --> give your hook a name --> Create. And you're done; just copy the link generated by Teams and past it in TFS when u're asked for it ;)