Teams Connector - Hardcoded URL issue
PR3R00T opened this issue · comments
Notify version:
1.0.2
Current Behavior:
While not fully documented I am looking to use the Teams provider. I read the code and saw a couple of parameters are required including the teams webhook url and message format.
The webhook I have been generated is for a corporate enviroment and is formatted as: Company.webhook.office.com/Webhook_details...
However, the MS teams connection code is currently configured with a hardcoded URL to be: https://outlook.office.com/webhook/. This is causing an issue as companies with corporate MS Teams that are unable to use this plugin and are having to resort to a custom connector configuration. This code is found under "notify/pkg/providers/teams/teams.go"
If anyone else is reading this and is looking for the custom connector code for teams as a work around please see below and add into the provider-config.yaml:
custom:
- id: webhook
custom_webhook_url: "YOUR TEAMS WEBHOOK URL"
custom_method: POST
custom_format: '{"text": "{{data}}"}'
custom_headers:
Content-Type: application/json
Expected Behavior:
I expected the MS Teams connector to parse the Full webhook url and send the MS Teams message. This can be parsed through the existing "teams_webhook_url" parameter.
Steps To Reproduce:
Please see the teams.go file and see line 41.
Anything else:
Hello! I once had the same issue but I managed to figure out what was going on and made a fix that works for me. I never made a PR because I was quite busy at the time and forgot about it but the general gist of it is as follows from memory:
- For sending info to teams web hooks Notify utilises the shoutrrr library as we can see in the go.mod
- The version in use with notify is v0.4.5-0.20220522113502-c91dc3cf1279 whereas the library has already moved onto v0.6+ as we can see from their releases
- From the shoutrrr v0.5 docs on sending messages to Teams web hooks there is a warning on how the format for Teams web hooks have changed:
That is basically the source of the problem, so I managed to resolve it for myself by changing the version of shoutrrr in use to be v0.5+ and then changing the Send function in pkg/providers/teams/teams.go to be the following:
func (p *Provider) Send(message, CliFormat string) error {
var TeamsErr error
for _, pr := range p.Teams {
msg := utils.FormatMessage(message, utils.SelectFormat(CliFormat, pr.TeamsFormat))
teamsTokens := strings.TrimPrefix(pr.TeamsWebHookURL, "https://<domain>.webhook.office.com/webhookb2/")
teamsTokens = strings.ReplaceAll(teamsTokens, "IncomingWebhook/", "")
url := fmt.Sprintf("teams://%s?host=<domain>.webhook.office.com", teamsTokens)
err := shoutrrr.Send(url, msg)
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("failed to send teams notification for id: %s ", pr.ID))
TeamsErr = multierr.Append(TeamsErr, err)
continue
}
gologger.Verbose().Msgf("teams notification sent for id: %s", pr.ID)
}
return TeamsErr
}
You will need to replace with the domain that your Corporate MS Teams uses for it to work.
My provider-config.yaml looked like the following:
teams:
- id: '<id>'
teams_webhook_url: 'https://<domain>.webhook.office.com/webhookb2/....'
teams_format: '{{data}}'
I don't actually know Go so looking back on this I just didn't spend the time figuring out how to make it generic whilst I was busy. Also I do not know if the old Teams web hooks are still supported in some places 🤷♂️
Hopefully this is helpful in getting this resolved.
@LegendOfLynkle @PR3R00T this is now fixed in dev with #175
Example: #175 (review)