MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / createKiloBot

Function createKiloBot

apps/web/src/lib/bot.ts:21–128  ·  view source on GitHub ↗
(
  slackAdapter: SlackAdapter,
  githubAdapter: GitHubAdapter,
  linearAdapter: LinearAdapter
)

Source from the content-addressed store, hash-verified

19import { createSlackWebhookHandler } from '@/lib/bot/platforms/slack-webhook';
20
21function createKiloBot(
22 slackAdapter: SlackAdapter,
23 githubAdapter: GitHubAdapter,
24 linearAdapter: LinearAdapter
25) {
26 const chatBot = new Chat({
27 userName: process.env.NODE_ENV === 'production' ? 'Kilo' : 'Henk',
28 adapters: {
29 github: githubAdapter,
30 slack: slackAdapter,
31 linear: linearAdapter,
32 },
33 state: createChatState(),
34 logger: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
35 });
36
37 chatBot.webhooks.slack = createSlackWebhookHandler(chatBot, slackAdapter);
38 chatBot.webhooks.linear = createLinearWebhookHandler(chatBot, linearAdapter);
39
40 chatBot.onNewMention(async function handleIncomingMessage(
41 thread: Thread,
42 message: Message
43 ): Promise<void> {
44 const botPlatform = botPlatforms.requireByAdapter(thread.adapter);
45 const identity = await botPlatform.getIdentity({ thread, message });
46 const [platformIntegration, kiloUserId] = await Promise.all([
47 getPlatformIntegration(identity),
48 resolveKiloUserId(chatBot.getState(), identity),
49 ]);
50
51 if (!platformIntegration) {
52 captureException(new Error('No active platform integration found'), {
53 extra: { platform: identity.platform, teamId: identity.teamId },
54 });
55 return;
56 }
57
58 if (!botPlatform.isEnabledForBot(platformIntegration)) {
59 return;
60 }
61
62 if (!(await botPlatform.canHandleMessage({ thread, message, platformIntegration }))) {
63 return;
64 }
65
66 if (!kiloUserId) {
67 await botPlatform.promptLinkAccount({
68 thread,
69 message,
70 identity,
71 platformIntegration,
72 state: chatBot.getState(),
73 });
74 return;
75 }
76
77 const user = await findUserById(kiloUserId);
78

Callers 1

bot.tsFile · 0.85

Calls 12

createChatStateFunction · 0.90
getPlatformIntegrationFunction · 0.90
resolveKiloUserIdFunction · 0.90
findUserByIdFunction · 0.90
unlinkKiloUserFunction · 0.90
processLinkedMessageFunction · 0.90
postMethod · 0.80
errorMethod · 0.65
getStateMethod · 0.45

Tested by

no test coverage detected