如何从Azure Function PowerShell HTTP触发器立即响应,然后“带外响应另一个URL”?

Dou*_*nke 5 powershell azure azure-functions

我有一个连接到Slack命令的PowerShell HTTP触发器。如果PS触发器在<3秒内做出响应,则一切正常。我有这个工作

如果需要更长的时间,Slack需要做两件事,立即做出响应,然后在上进行带外响应response_url

这可行。如果我在sleep 10后面加上a set-content,则不会返回,Slack表示超时。

有没有办法在PowerShell中完成此任务?

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

带外作品。

$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"
Run Code Online (Sandbox Code Playgroud)

ahm*_*yed 3

在 Azure Functions 中执行此操作的正确模式是让 HTTP 触发器函数将消息推送到队列中,然后立即返回。然后让另一个 Azure Function 监听该队列,然后在那里运行您的逻辑。