Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/fix-industry-alerts-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"adcontextprotocol": patch
---

Remove AAO bot dependency; use Addie bot for all Slack operations

- Consolidate to single Slack bot (Addie) instead of dual-bot setup
- ADDIE_BOT_TOKEN is now primary, with SLACK_BOT_TOKEN fallback for migration
- Remove useAddieToken parameter from sendChannelMessage and getThreadReplies
- Remove getSlackUserWithAddieToken helper function
- Update all callers to use simplified API
8 changes: 4 additions & 4 deletions server/src/addie/bolt-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import type { RequestTools } from './claude-client.js';
import type { SuggestedPrompt } from './types.js';
import { DatabaseThreadContextStore } from './thread-context-store.js';
import { getThreadService, type ThreadContext } from './thread-service.js';
import { getThreadReplies, getSlackUserWithAddieToken, getChannelInfo } from '../slack/client.js';
import { getThreadReplies, getSlackUser, getChannelInfo } from '../slack/client.js';
import { AddieRouter, type RoutingContext, type ExecutionPlan } from './router.js';
import { getCachedInsights, prefetchInsights } from './insights-cache.js';

Expand Down Expand Up @@ -803,7 +803,7 @@ async function handleAppMention({
let threadContext = '';
if (isInThread && event.thread_ts) {
try {
const threadMessages = await getThreadReplies(channelId, event.thread_ts, true);
const threadMessages = await getThreadReplies(channelId, event.thread_ts);
if (threadMessages.length > 0) {
// Filter out Addie's own messages and format the thread history
const filteredMessages = threadMessages
Expand All @@ -828,7 +828,7 @@ async function handleAppMention({
if (mentionedUserIds.size > 0) {
const lookups = await Promise.all(
Array.from(mentionedUserIds).map(async (uid) => {
const user = await getSlackUserWithAddieToken(uid);
const user = await getSlackUser(uid);
return { uid, name: user?.profile?.display_name || user?.real_name || user?.name || null };
})
);
Expand Down Expand Up @@ -1150,7 +1150,7 @@ async function indexChannelMessage(
try {
// Fetch user and channel info
const [user, channel] = await Promise.all([
getSlackUserWithAddieToken(userId),
getSlackUser(userId),
getChannelInfo(channelId),
]);

Expand Down
10 changes: 5 additions & 5 deletions server/src/addie/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ export async function handleAssistantMessage(
// Validate output
const outputValidation = validateOutput(response.text);

// Send response using Addie's bot token
// Send response
try {
await sendChannelMessage(channelId, {
text: outputValidation.sanitized,
thread_ts: event.thread_ts,
}, true); // useAddieToken = true
});
} catch (error) {
logger.error({ error }, 'Addie: Failed to send response');
}
Expand Down Expand Up @@ -433,12 +433,12 @@ export async function handleAppMention(event: AppMentionEvent): Promise<void> {
// Validate output
const outputValidation = validateOutput(response.text);

// Send response in thread using Addie's bot token
// Send response in thread
try {
await sendChannelMessage(event.channel, {
text: outputValidation.sanitized,
thread_ts: event.thread_ts || event.ts,
}, true); // useAddieToken = true
});
} catch (error) {
logger.error({ error }, 'Addie: Failed to send mention response');
}
Expand Down Expand Up @@ -579,7 +579,7 @@ export async function sendAccountLinkedMessage(
await sendChannelMessage(recentThread.channel_id, {
text: message,
thread_ts: recentThread.thread_ts,
}, true); // useAddieToken = true
});
logger.info({ slackUserId, channelId: recentThread.channel_id }, 'Addie: Sent account linked message');
return true;
} catch (error) {
Expand Down
88 changes: 18 additions & 70 deletions server/src/slack/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* Slack Web API client for AAO integration
* Slack Web API client
*
* Provides methods for user lookup, DM sending, and channel management.
* Uses bot token authentication.
* Uses Addie's bot token for all operations.
*/

import { logger } from '../logger.js';
Expand All @@ -13,8 +13,8 @@ import type {
SlackBlockMessage,
} from './types.js';

const SLACK_BOT_TOKEN = process.env.SLACK_BOT_TOKEN;
const ADDIE_BOT_TOKEN = process.env.ADDIE_BOT_TOKEN;
// Use ADDIE_BOT_TOKEN as the primary token (fall back to SLACK_BOT_TOKEN for migration)
const SLACK_BOT_TOKEN = process.env.ADDIE_BOT_TOKEN || process.env.SLACK_BOT_TOKEN;
const SLACK_API_BASE = 'https://slack.com/api';

// Rate limiting: Slack's tier 2 methods allow ~20 requests per minute
Expand Down Expand Up @@ -43,7 +43,7 @@ async function slackRequest<T>(
retries = 3
): Promise<T> {
if (!SLACK_BOT_TOKEN) {
throw new Error('SLACK_BOT_TOKEN is not configured');
throw new Error('ADDIE_BOT_TOKEN is not configured');
}

const url = new URL(`${SLACK_API_BASE}/${method}`);
Expand Down Expand Up @@ -99,17 +99,14 @@ async function slackRequest<T>(

/**
* Make a POST request to the Slack API (for chat.postMessage, etc.)
* @param useAddieToken - If true, uses ADDIE_BOT_TOKEN instead of SLACK_BOT_TOKEN
*/
async function slackPostRequest<T>(
method: string,
body: Record<string, unknown>,
retries = 3,
useAddieToken = false
retries = 3
): Promise<T> {
const token = useAddieToken ? (ADDIE_BOT_TOKEN || SLACK_BOT_TOKEN) : SLACK_BOT_TOKEN;
if (!token) {
throw new Error(useAddieToken ? 'ADDIE_BOT_TOKEN is not configured' : 'SLACK_BOT_TOKEN is not configured');
if (!SLACK_BOT_TOKEN) {
throw new Error('ADDIE_BOT_TOKEN is not configured');
}

const url = `${SLACK_API_BASE}/${method}`;
Expand All @@ -119,7 +116,7 @@ async function slackPostRequest<T>(
const response = await fetch(url, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${SLACK_BOT_TOKEN}`,
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(body),
Expand Down Expand Up @@ -160,10 +157,10 @@ function sleep(ms: number): Promise<void> {
}

/**
* Check if Slack integration is configured
* Check if Slack integration is configured (Addie bot token)
*/
export function isSlackConfigured(): boolean {
return Boolean(SLACK_BOT_TOKEN);
return Boolean(process.env.ADDIE_BOT_TOKEN || process.env.SLACK_BOT_TOKEN);
}

/**
Expand Down Expand Up @@ -211,42 +208,6 @@ export async function getSlackUser(userId: string): Promise<SlackUser | null> {
}
}

/**
* Get a single user by ID using Addie's bot token
* Use this when Addie needs to look up users in channels it has access to
*/
export async function getSlackUserWithAddieToken(userId: string): Promise<SlackUser | null> {
if (!ADDIE_BOT_TOKEN) {
logger.warn('ADDIE_BOT_TOKEN not configured, cannot look up user');
return null;
}

try {
const url = new URL(`${SLACK_API_BASE}/users.info`);
url.searchParams.set('user', userId);

const response = await fetch(url.toString(), {
method: 'GET',
headers: {
Authorization: `Bearer ${ADDIE_BOT_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
});

const data = await response.json() as { ok: boolean; user?: SlackUser; error?: string };

if (!data.ok) {
logger.warn({ error: data.error, userId }, 'Failed to get Slack user with Addie token');
return null;
}

return data.user || null;
} catch (error) {
logger.error({ error, userId }, 'Error fetching Slack user with Addie token');
return null;
}
}

/**
* Look up a user by email address
*/
Expand Down Expand Up @@ -299,12 +260,10 @@ export async function sendDirectMessage(

/**
* Send a message to a channel
* @param useAddieToken - If true, uses ADDIE_BOT_TOKEN for Addie's DM channels
*/
export async function sendChannelMessage(
channelId: string,
message: SlackBlockMessage,
useAddieToken = false
message: SlackBlockMessage
): Promise<{ ok: boolean; ts?: string; error?: string }> {
try {
const response = await slackPostRequest<{ ts: string }>('chat.postMessage', {
Expand All @@ -313,9 +272,9 @@ export async function sendChannelMessage(
blocks: message.blocks,
thread_ts: message.thread_ts,
reply_broadcast: message.reply_broadcast,
}, 3, useAddieToken);
});

logger.info({ channelId, ts: response.ts, useAddieToken }, 'Sent Slack channel message');
logger.info({ channelId, ts: response.ts }, 'Sent Slack channel message');
return { ok: true, ts: response.ts };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
Expand Down Expand Up @@ -491,24 +450,13 @@ export interface SlackThreadMessage {
/**
* Get thread replies (conversations.replies)
* Returns all messages in a thread, including the parent message
* @param useAddieToken - If true, uses ADDIE_BOT_TOKEN
*/
export async function getThreadReplies(
channelId: string,
threadTs: string,
useAddieToken = false
threadTs: string
): Promise<SlackThreadMessage[]> {
let token: string | undefined;
if (useAddieToken) {
if (!ADDIE_BOT_TOKEN) {
throw new Error('ADDIE_BOT_TOKEN is not configured');
}
token = ADDIE_BOT_TOKEN;
} else {
if (!SLACK_BOT_TOKEN) {
throw new Error('SLACK_BOT_TOKEN is not configured');
}
token = SLACK_BOT_TOKEN;
if (!SLACK_BOT_TOKEN) {
throw new Error('ADDIE_BOT_TOKEN is not configured');
}

try {
Expand All @@ -520,7 +468,7 @@ export async function getThreadReplies(
const response = await fetch(url.toString(), {
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
Authorization: `Bearer ${SLACK_BOT_TOKEN}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
});
Expand Down
4 changes: 2 additions & 2 deletions server/src/slack/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function syncSlackUsers(): Promise<SyncSlackUsersResult> {
new_users: 0,
updated_users: 0,
auto_mapped: 0,
errors: ['Slack is not configured (SLACK_BOT_TOKEN missing)'],
errors: ['Slack is not configured (ADDIE_BOT_TOKEN missing)'],
};
}

Expand Down Expand Up @@ -197,7 +197,7 @@ export async function syncWorkingGroupMembersFromSlack(
members_added: 0,
members_already_in_group: 0,
unmapped_slack_users: 0,
errors: ['Slack is not configured (SLACK_BOT_TOKEN missing)'],
errors: ['Slack is not configured (ADDIE_BOT_TOKEN missing)'],
};
}

Expand Down