Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you respond immediately from an Azure Function PowerShell HTTP Trigger and then respond "out of band to another Url"?

I have a PowerShell HTTP trigger wired up to a Slack command. If the PS trigger responds in < 3 seconds all is good. I've got this working

If it takes longer, Slack requires two things, respond immediately and then respond out of band on the response_url.

This works. If I put a sleep 10 after the set-content, neither return and Slack says it timed out.

Is there way to accomplish this in PowerShell?

@"
{
  "response_type": "ephemeral",
   "text": "Checking $(get-date) ..."
}
"@ |  set-content $res -Encoding Ascii

The out of band works.

$b = @"
{
    "response_type": "in_channel",
    "text": "It's 80 degrees right now.",
    "attachments": [
        {
            "text":"Partly cloudy today and tomorrow"
        }
    ]
}
"@

Invoke-RestMethod $responseUrl -Method post -Body $b -ContentType "application/json"
like image 354
Doug Finke Avatar asked Oct 18 '22 11:10

Doug Finke


1 Answers

The right pattern of doing that in Azure Functions is to have your HTTP trigger function just push a message in a queue, then return immediately. Then have another Azure Function that's listening on that queue and then run your logic there.

like image 189
ahmelsayed Avatar answered Oct 20 '22 05:10

ahmelsayed