Build Knowledge Graph from Slack Messages
User Intent
What this does
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
Last updated