@memberjunction/messaging-adapters 0.0.1 → 5.17.0
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 +231 -43
- package/dist/base/BaseMessagingAdapter.d.ts +428 -0
- package/dist/base/BaseMessagingAdapter.d.ts.map +1 -0
- package/dist/base/BaseMessagingAdapter.js +934 -0
- package/dist/base/BaseMessagingAdapter.js.map +1 -0
- package/dist/base/message-formatter.d.ts +70 -0
- package/dist/base/message-formatter.d.ts.map +1 -0
- package/dist/base/message-formatter.js +201 -0
- package/dist/base/message-formatter.js.map +1 -0
- package/dist/base/types.d.ts +211 -0
- package/dist/base/types.d.ts.map +1 -0
- package/dist/base/types.js +6 -0
- package/dist/base/types.js.map +1 -0
- package/dist/index.d.ts +72 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/slack/SlackAdapter.d.ts +141 -0
- package/dist/slack/SlackAdapter.d.ts.map +1 -0
- package/dist/slack/SlackAdapter.js +291 -0
- package/dist/slack/SlackAdapter.js.map +1 -0
- package/dist/slack/SlackMessagingExtension.d.ts +148 -0
- package/dist/slack/SlackMessagingExtension.d.ts.map +1 -0
- package/dist/slack/SlackMessagingExtension.js +433 -0
- package/dist/slack/SlackMessagingExtension.js.map +1 -0
- package/dist/slack/slack-block-builder.d.ts +133 -0
- package/dist/slack/slack-block-builder.d.ts.map +1 -0
- package/dist/slack/slack-block-builder.js +748 -0
- package/dist/slack/slack-block-builder.js.map +1 -0
- package/dist/slack/slack-formatter.d.ts +37 -0
- package/dist/slack/slack-formatter.d.ts.map +1 -0
- package/dist/slack/slack-formatter.js +116 -0
- package/dist/slack/slack-formatter.js.map +1 -0
- package/dist/slack/slack-interactivity.d.ts +38 -0
- package/dist/slack/slack-interactivity.d.ts.map +1 -0
- package/dist/slack/slack-interactivity.js +414 -0
- package/dist/slack/slack-interactivity.js.map +1 -0
- package/dist/slack/slack-routes.d.ts +35 -0
- package/dist/slack/slack-routes.d.ts.map +1 -0
- package/dist/slack/slack-routes.js +98 -0
- package/dist/slack/slack-routes.js.map +1 -0
- package/dist/teams/TeamsAdapter.d.ts +155 -0
- package/dist/teams/TeamsAdapter.d.ts.map +1 -0
- package/dist/teams/TeamsAdapter.js +383 -0
- package/dist/teams/TeamsAdapter.js.map +1 -0
- package/dist/teams/TeamsMessagingExtension.d.ts +75 -0
- package/dist/teams/TeamsMessagingExtension.d.ts.map +1 -0
- package/dist/teams/TeamsMessagingExtension.js +176 -0
- package/dist/teams/TeamsMessagingExtension.js.map +1 -0
- package/dist/teams/teams-card-builder.d.ts +94 -0
- package/dist/teams/teams-card-builder.d.ts.map +1 -0
- package/dist/teams/teams-card-builder.js +648 -0
- package/dist/teams/teams-card-builder.js.map +1 -0
- package/dist/teams/teams-formatter.d.ts +39 -0
- package/dist/teams/teams-formatter.d.ts.map +1 -0
- package/dist/teams/teams-formatter.js +107 -0
- package/dist/teams/teams-formatter.js.map +1 -0
- package/package.json +40 -7
package/README.md
CHANGED
|
@@ -1,45 +1,233 @@
|
|
|
1
1
|
# @memberjunction/messaging-adapters
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
This
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
3
|
+
Slack and Microsoft Teams integrations for MemberJunction AI agents. Receive messages from messaging platforms, route them to MJ AI agents via `AgentRunner.RunAgentInConversation()`, and stream rich formatted responses back to users.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides ready-to-use server extensions that connect messaging platforms to MJ AI agents:
|
|
8
|
+
|
|
9
|
+
- **Slack** — Webhook + Socket Mode integration with Block Kit rich formatting, interactive modals, slash commands, and HMAC-SHA256 signature verification
|
|
10
|
+
- **Microsoft Teams** — Bot Framework integration with Adaptive Card formatting, form handling, and JWT validation
|
|
11
|
+
|
|
12
|
+
Built on the [`@memberjunction/server-extensions-core`](../ServerExtensionsCore/) framework, these adapters are auto-discovered by MJServer via `@RegisterClass` and configured in `mj.config.cjs` — no MJServer source code changes needed.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- **Multi-agent routing** — Users can @mention different agents (e.g., `@Research Agent`). 4-pass name matching handles full names, prefixes, bare names, and anywhere-in-message patterns. Thread affinity remembers the agent across follow-up messages.
|
|
17
|
+
- **Agent delegation** — When an agent returns `payload.invokeAgent`, the adapter auto-delegates to the target agent (up to 3 chained hops), mirroring MJ Explorer behavior.
|
|
18
|
+
- **User identity mapping** — Platform user emails are mapped to MJ `UserInfo` records for proper per-user permission scoping. Falls back to a configured service account.
|
|
19
|
+
- **Streaming responses** — Progressive message updates as the agent generates content, with configurable throttle intervals to avoid rate limiting.
|
|
20
|
+
- **Rich formatting** — Markdown responses convert to Slack Block Kit blocks or Teams Adaptive Cards, with agent identity headers, artifact deep-links, action buttons, response forms, and metadata footers.
|
|
21
|
+
- **Conversation context** — Thread history is passed to agents for multi-turn conversations. MJ Conversations and Artifacts are automatically created.
|
|
22
|
+
- **Interactive forms** — Response forms render as Slack modals or Teams Adaptive Card forms, with round-trip back to the agent.
|
|
23
|
+
- **Slash commands** — Slack slash commands auto-generated from agent names, with config overrides.
|
|
24
|
+
- **Deep links** — "View in MJ Explorer" buttons link to artifacts and conversations.
|
|
25
|
+
- **Platform-specific auth** — Slack uses HMAC-SHA256 signature verification with replay protection; Teams uses Bot Framework JWT validation.
|
|
26
|
+
- **Dual Slack connection modes** — HTTP webhooks (production) or Socket Mode (local dev, no public URL needed).
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
See **[SETUP_GUIDE.md](SETUP_GUIDE.md)** for detailed step-by-step instructions including Slack App creation, Azure Bot registration, and Teams manifest setup.
|
|
31
|
+
|
|
32
|
+
### Slack (minimal config)
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// mj.config.cjs
|
|
36
|
+
module.exports = {
|
|
37
|
+
serverExtensions: [{
|
|
38
|
+
Enabled: true,
|
|
39
|
+
DriverClass: 'SlackMessagingExtension',
|
|
40
|
+
RootPath: '/webhook/slack',
|
|
41
|
+
Settings: {
|
|
42
|
+
DefaultAgentName: 'Sage',
|
|
43
|
+
ContextUserEmail: 'bot@company.com',
|
|
44
|
+
BotToken: process.env.SLACK_BOT_TOKEN,
|
|
45
|
+
SigningSecret: process.env.SLACK_SIGNING_SECRET,
|
|
46
|
+
}
|
|
47
|
+
}]
|
|
48
|
+
};
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Teams (minimal config)
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
// mj.config.cjs
|
|
55
|
+
module.exports = {
|
|
56
|
+
serverExtensions: [{
|
|
57
|
+
Enabled: true,
|
|
58
|
+
DriverClass: 'TeamsMessagingExtension',
|
|
59
|
+
RootPath: '/webhook/teams',
|
|
60
|
+
Settings: {
|
|
61
|
+
DefaultAgentName: 'Sage',
|
|
62
|
+
ContextUserEmail: 'bot@company.com',
|
|
63
|
+
MicrosoftAppId: process.env.MICROSOFT_APP_ID,
|
|
64
|
+
MicrosoftAppPassword: process.env.MICROSOFT_APP_PASSWORD,
|
|
65
|
+
}
|
|
66
|
+
}]
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Tree-Shaking Prevention
|
|
71
|
+
|
|
72
|
+
Ensure the `@RegisterClass` decorators fire at module load time:
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { LoadMessagingAdapters } from '@memberjunction/messaging-adapters';
|
|
76
|
+
LoadMessagingAdapters();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Architecture
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
┌─────────────────────────────────────┐
|
|
83
|
+
│ mj.config.cjs │
|
|
84
|
+
│ serverExtensions: [{ │
|
|
85
|
+
│ DriverClass: 'SlackMessaging...' │
|
|
86
|
+
│ Settings: { ... } │
|
|
87
|
+
│ }] │
|
|
88
|
+
└──────────────┬──────────────────────┘
|
|
89
|
+
│
|
|
90
|
+
┌──────────────▼──────────────────────┐
|
|
91
|
+
│ ServerExtensionLoader │
|
|
92
|
+
│ ClassFactory.CreateInstance( │
|
|
93
|
+
│ BaseServerExtension, driverClass │
|
|
94
|
+
│ ) │
|
|
95
|
+
└──────────────┬──────────────────────┘
|
|
96
|
+
│
|
|
97
|
+
┌────────────────────┼────────────────────┐
|
|
98
|
+
│ │ │
|
|
99
|
+
┌─────────▼──────────┐ ┌──────▼──────────┐ ┌───────▼─────────┐
|
|
100
|
+
│ SlackMessaging │ │ TeamsMessaging │ │ YourCustom │
|
|
101
|
+
│ Extension │ │ Extension │ │ Extension │
|
|
102
|
+
│ POST /webhook/slack │ │ POST /webhook/ │ │ │
|
|
103
|
+
│ POST .../interact │ │ teams │ │ │
|
|
104
|
+
│ POST .../slash │ │ │ │ │
|
|
105
|
+
└─────────┬──────────┘ └──────┬──────────┘ └─────────────────┘
|
|
106
|
+
│ │
|
|
107
|
+
┌─────────▼──────────┐ ┌──────▼──────────┐
|
|
108
|
+
│ SlackAdapter │ │ TeamsAdapter │
|
|
109
|
+
│ extends │ │ extends │
|
|
110
|
+
│ BaseMessaging- │ │ BaseMessaging- │
|
|
111
|
+
│ Adapter │ │ Adapter │
|
|
112
|
+
└─────────┬──────────┘ └──────┬──────────┘
|
|
113
|
+
│ │
|
|
114
|
+
└────────┬───────────┘
|
|
115
|
+
│
|
|
116
|
+
┌────────▼────────┐
|
|
117
|
+
│ BaseMessaging │
|
|
118
|
+
│ Adapter │
|
|
119
|
+
│ (orchestration) │
|
|
120
|
+
│ │
|
|
121
|
+
│ 1. Resolve user │
|
|
122
|
+
│ 2. Resolve agent│
|
|
123
|
+
│ 3. Fetch thread │
|
|
124
|
+
│ 4. Run agent │
|
|
125
|
+
│ 5. Delegation │
|
|
126
|
+
│ 6. Format resp │
|
|
127
|
+
│ 7. Send/update │
|
|
128
|
+
└─────────────────┘
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Settings Reference
|
|
132
|
+
|
|
133
|
+
| Setting | Type | Default | Description |
|
|
134
|
+
|---------|------|---------|-------------|
|
|
135
|
+
| `DefaultAgentName` | `string` | (required) | Default MJ AI Agent name |
|
|
136
|
+
| `ContextUserEmail` | `string` | (required) | Fallback service account email |
|
|
137
|
+
| `BotToken` | `string` | (required for Slack) | Slack Bot OAuth Token (`xoxb-...`) |
|
|
138
|
+
| `SigningSecret` | `string` | — | Slack signing secret for webhook verification |
|
|
139
|
+
| `AppToken` | `string` | — | Slack App-Level Token for Socket Mode (`xapp-...`) |
|
|
140
|
+
| `ConnectionMode` | `'http' \| 'socket'` | `'http'` | Slack connection mode |
|
|
141
|
+
| `MaxThreadMessages` | `number` | `50` | Max thread messages for conversation context |
|
|
142
|
+
| `ShowTypingIndicator` | `boolean` | `true` | Show typing indicator while processing |
|
|
143
|
+
| `StreamingUpdateIntervalMs` | `number` | `1000` | Min interval between streaming updates (ms) |
|
|
144
|
+
| `ExplorerBaseURL` | `string` | — | MJ Explorer URL for "View in Explorer" buttons |
|
|
145
|
+
| `SlashCommands` | `Record<string, string>` | — | Slash command → agent name mapping (Slack only) |
|
|
146
|
+
| `MicrosoftAppId` | `string` | — | Azure Bot Service App ID (Teams only) |
|
|
147
|
+
| `MicrosoftAppPassword` | `string` | — | Azure Bot Service App Password (Teams only) |
|
|
148
|
+
| `MicrosoftAppTenantId` | `string` | — | Azure AD Tenant ID for Single Tenant (Teams only) |
|
|
149
|
+
| `MicrosoftAppType` | `string` | auto | `'SingleTenant'`, `'MultiTenant'`, or `'UserAssignedMsi'` |
|
|
150
|
+
|
|
151
|
+
## Exported Utilities
|
|
152
|
+
|
|
153
|
+
The package exports shared formatting utilities useful for building custom adapters:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import {
|
|
157
|
+
// Base utilities
|
|
158
|
+
BaseMessagingAdapter,
|
|
159
|
+
splitMarkdownIntoSections,
|
|
160
|
+
convertToSlackMrkdwn,
|
|
161
|
+
truncateText,
|
|
162
|
+
splitTextIntoChunks,
|
|
163
|
+
|
|
164
|
+
// Slack
|
|
165
|
+
SlackAdapter,
|
|
166
|
+
SlackMessagingExtension,
|
|
167
|
+
markdownToBlocks,
|
|
168
|
+
verifySlackSignature,
|
|
169
|
+
handleSlackInteraction,
|
|
170
|
+
buildRichResponse,
|
|
171
|
+
buildAgentContextBlock,
|
|
172
|
+
buildFormModal,
|
|
173
|
+
|
|
174
|
+
// Teams
|
|
175
|
+
TeamsAdapter,
|
|
176
|
+
TeamsMessagingExtension,
|
|
177
|
+
markdownToAdaptiveCard,
|
|
178
|
+
buildRichAdaptiveCard,
|
|
179
|
+
|
|
180
|
+
// Tree-shaking prevention
|
|
181
|
+
LoadMessagingAdapters,
|
|
182
|
+
} from '@memberjunction/messaging-adapters';
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Building a Custom Adapter
|
|
186
|
+
|
|
187
|
+
To add support for a new messaging platform (Discord, Google Chat, etc.):
|
|
188
|
+
|
|
189
|
+
1. Create a class extending `BaseMessagingAdapter` and implement all abstract methods
|
|
190
|
+
2. Create a `BaseServerExtension` subclass with `@RegisterClass` that sets up routes
|
|
191
|
+
3. Add a formatter that converts Markdown to your platform's rich format
|
|
192
|
+
4. Optionally add a block/card builder for rich layouts
|
|
193
|
+
|
|
194
|
+
See `SlackAdapter.ts` and `SlackMessagingExtension.ts` for a complete reference implementation.
|
|
195
|
+
|
|
196
|
+
## Testing
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
npm run test # Run all 301 tests
|
|
200
|
+
npm run test:watch # Watch mode
|
|
201
|
+
npm run test:coverage # With coverage report
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Test suites cover every module:
|
|
205
|
+
|
|
206
|
+
| Test File | Tests | Coverage |
|
|
207
|
+
|-----------|-------|----------|
|
|
208
|
+
| `BaseMessagingAdapter.test.ts` | 40 | Core orchestration, agent resolution, thread affinity, delegation |
|
|
209
|
+
| `message-formatter.test.ts` | 28 | Markdown parsing, text splitting, Slack mrkdwn conversion |
|
|
210
|
+
| `slack-formatter.test.ts` | 10 | Markdown → Block Kit conversion |
|
|
211
|
+
| `slack-block-builder.test.ts` | 57 | Rich layouts, truncation, payload limits, "View Full" |
|
|
212
|
+
| `slack-routes.test.ts` | 10 | HMAC-SHA256 verification, replay attack prevention |
|
|
213
|
+
| `slack-interactivity.test.ts` | 19 | Modal forms, button routing, form submissions |
|
|
214
|
+
| `SlackAdapter.test.ts` | 12 | Event mapping, mention parsing, typing indicators |
|
|
215
|
+
| `SlackMessagingExtension.test.ts` | 26 | HTTP/Socket mode, signature verification, slash commands |
|
|
216
|
+
| `TeamsAdapter.test.ts` | 31 | Activity mapping, form extraction, streaming |
|
|
217
|
+
| `TeamsMessagingExtension.test.ts` | 12 | Bot Framework routing, JWT validation |
|
|
218
|
+
| `teams-formatter.test.ts` | 7 | Markdown → Adaptive Card TextBlock |
|
|
219
|
+
| `teams-card-builder.test.ts` | 52 | Rich card composition, actions, forms, payload limits |
|
|
220
|
+
|
|
221
|
+
## Known Limitations
|
|
222
|
+
|
|
223
|
+
- **Teams thread history**: Requires Microsoft Graph API with `ChannelMessage.Read.All` permission, not yet implemented. Teams conversations are currently single-turn.
|
|
224
|
+
- **Full response store**: The "View Full" button in Slack stores content in memory with a 30-minute TTL. Content is lost on server restart.
|
|
225
|
+
- **Conversation references**: Teams conversation references for proactive messaging are stored in memory (lost on restart).
|
|
226
|
+
- **Max delegation hops**: Agent delegation chains limited to 3 hops.
|
|
227
|
+
|
|
228
|
+
## Related Packages
|
|
229
|
+
|
|
230
|
+
- [`@memberjunction/server-extensions-core`](../ServerExtensionsCore/) — The extension framework this package builds on
|
|
231
|
+
- [`@memberjunction/server`](../MJServer/) — MJServer that loads and manages extensions
|
|
232
|
+
- [`@memberjunction/ai-agents`](../AI/Agents/) — Agent execution engine (`AgentRunner`)
|
|
233
|
+
- [`@memberjunction/ai-core-plus`](../AI/CorePlus/) — Agent types and execution result structures
|