使用 slackbot 发出经过身份验证的请求

Make authenticated requests with a slackbot

我按照 Google Cloud 运行 页面上的教程进行操作,并创建了一个小型私有 Google Cloud 运行 API。现在我可以按照 here 所述使用 curl 向我的 API:

发出请求
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" SERVICE_URL

到目前为止一切顺利。现在我想构建一个 slackbot。 slackbot 应该响应 slashcommands,每当发出某个 slashcommand 时,它应该 1) 用 API 验证自己,然后 2) 发出命令。

这可能吗?我查看了整个 Slack API 文档,但没有找到 Slack Bot 必须通过其他服务对自己进行身份验证的示例。有人可以指点我 guide/tutorial 作者在 Google 云中实现私有 API 是从 slackbot 调用的吗?

这不可能。不要让 Slack 能够向您的 Cloud 运行 实例发出经过身份验证的请求,而是将其配置为 allow unauthenticated access 并通过验证中提供的 token 来验证来自 Slack 的事件是否有效请求。

这在 Slack 的 Event's API documentation:

中有描述

token: The shared-private callback token that authenticates this callback to the application as having come from Slack. Match this against what you were given when the subscription was created. If it does not match, do not process the event and discard it.