Hi Prefect Community, I'm having issue on sending...
# ask-community
t
Hi Prefect Community, I'm having issue on sending notification to Microsoft Teams using webhook block & Automation. The generic Microsoft Teams block simply won't send anything, if I switch to the Custom Webhook block, it will send only headers but no content. This is really confusing, how should i make it work? I'm currently on Ver 3.1.11
b
Hi Tuoyi! How are you generating the webhook URL? Are you doing it through the workflows app?
t
Hi @Bianca Hoch, yes, i setup the webhook from the workflow component inside the Microsoft Teams.
I tested this webhook on postman, and the webhook itselfs works properly
the right branch basically print what's sent from the POST, and the prefect will send me something like this (i replaced the personal info with XXX)
{"headers":{"Accept":"*/*","Accept-Encoding":"gzip,deflate","Host":"XX-XX.XXX.logic.azure.com","Max-Forwards":"10","User-Agent":"Prefect,Notifications","X-ARR-LOG-ID":"9182042b-ac30-4469-bb86-1efc38f49a7b","CLIENT-IP":"XX.77.XX.2:52083","DISGUISED-HOST":"XXX.logic.azure.com","X-SITE-DEPLOYMENT-ID":"flowfe-prod-by-rp00-app-01","WAS-DEFAULT-HOSTNAME":"XXXXX.p.azurewebsites.net","X-Forwarded-Proto":"https","X-AppService-Proto":"https","X-ARR-SSL":"2048|256|CN=Microsoft Azure RSA TLS Issuing CA 08, O=Microsoft Corporation, C=US|CN=westus.logic.azure.com, O=Microsoft Corporation, L=Redmond, S=WA, C=US","X-Forwarded-TlsVersion":"1.3","X-Forwarded-For":"209.77.191.2:52083","X-Original-URL":"/workflows/XXXX/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=XXXXX","X-WAWS-Unencoded-URL":"/workflows/XXXX/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=XXXX","Content-Length":"0"}}
basically just the header, without content, especially the json part
b
Thanks for the context! Prefect's notification blocks are built on top of the apprise library. It looks like they added support for the new format of the MS teams webhook back in December, so it should work from what I gather. The new URL looks like this. Does the URL you configured in your blocks look similar?:
Copy code
<https://yourteam.webhook.office.com/webhookb2/{token_a}/IncomingWebhook/{token_b}/{token_c}/{token_d}>
Also, when attempting to send a notification using the MS Teams block, do you see any errors show up in the Prefect event feed in the UI? Anything indicating that the notification couldn't be sent?
t
@Bianca Hoch Hi Bianca, actually, the webhook assigned to me does not like any of the new or old webhook mentioned in your link.....i think those are all Microsoft 365 Connectors going to be deprecated, and Microsoft recommends to create webhook in the workflow instead https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook?tabs=newteams%2Cdotnet
my webhook is actually in below structure
https://<address>:<port>/workflows/<token1>/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=<token2>
and no, prefect didn't show error on the notification block.....the notification POST was sent successfully but just header
I reviewed the code section on
/src/prefect/blocks
/notifications.py/CustomWebhookNotificationBlock
I think the issue is the request_arg made in
request_args = self._build_request_args(body, subject)
are mostly not valid to be used in
await client.request(**request_args)
resulting only the method and URL those two arguments valid in the request while left the rest of the content not legit.
basically the subject and the body needs to be wrapped into the json argument in the httpx request function and so can be sent as json content. Besides, apply_values() does not make substitution to the template as expected.
you can reproduce the issue by running:
tt = CustomWebhookNotificationBlock(method='POST', url='<https://test.tst.ts>', name='test')
then`tt._build_request_args(body='Hi', subject='World')` the body and subject will not be appear in the argument returned
I made an ad hoc patch to this: https://github.com/PrefectHQ/prefect/pull/16870
b
Thank you for doing that, Tuoyi! Much appreciated.