Build Knowledge Graph from Slack Messages

User Intent

"How do I extract entities from Slack messages to build a knowledge graph?"

What this does

  1. Create an entity-extraction workflow.

  2. Create a Slack feed (one feed per channel).

  3. Wait for the initial sync.

  4. Query message content and inspect extracted observations (entities).

TypeScript (End-to-End Example)

import { Graphlit } from 'graphlit-client';
import {
  ContentTypes,
  EntityExtractionServiceTypes,
  FeedListingTypes,
  FeedTypes,
  ObservableTypes,
} from 'graphlit-client/dist/generated/graphql-types';

const graphlit = new Graphlit();

// 1) Create a workflow that extracts entities from content
const workflow = await graphlit.createWorkflow({
  name: 'Extract Entities from Slack Messages',
  extraction: {
    jobs: [
      {
        connector: {
          type: EntityExtractionServiceTypes.ModelText,
          extractedTypes: [ObservableTypes.Person, ObservableTypes.Organization, ObservableTypes.Label],
        },
      },
    ],
  },
});

// 2) Create a Slack feed (one channel per feed)
const feed = await graphlit.createFeed({
  name: 'Slack #engineering',
  type: FeedTypes.Slack,
  slack: {
    type: FeedListingTypes.Past,
    channel: 'engineering',
    token: process.env.SLACK_TOKEN!,
    readLimit: 1000,
    includeAttachments: true,
  },
  workflow: { id: workflow.createWorkflow.id },
});

// 3) Wait for initial sync
while (true) {
  const status = await graphlit.isFeedDone(feed.createFeed.id);
  if (status.isFeedDone.result) break;
  await new Promise((r) => setTimeout(r, 5000));
}

// 4) Query messages ingested by this feed
const messages = await graphlit.queryContents({
  
    types: [ContentTypes.Message],
    feeds: [{ id: feed.createFeed.id }],
  
});

// 5) Observations (entities) are attached to content
for (const c of messages.contents.results.slice(0, 5)) {
  const people = (c.observations ?? []).filter((o) => o.type === ObservableTypes.Person);
  console.log(c.name, people.map((p) => p.observable.name));
}

Notes

  • Slack feeds are scoped to a single channel name. If you want multiple channels, create multiple feeds.

  • Thread/reply behavior is handled by the connector; there is no separate boolean field in the current Slack feed input shape.

Last updated