我正在构建一个使用 Azure Functions 的自定义 slack 命令,问题是该作业需要超过 3 秒才能完成,这将触发自定义 slack 命令超时。
我的问题是,我如何以 200 状态回复 Slack 并触发我的工作以获得一些很酷的东西。
我正在使用“Slack.Webhooks”来向 slack 发送一条包含所有酷数据的单独消息。
这是我的代码:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Slack.Webhooks;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace WinRatio
{
public class GetMachines
{
[FunctionName("GetMachines")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestMessage req,
ILogger log)
{
var formData = await req.Content.ReadAsFormDataAsync();
req.CreateResponse(HttpStatusCode.OK);
Console.WriteLine(formData["text"]);
Console.WriteLine($"Response URL: '{formData["response_url"]}'");
MachineInstructions machineInstructions = new MachineInstructions();
machineInstructions.doCoolStuff();
var slackResponseHook = formData["response_url"];
var slackClient = new SlackClient(slackResponseHook);
var slackMessage = new SlackMessage
{
Text = "We found some Machines for you",
};
var slackAttachment = new SlackAttachment
{
Fallback = "Place down the street",
Text = $"Machine: {machineInstructions.Rooms[0]}",
};
slackMessage.Attachments = new List<SlackAttachment> { slackAttachment };
slackClient.Post(slackMessage);
return new OkResult();
}
}
}