@mastra/slack 1.6.3-alpha.0 → 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -126
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,146 +1,38 @@
|
|
|
1
1
|
# @mastra/slack
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@mastra/slack` connects Mastra agents to Slack. It creates and configures Slack apps through the Manifest API, manages the OAuth installation flow, and routes Slack conversations to agents registered with Mastra.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
```
|
|
7
|
+
```bash
|
|
8
|
+
npm install @mastra/slack
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Set `SLACK_APP_CONFIG_REFRESH_TOKEN` to your Slack app configuration refresh token.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
8
16
|
import { Mastra } from '@mastra/core/mastra';
|
|
9
|
-
import { Agent } from '@mastra/core/agent';
|
|
10
17
|
import { SlackProvider } from '@mastra/slack';
|
|
11
18
|
|
|
12
|
-
const myAgent = new Agent({
|
|
13
|
-
id: 'my-agent',
|
|
14
|
-
name: 'My Agent',
|
|
15
|
-
model: 'openai/gpt-4.1',
|
|
16
|
-
instructions: 'You are a helpful assistant.',
|
|
17
|
-
});
|
|
18
|
-
|
|
19
19
|
const slack = new SlackProvider({
|
|
20
20
|
refreshToken: process.env.SLACK_APP_CONFIG_REFRESH_TOKEN,
|
|
21
|
-
// For local dev, set SLACK_BASE_URL to your tunnel URL
|
|
22
|
-
// In production, this is auto-derived from server config
|
|
23
|
-
baseUrl: process.env.SLACK_BASE_URL,
|
|
24
21
|
});
|
|
25
22
|
|
|
26
|
-
const mastra = new Mastra({
|
|
27
|
-
agents: { myAgent },
|
|
23
|
+
export const mastra = new Mastra({
|
|
28
24
|
channels: { slack },
|
|
29
25
|
});
|
|
30
|
-
|
|
31
|
-
// Or configure credentials later (e.g., from UI or vault)
|
|
32
|
-
// slack.configure({ refreshToken: 'xoxe-1-...' });
|
|
33
|
-
|
|
34
|
-
// Connect an agent to Slack (creates app, returns OAuth URL)
|
|
35
|
-
const { authorizationUrl } = await slack.connect('my-agent', {
|
|
36
|
-
name: 'My Bot',
|
|
37
|
-
description: 'An AI assistant',
|
|
38
|
-
iconUrl: 'https://example.com/my-bot-icon.png',
|
|
39
|
-
slashCommands: [
|
|
40
|
-
{ command: '/ask', prompt: 'Answer: {{text}}' },
|
|
41
|
-
{ command: '/help', prompt: 'List your capabilities.' },
|
|
42
|
-
],
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## Setup
|
|
47
|
-
|
|
48
|
-
1. **Get App Configuration Tokens** from https://api.slack.com/apps (look for "Your App Configuration Tokens" section)
|
|
49
|
-
|
|
50
|
-
2. **Set up a tunnel** for local development:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
cloudflared tunnel --url http://localhost:4111
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
3. **Add to .env**:
|
|
57
|
-
```
|
|
58
|
-
SLACK_APP_CONFIG_TOKEN=xoxe.xoxp-...
|
|
59
|
-
SLACK_APP_CONFIG_REFRESH_TOKEN=xoxe-1-...
|
|
60
|
-
SLACK_BASE_URL=https://abc123.trycloudflare.com
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
> ⚠️ **Token Rotation**: Slack config access tokens expire after 12 hours, but the refresh token does not expire (it's single-use — each rotation returns a new pair). Tokens auto-rotate and are persisted to storage, so the `.env` values are only used as the initial seed. If you lose your persisted storage (e.g., DB wipe), you'll need fresh tokens from the Slack dashboard.
|
|
64
|
-
|
|
65
|
-
## Storage & Persistence
|
|
66
|
-
|
|
67
|
-
`SlackProvider` automatically uses Mastra's storage if configured. Just add `storage` to your Mastra config:
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import { LibSQLStore } from '@mastra/libsql';
|
|
71
|
-
|
|
72
|
-
const mastra = new Mastra({
|
|
73
|
-
agents: { myAgent },
|
|
74
|
-
storage: new LibSQLStore({ url: 'file:./mastra.db' }),
|
|
75
|
-
channels: {
|
|
76
|
-
slack: new SlackProvider({
|
|
77
|
-
refreshToken: process.env.SLACK_APP_CONFIG_REFRESH_TOKEN!,
|
|
78
|
-
}),
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
26
|
```
|
|
82
27
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
- Persists rotated config tokens (so you don't need fresh tokens after restart)
|
|
86
|
-
- Persists Slack app installations
|
|
87
|
-
- Detects config changes (e.g., agent renames) and updates manifests on startup
|
|
88
|
-
|
|
89
|
-
Without storage, data is lost on restart and apps are recreated.
|
|
90
|
-
|
|
91
|
-
## How It Works
|
|
28
|
+
## Documentation
|
|
92
29
|
|
|
93
|
-
|
|
94
|
-
2. Call `slack.connect(agentId)` to provision a Slack app and get an OAuth URL
|
|
95
|
-
3. Visit the OAuth URL to install the app to your Slack workspace
|
|
96
|
-
4. After installation, messages and slash commands route to your agent
|
|
97
|
-
5. Config access tokens auto-rotate (they expire every 12 hours) and are saved to storage
|
|
98
|
-
|
|
99
|
-
## Slash Commands
|
|
100
|
-
|
|
101
|
-
Commands use prompt templates with variable substitution:
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
await slack.connect('my-agent', {
|
|
105
|
-
slashCommands: [
|
|
106
|
-
{
|
|
107
|
-
command: '/ask',
|
|
108
|
-
description: 'Ask the AI a question',
|
|
109
|
-
prompt: 'Answer this question: {{text}}',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
command: '/summarize',
|
|
113
|
-
description: 'Summarize content',
|
|
114
|
-
prompt: 'Summarize the following in 2-3 sentences: {{text}}',
|
|
115
|
-
},
|
|
116
|
-
],
|
|
117
|
-
});
|
|
118
|
-
```
|
|
30
|
+
- [Reference: SlackProvider](https://mastra.ai/reference/channels/slack-provider)
|
|
119
31
|
|
|
120
|
-
|
|
32
|
+
## Changelog
|
|
121
33
|
|
|
122
|
-
|
|
34
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/channels/slack/CHANGELOG.md) for version history and release notes.
|
|
123
35
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```ts
|
|
127
|
-
await slack.connect('my-agent', {
|
|
128
|
-
iconUrl: 'https://example.com/my-bot-avatar.png',
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
The image should be:
|
|
133
|
-
|
|
134
|
-
- Square (1:1 aspect ratio)
|
|
135
|
-
- At least 512x512 pixels
|
|
136
|
-
- PNG, JPG, or GIF format
|
|
137
|
-
|
|
138
|
-
The icon is uploaded automatically when the Slack app is created.
|
|
139
|
-
|
|
140
|
-
## Disconnecting
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
await slack.disconnect('my-agent');
|
|
144
|
-
```
|
|
36
|
+
## Support
|
|
145
37
|
|
|
146
|
-
|
|
38
|
+
We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/slack",
|
|
3
|
-
"version": "1.6.3
|
|
3
|
+
"version": "1.6.3",
|
|
4
4
|
"description": "Slack integration for Mastra agents with app factory, OAuth, and slash commands",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"typescript": "^7.0.2",
|
|
31
31
|
"vitest": "^4.1.10",
|
|
32
32
|
"zod": "^4.4.3",
|
|
33
|
-
"@mastra/core": "1.64.0
|
|
33
|
+
"@mastra/core": "1.64.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"@mastra/core": "^1.0.0"
|