Slack API 事件订阅触发 Firebase Cloud Functions
Slack API Event Subscription to trigger Firebase Cloud Functions
目标
我希望 Slack 触发 Firebase Cloud Function。
示例:用户发送一条 Slack 消息,Firebase Cloud Functions 将部分消息写入 Firebase 数据库。
工具:Slack API\事件订阅、googleapis、nodejs 等
问题
Slack 文档 here 描述了质询响应要求。
Once you receive the event, respond in plaintext with the challenge
attribute value.
但是,我不确定如何让 Firebase 知道 Slack 请求已获得授权。对 Firebase Cloud Functions 的 HTTP 请求必须包含 Firebase ID。我已经让 googleapis 完成设置 Firebase ID 的工作,但我没有看到改变 Slack 的初始验证请求的方法(如果我有 ID 可以提供的话)
使用 Slack API 触发 Firebase 的最佳方式是什么?
使用 Slack 验证 Firebase URL 非常简单。
解决方案
Google Firebase 云函数
import * as functions from "firebase-functions";
export const helloSlack = functions.https.onRequest((request, response) => {
if (request) {
response.status(200).send(request.body);
} else {
console.log("Request Error...");
throw response.status(500);
}
});
步骤
- 部署您的 Firebase 云函数
- 转到https://api.slack.com/apps
- 您的应用 > 事件订阅 > 启用事件
- 开启事件
- 输入您的 Firebase 云函数 URL
tl;博士
松弛说明:
We’ll send HTTP POST requests to [your] URL when events occur. As soon
as you enter a URL, we’ll send a request with a challenge parameter,
and your endpoint must respond with the challenge value.
云函数URL:
https://firebase-slack-adaptor.cloudfunctions.net/helloSlack
为了应对验证挑战,请在 Slack 的请求 URL 字段中输入您的 Firebase Cloud Functions URL(上例)。
您的 Firebase Cloud Function 应该 return Slack 请求的 body
。 Slack 在 request.body
中找到它需要的东西并且应该验证你的 URL.
目标
我希望 Slack 触发 Firebase Cloud Function。
示例:用户发送一条 Slack 消息,Firebase Cloud Functions 将部分消息写入 Firebase 数据库。
工具:Slack API\事件订阅、googleapis、nodejs 等
问题
Slack 文档 here 描述了质询响应要求。
Once you receive the event, respond in plaintext with the challenge attribute value.
但是,我不确定如何让 Firebase 知道 Slack 请求已获得授权。对 Firebase Cloud Functions 的 HTTP 请求必须包含 Firebase ID。我已经让 googleapis 完成设置 Firebase ID 的工作,但我没有看到改变 Slack 的初始验证请求的方法(如果我有 ID 可以提供的话)
使用 Slack API 触发 Firebase 的最佳方式是什么?
使用 Slack 验证 Firebase URL 非常简单。
解决方案
Google Firebase 云函数
import * as functions from "firebase-functions";
export const helloSlack = functions.https.onRequest((request, response) => {
if (request) {
response.status(200).send(request.body);
} else {
console.log("Request Error...");
throw response.status(500);
}
});
步骤
- 部署您的 Firebase 云函数
- 转到https://api.slack.com/apps
- 您的应用 > 事件订阅 > 启用事件
- 开启事件
- 输入您的 Firebase 云函数 URL
tl;博士
松弛说明:
We’ll send HTTP POST requests to [your] URL when events occur. As soon as you enter a URL, we’ll send a request with a challenge parameter, and your endpoint must respond with the challenge value.
云函数URL:
https://firebase-slack-adaptor.cloudfunctions.net/helloSlack
为了应对验证挑战,请在 Slack 的请求 URL 字段中输入您的 Firebase Cloud Functions URL(上例)。
您的 Firebase Cloud Function 应该 return Slack 请求的 body
。 Slack 在 request.body
中找到它需要的东西并且应该验证你的 URL.