> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # Slack 어시스턴트 구축 이 가이드에서는 Slack의 메시지 및 멘션에 응답하는 Mastra Agent를 구축합니다. 채널 어댑터를 구성하고, 올바른 권한으로 Slack 앱을 설정하고, 웹후크를 통해 Agent에 연결하고, 상호 작용을 테스트하는 방법을 배우게 됩니다. ## 전제조건 - Node.js`v22.13.0` or later installed - 지원되는 API 키[Model Provider](https://mastra.zisheng.pro/ko/models) - 기존 Mastra 프로젝트. 따라가다[installation guide](https://mastra.zisheng.pro/ko/guides/getting-started/quickstart) if needed. - 에이[Slack workspace](https://slack.com/) where you can create apps ## Agent 만들기 Slack 어댑터를 설치합니다. **npm**: ```bash npm install @chat-adapter/slack ``` **pnpm**: ```bash pnpm add @chat-adapter/slack ``` **Yarn**: ```bash yarn add @chat-adapter/slack ``` **Bun**: ```bash bun add @chat-adapter/slack ``` 새 파일 만들기`src/mastra/agents/slack-agent.ts` and define your agent: ```ts import { Agent } from '@mastra/core/agent' import { createSlackAdapter } from '@chat-adapter/slack' export const slackAgent = new Agent({ id: 'slack-agent', name: 'Slack Agent', instructions: 'You are a helpful assistant. Answer questions, help with tasks, and have natural conversations.', model: 'anthropic/claude-opus-4-7', channels: { adapters: { slack: createSlackAdapter(), }, }, }) ``` 그만큼`channels` 속성은 Mastra가 각 adapter의 webhook endpoint를 생성하도록 합니다. 이 경우 Slack adapter가 이벤트 확인, 서명 검증 및 메시지 형식 지정을 자동으로 처리합니다. 귀하의 대리인을 등록하십시오.`src/mastra/index.ts` file: ```ts import { Mastra } from '@mastra/core' import { slackAgent } from './agents/slack-agent' export const mastra = new Mastra({ agents: { slackAgent }, }) ``` ## Slack 앱 만들기 Agent를 작업 공간에 연결하려면 Slack 앱이 필요합니다. 이동 and select **Create New App** > **From scratch**. Give it a name and select your workspace. 다음으로 이동**OAuth & Permissions** and scroll to **Bot Token Scopes**. Add the following scopes: - `app_mentions:read` - `channels:history` - `channels:read` - `chat:write` - `users:read` 상단에는**OAuth & Permissions**, select **Install to Workspace**. Copy the **Bot User OAuth Token** (`xoxb-...`). 이동**Basic Information** > **App Credentials** and copy the **Signing Secret** (e.g. `c3a4...`). 보장하다**Socket Mode** is turned **off** under **Settings** > **Socket Mode**. 자격 증명을`.env` file: ```bash SLACK_SIGNING_SECRET=your-signing-secret SLACK_BOT_TOKEN=xoxb-your-bot-token ``` 어댑터는 기본적으로 이러한 환경 변수를 읽습니다. 참조[Chat SDK Slack adapter docs](https://chat-sdk.dev/adapters/slack) for more details. ## 웹훅 연결 Slack은 웹훅을 통해 Agent에 이벤트를 전달합니다. Mastra는 각 채널 어댑터에 대해 이 끝점을 자동으로 생성합니다. 개발 서버를 시작합니다: **npm**: ```bash npm run dev ``` **pnpm**: ```bash pnpm run dev ``` **Yarn**: ```bash yarn dev ``` **Bun**: ```bash bun run dev ``` 로컬 개발 중에 Slack이 로컬 서버에 연결하려면 공개 URL이 필요합니다. 새 터미널을 열고 터널을 시작합니다. ```bash npx cloudflared tunnel --url http://localhost:4111 ``` 그러면 다음과 같은 임시 공개 URL이 출력됩니다.`https://triple-arms-solutions-kit.trycloudflare.com`. 터널을 다시 시작할 때마다 URL이 변경됩니다. Slack 앱 설정에서 다음으로 이동하세요.**Event Subscriptions** and toggle **Enable Events** to **On**. 설정**Request URL** 을 Agent webhook 경로가 포함된 터널 URL로 설정합니다: ```text https:///api/agents/slack-agent/channels/slack/webhook ``` Slack이 확인 요청을 보냅니다. 개발 서버가 실행 중인 경우 녹색 확인 표시로 응답합니다. 아래에**Subscribe to bot events**, add: - `app_mention` - `message.channels` 선택하다**Save Changes**. Slack에서는 이벤트 구독을 변경한 후 앱을 다시 설치해야 합니다. **OAuth & Permissions** and select **Reinstall to Workspace** to apply the updated permissions. > **노트:** 터널 URL은 로컬 개발 전용입니다. 당신이[deploy your application](https://mastra.zisheng.pro/ko/docs/deployment/overview), update the **Request URL** in your Slack app's **Event Subscriptions** to your production URL (e.g. `https://your-app.example.com/api/agents/slack-agent/channels/slack/webhook`). ## Agent 테스트 Slack으로 테스트하기 전에 다음에서 Agent의 동작을 개선할 수 있습니다.[Studio](https://mastra.zisheng.pro/ko/docs/studio/overview). Open 에서 Agent와 채팅하고 지침을 조정합니다. 응답이 어떻게 생성되는지 확인하려면 Trace를 살펴보세요. Agent의 응답이 만족스러우면 Slack 통합을 테스트하세요. Slack의 채널에 봇을 초대합니다. ```text /invite @your-bot-name ``` 채널에서 봇을 언급하세요. ```text @your-bot-name What can you help me with? ``` Agent는 스레드에서 응답합니다. 출력은 Model 및 지침에 따라 다를 수 있습니다. ## 다음 단계 이 Agent를 다음으로 확장할 수 있습니다. - [애플리케이션 배포](https://mastra.zisheng.pro/ko/docs/deployment/overview)Slack을 업데이트하고**Request URL** to your production endpoint - 여러 플랫폼에서 응답할 수 있도록 동일한 Agent에 더 많은 어댑터(Discord, Telegram)를 추가하세요. - 구성[multimodal content](https://mastra.zisheng.pro/ko/docs/capabilities/channels/overview) 을 사용해 Agent가 채팅에서 공유된 이미지, 동영상 및 오디오를 처리할 수 있도록 합니다 - 추가하다[tools](https://mastra.zisheng.pro/ko/docs/agents/using-tools) 을 사용해 Agent가 외부 API와 데이터에 접근할 수 있도록 합니다 자세히 알아보기: - [채널 개요](https://mastra.zisheng.pro/ko/docs/capabilities/channels/overview) - [사진관](https://mastra.zisheng.pro/ko/docs/studio/overview) - [배포 개요](https://mastra.zisheng.pro/ko/docs/deployment/overview) - [Chat SDK 어댑터 문서](https://chat-sdk.dev)