MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / sendAccountLinkedMessage

Function sendAccountLinkedMessage

server/src/addie/bolt-app.ts:4252–4306  ·  view source on GitHub ↗
(
  slackUserId: string,
  userName?: string
)

Source from the content-addressed store, hash-verified

4250 * Send a proactive message when a user links their account
4251 */
4252export async function sendAccountLinkedMessage(
4253 slackUserId: string,
4254 userName?: string
4255): Promise<boolean> {
4256 if (!initialized || !boltApp) {
4257 logger.warn('Addie Bolt: Not initialized, cannot send account linked message');
4258 return false;
4259 }
4260
4261 const threadService = getThreadService();
4262
4263 // Find the user's most recent Addie thread (within 30 minutes)
4264 const recentThread = await threadService.getUserRecentThread(slackUserId, 'slack', 30);
4265 if (!recentThread) {
4266 logger.debug({ slackUserId }, 'Addie Bolt: No recent thread found for account linked message');
4267 return false;
4268 }
4269
4270 // Parse external_id back to channel_id:thread_ts
4271 const [channelId, threadTs] = recentThread.external_id.split(':');
4272 if (!channelId || !threadTs) {
4273 logger.warn({ slackUserId, externalId: recentThread.external_id }, 'Addie Bolt: Invalid external_id format');
4274 return false;
4275 }
4276
4277 // Build a personalized message
4278 const greeting = userName ? `Thanks for linking your account, ${userName}!` : 'Thanks for linking your account!';
4279 const messageText = `${greeting} 🎉\n\nI can now see your profile and help you get more involved with AgenticAdvertising.org. What would you like to do next?`;
4280
4281 // Send the message using Bolt's client
4282 try {
4283 await boltApp.client.chat.postMessage({
4284 channel: channelId,
4285 text: messageText,
4286 thread_ts: threadTs,
4287 });
4288 } catch (error) {
4289 logger.error({ error, slackUserId }, 'Addie Bolt: Failed to send account linked message');
4290 return false;
4291 }
4292
4293 // Log as a system message in the unified thread (separate from Slack send)
4294 try {
4295 await threadService.addMessage({
4296 thread_id: recentThread.thread_id,
4297 role: 'system',
4298 content: messageText,
4299 });
4300 } catch (error) {
4301 logger.error({ error, threadId: recentThread.thread_id }, 'Addie Bolt: Failed to save account linked message');
4302 }
4303
4304 logger.info({ slackUserId, channelId }, 'Addie Bolt: Sent account linked message');
4305 return true;
4306}
4307
4308// ============================================================================
4309// App Home Handlers

Callers

nothing calls this directly

Calls 4

getThreadServiceFunction · 0.85
warnMethod · 0.80
getUserRecentThreadMethod · 0.45
addMessageMethod · 0.45

Tested by

no test coverage detected