# 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)

```typescript
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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.graphlit.dev/api-guides/use-cases/knowledge-graph/knowledge-graph-from-slack-messages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
