Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(channel-reader): tell an unresolved Teams sender why they are being ignored

Jose Ramirezfeb2f0187e81
diff --git a/channel-reader/package-lock.json b/channel-reader/package-lock.json
index 0d890b564..a32701ead 100644
--- a/channel-reader/package-lock.json
+++ b/channel-reader/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-channel-reader",
- "version": "0.1.93",
+ "version": "0.1.94",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-channel-reader",
- "version": "0.1.93",
+ "version": "0.1.94",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@kubernetes/client-node": "^1.0.0",
diff --git a/channel-reader/package.json b/channel-reader/package.json
index bdf0cfa14..8f2a6a307 100644
--- a/channel-reader/package.json
+++ b/channel-reader/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-channel-reader",
- "version": "0.1.93",
+ "version": "0.1.94",
"description": "Watches CommunicationChannel CRDs and fetches messages from Telegram, Email, and Slack",
"main": "dist/main.js",
"engines": {
diff --git a/channel-reader/src/main.ts b/channel-reader/src/main.ts
index 90185e047..e412cf38d 100644
--- a/channel-reader/src/main.ts
+++ b/channel-reader/src/main.ts
@@ -102,6 +102,9 @@ const UNRESOLVED_NOTICE_TTL_MS = 24 * 60 * 60 * 1000 // 24 hours
const UNRESOLVED_NOTICE_COPY =
"I can't accept messages from this Slack account. If you haven't linked it yet, " +
'do that in your evenfire profile. If you think you should already have access, contact your admin.'
+const UNRESOLVED_NOTICE_COPY_TEAMS =
+ "I can't accept messages from this Teams account. If you haven't linked it yet, " +
+ 'do that in your evenfire profile. If you think you should already have access, contact your admin.'
const SLACK_VERIFICATION_SCAN_INTERVAL_MS = 60 * 1000
const TOOL_APPROVAL_ACTION_RE = /^tool:([ald]):([A-Za-z0-9_-]{16})$/
/**
@@ -1550,11 +1553,11 @@ export class ChannelReader {
}
/**
- * Tell an unresolved Slack sender why the agent is ignoring them, at most once
- * per user per conversation per UNRESOLVED_NOTICE_TTL_MS.
+ * Tell an unresolved Slack or Teams sender why the agent is ignoring them, at
+ * most once per user per conversation per UNRESOLVED_NOTICE_TTL_MS.
*/
private async sendUnresolvedSenderNotice(msg: Message): Promise<void> {
- if (msg.channelType !== 'slack') return
+ if (msg.channelType !== 'slack' && msg.channelType !== 'teams') return
const identity = msg.providerIdentity
const userId = identity?.providerUserId?.trim()
const workspaceId = identity?.providerWorkspaceId?.trim()
@@ -1572,11 +1575,21 @@ export class ChannelReader {
this.unresolvedNoticesSent.set(key, { seenAt: Date.now() })
const adapter = this.adapterForMessage(msg)
- if (!adapter?.sendEphemeral) return
+ if (!adapter) return
const profileUrl = config.profileUiUrl?.trim()
- const content = profileUrl ? `${UNRESOLVED_NOTICE_COPY} ${profileUrl}` : UNRESOLVED_NOTICE_COPY
+ const baseCopy =
+ msg.channelType === 'teams' ? UNRESOLVED_NOTICE_COPY_TEAMS : UNRESOLVED_NOTICE_COPY
+ const content = profileUrl ? `${baseCopy} ${profileUrl}` : baseCopy
try {
- await adapter.sendEphemeral(channelId, userId, content)
+ if (msg.channelType === 'teams') {
+ // TeamsAdapter has no ephemeral concept, so the notice is a normal message.
+ // Thread it under the triggering message so an unconnected user does not
+ // produce a top-level post in a shared channel.
+ await adapter.sendMessage(channelId, content, msg.messageId)
+ } else {
+ if (!adapter.sendEphemeral) return
+ await adapter.sendEphemeral(channelId, userId, content)
+ }
} catch (error) {
// Contain the failure HERE. SlackAdapter swallows its own errors today, but
// the ChannelAdapter interface promises nothing, and this runs inside the
diff --git a/channel-reader/test/unresolvedSenderNotice.test.ts b/channel-reader/test/unresolvedSenderNotice.test.ts
index 1906b5cc3..fbfd515ee 100644
--- a/channel-reader/test/unresolvedSenderNotice.test.ts
+++ b/channel-reader/test/unresolvedSenderNotice.test.ts
@@ -94,7 +94,7 @@ describe('authorizeProviderMessage response shape', () => {
interface BuildReaderOptions {
/** Omit the key entirely for the default; pass `undefined` for "no reason at all". */
reason?: 'unresolved' | 'error'
- medium?: 'slack' | 'telegram'
+ medium?: 'slack' | 'telegram' | 'teams'
ephemeralThrows?: boolean
profileUiUrl?: string
}
@@ -120,13 +120,14 @@ function buildReader(options: BuildReaderOptions = {}) {
const sendEphemeral = vi.fn(async (_channelId: string, _userId: string, _content: string) => {
if (ephemeralThrows) throw new Error('user_not_in_channel')
})
+ const sendMessage = vi.fn(async () => undefined)
const adapter: ChannelAdapter = {
channelType: medium,
connect: vi.fn(async () => undefined),
disconnect: vi.fn(async () => undefined),
fetchMessages: vi.fn(async () => []),
- sendMessage: vi.fn(async () => undefined),
+ sendMessage,
editMessage: vi.fn(async () => undefined),
sendEphemeral,
}
@@ -194,8 +195,8 @@ function buildReader(options: BuildReaderOptions = {}) {
// contain a throwing adapter itself, so an escaped throw must surface here as a
// rejected promise rather than being absorbed by the harness.
const deliver = async (
- channelId: string,
- userId: string,
+ channelId = 'C1',
+ userId = 'U1',
workspaceId = 'T1',
providerChannelId = channelId
): Promise<void> =>
@@ -213,6 +214,7 @@ function buildReader(options: BuildReaderOptions = {}) {
deliverBatch,
runSweep,
sendEphemeral,
+ sendMessage,
adapter,
authorizeProviderMessage,
}
@@ -343,6 +345,42 @@ describe('unresolved sender notice', () => {
})
})
+describe('unresolved sender notice on Teams', () => {
+ it('sends a threaded notice to an unresolved Teams sender', async () => {
+ const { deliver, sendMessage } = buildReader({
+ medium: 'teams',
+ profileUiUrl: 'https://profile.test',
+ })
+
+ await deliver()
+
+ expect(sendMessage).toHaveBeenCalledTimes(1)
+ const [channelId, content, replyToMessageId] = sendMessage.mock.calls[0]
+ expect(channelId).toBe('C1')
+ expect(content).toContain('https://profile.test')
+ // Threading is the whole mitigation for Teams having no ephemeral concept:
+ // a top-level post would announce the notice to the entire channel.
+ expect(replyToMessageId).toBeTruthy()
+ })
+
+ it('sends the Teams notice at most once per user per conversation', async () => {
+ const { deliver, sendMessage } = buildReader({ medium: 'teams' })
+
+ await deliver()
+ await deliver()
+
+ expect(sendMessage).toHaveBeenCalledTimes(1)
+ })
+
+ it('does not use sendEphemeral for Teams', async () => {
+ const { deliver, sendEphemeral } = buildReader({ medium: 'teams' })
+
+ await deliver()
+
+ expect(sendEphemeral).not.toHaveBeenCalled()
+ })
+})
+
describe('unresolved notice link', () => {
it('appends the profile URL when configured', async () => {
const { deliver, sendEphemeral } = buildReader({ profileUiUrl: 'https://profile.example.com' })