- 使用 ngrok,它可为在计算机上本地打开的端口创建外部可寻址 URL。
在 Slack 内创建 Ap
- 创建 Slack 工作区
创建一个新的Slack 应用程序:「Create New Ap」,选择 From scratch。
![%E6%88%AA%E5%B1%8F2024-02-26_15.51.48.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/db4af0d3-e94a-46be-9cff-379ac9db813e/%E6%88%AA%E5%B1%8F2024-02-26_15.51.48.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035835Z&X-Amz-Expires=3600&X-Amz-Signature=9b672eb0903b7a3fddb3478ff1645402252dc6ecb909649835bfe419c81d3367&X-Amz-SignedHeaders=host&x-id=GetObject)
设置应用程序的OAuth 和权限,点击左侧目录的「 OAuth & Permissions」 - 在Redirect URLs内添加新的重定向 url 用于应用安装和授权,重定向的 url 需要使用到你的 ngrok domain,如
puma-rational-rapidly.ngrok-free.app
。![%E6%88%AA%E5%B1%8F2024-02-26_16.11.24.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/94e302df-b0cc-4b7f-a852-bd0a43fee050/%E6%88%AA%E5%B1%8F2024-02-26_16.11.24.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035837Z&X-Amz-Expires=3600&X-Amz-Signature=1cd93eb40522e033757601535df56bfc0e85d48bd900a5e49aa0291af8f73c29&X-Amz-SignedHeaders=host&x-id=GetObject) - 在**Scopes**内设置应用程序的应用域 ![%E6%88%AA%E5%B1%8F2024-02-26_16.19.09.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/232da410-5c16-4a27-8ea9-801f9524a458/%E6%88%AA%E5%B1%8F2024-02-26_16.19.09.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035838Z&X-Amz-Expires=3600&X-Amz-Signature=6a724c48de64982155e82fd9247a23b678e6b52c74f811a7a50678bf630d5a4e&X-Amz-SignedHeaders=host&x-id=GetObject)
通过「Install Ap」→ 「Install to Workspace」将应用程序安装到我们的工作区,安装成功后获取到了SLACK_BOT_TOKEN(v1),后面会用到。
![%E6%88%AA%E5%B1%8F2024-02-26_16.34.34.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/7b928644-e0b7-470a-bf23-72f568db806f/%E6%88%AA%E5%B1%8F2024-02-26_16.34.34.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035839Z&X-Amz-Expires=3600&X-Amz-Signature=f65bf70bfc151050bd2b95990bb6e8dfea2d1f9fdfec8c683ee2d86b2681bb31&X-Amz-SignedHeaders=host&x-id=GetObject)
![%E6%88%AA%E5%B1%8F2024-02-26_16.40.03.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/4e2bb3fd-645f-42a9-bf86-b640b7aa8de6/%E6%88%AA%E5%B1%8F2024-02-26_16.40.03.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035839Z&X-Amz-Expires=3600&X-Amz-Signature=63ed7393f31a9f09fe1898cda5fb334998232060a5696bbafd0b951843258bde&X-Amz-SignedHeaders=host&x-id=GetObject)
- 进入应用程序的基本信息内获取基本的应用程序凭证:「Settings」→ 「**Basic Information」**,后续需要配置进环境变量
![%E6%88%AA%E5%B1%8F2024-02-26_16.52.06.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/a1b40867-90bd-4931-b610-c50e4de91521/%E6%88%AA%E5%B1%8F2024-02-26_16.52.06.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035839Z&X-Amz-Expires=3600&X-Amz-Signature=755ffa691dd1918174f009a2852094572d873af6a75bc5ec5dcc43560019b098&X-Amz-SignedHeaders=host&x-id=GetObject)
- 创建应用程序的斜杠命令,用于机器人监听对应的命令,创建时这里的**Request URL**要填你的`{ngrok domain}/slack/events` 。
![%E6%88%AA%E5%B1%8F2024-02-26_17.11.13.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/a0bdc100-d0e6-4660-8a91-9071d9d01779/047dd59b-5b61-4c72-8d49-119a33f11f96/%E6%88%AA%E5%B1%8F2024-02-26_17.11.13.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45HZZMZUHI%2F20240417%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20240417T035841Z&X-Amz-Expires=3600&X-Amz-Signature=13f4d93a089f683b04302655e125b38ff066c50753d29f5b16971ef225ea00d9&X-Amz-SignedHeaders=host&x-id=GetObject)