MSTeams-plugin does not support new webhook URL format
Closed this issue ยท 11 comments
๐ฃ Notification Service(s) Impacted
๐ Describe the bug
Microsoft is recommending everyone to update their connector URLs (https://learn.microsoft.com/nb-no/microsoftteams/m365-custom-connectors#update-connectors-url) in order to enhance security. Current version of Apprise 1.9.0 does not recognize the new connector URL as a parseable URL.
Old format currently supported by Apprise: https://{team-name}.office.com/webhook/{tokenA}/IncomingWebhook/{tokenB}/{tokenC}
New format not supported by Apprise: https://{team-name}.office.com/webhook/{tokenA}/IncomingWebhook/{tokenB}/{tokenC}/{tokenD}
According to this post, connectors with new URL will be valid until the end of 2025 so I believe this should be fixed in a future release.
๐ก Screenshots and Logs
Apprise 1.9.0:
import apprise
with apprise.LogCapture(level=apprise.logging.DEBUG) as output:
app = apprise.Apprise()
app.add(f"https://{team_name}.webhook.office.com/webhookb2/{tokenA}/IncomingWebhook/{tokenB}/{tokenC}/{tokenD}")
app.notify(title="title", body="test")
print(output.getvalue())
>> 2024-10-17 09:29:28,608 - DEBUG - Language set to en
>> 2024-10-17 09:29:28,609 - ERROR - Unparseable URL https://..../webhookb2/...../IncomingWebhook/...../...../.....
>> 2024-10-17 09:29:28,609 - ERROR - There are no service(s) to notify
However, I can verify that the URL is in fact valid:
import requests
import json
response = requests.post(
url=f"https://{team_name}.webhook.office.com/webhookb2/{tokenA}/IncomingWebhook/{tokenB}/{tokenC}/{tokenD}",
headers={
"Content-Type": "application/json"
},
data=json.dumps({"title": "title","text": "test"})
)
print(response.status_code)
>> 200
๐ป Your System Details:
- OS: Debian GNU/Linux 12
- Python Version: 3.10.15
๐ฎ Additional context
I would be glad to help if someone can point in the right direction.
+1 to this. Even though, Power Automate workflows is the way to go per the future of Microsoft, PA workflows don't support pushing to private channels yet, and the new 4-token Webhook format will be supported through the end of 2025. So to bridge that gap, it'd be nice to have Apprise support this. Otherwise, we lose ability to post to private channels via Webhooks using Apprise.
I will try to take a look at the code and offer a pull suggestion.
I would love a PR if you can help me out; been very busy with day job. I will otherwise try to investigate this when I can.
Ditto, I tried to take a quick peek at the code, made some initial progress but quickly realized I need to do dig into it more formally. Will attempt as time allows.
Did you get anywhere with this, @crscheid?
No not yet, and likely will not within the next month either.
Hi, I have no time to open a pull request ( at least today ) but I can hint the solution :
quite simply seems the fourth token is ignored in current parser :
apprise/plugins/msteams.py
results['token_b'] = None if not entries \
else NotifyMSTeams.unquote(entries.pop(0))
results['token_c'] = None if not entries \
else NotifyMSTeams.unquote(entries.pop(0))
# I added this two lines as a quick and dirty fix locally, ~ line 560
if len(entries):
results['token_c'] += f"/{NotifyMSTeams.unquote(entries.pop(0))}"
# it works, but for a legit pull request code should be aware a "token_d" exists.
# I'll try to find the time but can't guarantee, sorry
To avoid to use the new unsuported format by Apprise , I have not generated the urls with Incoming Webhook
. Instead, I have generated urls with the Webhook App in MS Teams. This generates a different url pattern that works with my current Apprise version (latest).
My MS Teams version is 24277.3507.3205.5228
.
@pepemonleon: Thanks for the tip. I was able to get this to work as well but unfortunately, this approach has a few drawbacks.
First, workflows posts as a USER to the channel which doesn't always meet the need depending on your use case.
Second, because the URL contains a query, it's not possible to also then pass a formatting ?template=
variable in the configuration via URL. ๐คจ
Hi @caronc , I'd like to submit a PR to try fixing this issue. What's the procedure?
Go for it๐๐. That would be amazing
Sorry, i missed the comment on the proceedure.
Chck out the source code and make the changes nessisary. All i ask is that you verify it is working. There is a docker container to test this with very easily:
# inside of your branch (root)
docker-compose run --rm test.py311 bash
# inside container:
bin/checkdone.sh
This was completed! Thank you very much @anothermwilson ๐