Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langfuse Langfuse SlackService

From Leeroopedia
Knowledge Sources
Domains Integrations, Slack, Notifications
Last Updated 2026-02-14 00:00 GMT

Overview

The SlackService is a singleton service class that manages Slack OAuth integration, channel listing, and message sending for Langfuse projects using the official Slack SDK libraries.

Description

The SlackService class handles the complete Slack integration lifecycle for Langfuse projects. It is implemented as a singleton (via getInstance()) and wraps the Slack SDK's InstallProvider for OAuth flow management and WebClient for API operations.

Key components and behaviors:

  • OAuth flow management - Uses @slack/oauth InstallProvider with a custom installationStore that persists Slack installations to PostgreSQL via the slackIntegration Prisma model. Each project maps to one Slack workspace integration.
  • Encrypted token storage - Bot tokens are encrypted via encrypt() before storage and decrypted via decrypt() on retrieval, ensuring sensitive credentials are not stored in plaintext.
  • Metadata-based project mapping - Installation metadata carries the projectId, parsed and validated by parseSlackInstallationMetadata. The fetchInstallation callback supports lookup by both teamId and projectId.
  • Channel listing - getChannels recursively fetches all public, non-archived channels using cursor-based pagination, respecting the SLACK_FETCH_LIMIT environment variable.
  • Message sending - sendMessage posts Block Kit messages to a specified channel with link unfurling disabled.
  • Client management - getWebClientForProject authorizes and returns a WebClient instance for a given project.
  • Client validation - validateClient tests whether a WebClient is still valid via auth.test().
  • Integration deletion - deleteIntegration removes the Slack integration for a project.

The requested OAuth scopes are: channels:read, chat:write, chat:write.public.

Usage

Use this service when you need to:

  • Initiate or handle the Slack OAuth installation flow for a project.
  • Retrieve the list of Slack channels a bot can post to.
  • Send notification messages (e.g., evaluation alerts) to a Slack channel.
  • Validate or refresh a Slack connection for a project.
  • Remove a Slack integration from a project.

Code Reference

Source Location

Signature

export interface SlackChannel {
  id: string;
  name: string;
  isPrivate: boolean;
  isMember: boolean;
}

export interface SlackMessageParams {
  client: WebClient;
  channelId: string;
  blocks: any[];
  text?: string;
}

export interface SlackMessageResponse {
  messageTs: string;
  channel: string;
}

export function parseSlackInstallationMetadata(
  metadata: unknown,
): SlackInstallationMetadata;

export class SlackService {
  static getInstance(): SlackService;
  static resetInstance(): void;
  getInstaller(): InstallProvider;
  async deleteIntegration(projectId: string): Promise<void>;
  async getWebClientForProject(projectId: string): Promise<WebClient>;
  async getChannels(client: WebClient): Promise<SlackChannel[]>;
  async sendMessage(params: SlackMessageParams): Promise<SlackMessageResponse>;
  async validateClient(client: WebClient): Promise<boolean>;
}

Import

import { SlackService, SlackChannel, SlackMessageParams } from "@langfuse/shared/src/server/services/SlackService";

I/O Contract

Inputs

Name Type Required Description
projectId string Yes The project ID for retrieving or deleting Slack integrations
client WebClient Yes (for channels/messages) An authorized Slack WebClient instance
channelId string Yes (for sending) The Slack channel ID to send a message to
blocks any[] Yes (for sending) Slack Block Kit blocks composing the message body
text string No Fallback plain text for the message (defaults to "Langfuse Notification")
metadata unknown Yes (for parsing) Raw installation metadata string containing projectId JSON

Outputs

Name Type Description
SlackService SlackService Singleton instance of the service
WebClient WebClient Authorized Slack Web API client for a specific project
SlackChannel[] array List of accessible Slack channels with id, name, privacy, and membership status
SlackMessageResponse object Contains messageTs (Slack timestamp ID) and channel for the sent message
boolean boolean Client validation result (true if auth.test succeeds)

Usage Examples

import { SlackService } from "@langfuse/shared/src/server/services/SlackService";

// Get the singleton instance
const slackService = SlackService.getInstance();

// Get a WebClient for a project
const client = await slackService.getWebClientForProject("proj-123");

// List available channels
const channels = await slackService.getChannels(client);

// Send a notification message
const response = await slackService.sendMessage({
  client,
  channelId: "C01234567",
  blocks: [
    {
      type: "section",
      text: {
        type: "mrkdwn",
        text: "Evaluation *accuracy* completed with score 0.95",
      },
    },
  ],
  text: "Evaluation accuracy completed with score 0.95",
});

// Validate the client connection
const isValid = await slackService.validateClient(client);

// Delete integration for a project
await slackService.deleteIntegration("proj-123");

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment