@credal/actions 0.2.153 → 0.2.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/autogen/templates.js +5 -0
- package/dist/actions/autogen/types.d.ts +3 -0
- package/dist/actions/autogen/types.js +4 -0
- package/dist/actions/groups.js +14 -1
- package/dist/actions/providers/confluence/updatePage.d.ts +3 -0
- package/dist/actions/providers/confluence/updatePage.js +46 -0
- package/dist/actions/providers/generic/fillTemplateAction.d.ts +7 -0
- package/dist/actions/providers/generic/fillTemplateAction.js +18 -0
- package/dist/actions/providers/generic/genericApiCall.d.ts +3 -0
- package/dist/actions/providers/generic/genericApiCall.js +38 -0
- package/dist/actions/providers/google-oauth/getDriveContentById.d.ts +3 -0
- package/dist/actions/providers/google-oauth/getDriveContentById.js +161 -0
- package/dist/actions/providers/google-oauth/searchAndGetDriveContentByKeywords.d.ts +3 -0
- package/dist/actions/providers/google-oauth/searchAndGetDriveContentByKeywords.js +47 -0
- package/dist/actions/providers/google-oauth/searchDriveAndGetContentByKeywords.d.ts +3 -0
- package/dist/actions/providers/google-oauth/searchDriveAndGetContentByKeywords.js +110 -0
- package/dist/actions/providers/google-oauth/searchDriveAndGetContentByQuery.d.ts +3 -0
- package/dist/actions/providers/google-oauth/searchDriveAndGetContentByQuery.js +78 -0
- package/dist/actions/providers/google-oauth/utils/extractContentFromDriveFileId.d.ts +15 -0
- package/dist/actions/providers/google-oauth/utils/extractContentFromDriveFileId.js +129 -0
- package/dist/actions/providers/googlemaps/nearbysearch.d.ts +3 -0
- package/dist/actions/providers/googlemaps/nearbysearch.js +96 -0
- package/dist/actions/providers/slack/archiveChannel.js +9 -2
- package/dist/actions/providers/slackUser/getSlackMessagesInTimeRange.d.ts +3 -0
- package/dist/actions/providers/slackUser/getSlackMessagesInTimeRange.js +81 -0
- package/dist/actions/providers/slackUser/searchSlack.d.ts +11 -0
- package/dist/actions/providers/slackUser/searchSlack.js +67 -24
- package/dist/actions/providers/snowflake/runSnowflakeQueryWriteResultsToS3.d.ts +3 -0
- package/dist/actions/providers/snowflake/runSnowflakeQueryWriteResultsToS3.js +154 -0
- package/dist/actions/providers/x/scrapeTweetDataWithNitter.d.ts +3 -0
- package/dist/actions/providers/x/scrapeTweetDataWithNitter.js +45 -0
- package/package.json +1 -1
- package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.d.ts +0 -3
- package/dist/actions/providers/salesforce/getSalesforceRecordByQuery.js +0 -43
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AuthParamsType } from "../../../autogen/types.js";
|
|
2
|
+
export type getDriveFileContentParams = {
|
|
3
|
+
fileId: string;
|
|
4
|
+
mimeType: string;
|
|
5
|
+
};
|
|
6
|
+
export type getDriveFileContentOutput = {
|
|
7
|
+
success: boolean;
|
|
8
|
+
content?: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
};
|
|
11
|
+
declare const extractContentFromDriveFileId: ({ params, authParams, }: {
|
|
12
|
+
params: getDriveFileContentParams;
|
|
13
|
+
authParams: AuthParamsType;
|
|
14
|
+
}) => Promise<getDriveFileContentOutput>;
|
|
15
|
+
export default extractContentFromDriveFileId;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { axiosClient } from "../../../util/axiosClient.js";
|
|
11
|
+
import mammoth from "mammoth";
|
|
12
|
+
import { MISSING_AUTH_TOKEN } from "../../../util/missingAuthConstants.js";
|
|
13
|
+
const extractContentFromDriveFileId = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
14
|
+
if (!authParams.authToken) {
|
|
15
|
+
return { success: false, error: MISSING_AUTH_TOKEN };
|
|
16
|
+
}
|
|
17
|
+
const { fileId, mimeType } = params;
|
|
18
|
+
let content = "";
|
|
19
|
+
try {
|
|
20
|
+
// Handle different file types - read content directly
|
|
21
|
+
if (mimeType === "application/vnd.google-apps.document") {
|
|
22
|
+
// Google Docs - download as plain text
|
|
23
|
+
const exportUrl = `https://www.googleapis.com/drive/v3/files/${encodeURIComponent(fileId)}/export?mimeType=text/plain`;
|
|
24
|
+
const exportRes = yield axiosClient.get(exportUrl, {
|
|
25
|
+
headers: {
|
|
26
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
27
|
+
},
|
|
28
|
+
responseType: "text",
|
|
29
|
+
});
|
|
30
|
+
content = exportRes.data;
|
|
31
|
+
}
|
|
32
|
+
else if (mimeType === "application/vnd.google-apps.spreadsheet") {
|
|
33
|
+
// Google Sheets - download as CSV
|
|
34
|
+
const exportUrl = `https://www.googleapis.com/drive/v3/files/${encodeURIComponent(fileId)}/export?mimeType=text/csv`;
|
|
35
|
+
const exportRes = yield axiosClient.get(exportUrl, {
|
|
36
|
+
headers: {
|
|
37
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
38
|
+
},
|
|
39
|
+
responseType: "text",
|
|
40
|
+
});
|
|
41
|
+
// Clean up excessive commas from empty columns
|
|
42
|
+
content = exportRes.data
|
|
43
|
+
.split("\n")
|
|
44
|
+
.map((line) => line.replace(/,+$/, "")) // Remove trailing commas
|
|
45
|
+
.map((line) => line.replace(/,{2,}/g, ",")) // Replace multiple commas with single comma
|
|
46
|
+
.join("\n");
|
|
47
|
+
}
|
|
48
|
+
else if (mimeType === "application/vnd.google-apps.presentation") {
|
|
49
|
+
// Google Slides - download as plain text
|
|
50
|
+
const exportUrl = `https://www.googleapis.com/drive/v3/files/${encodeURIComponent(fileId)}/export?mimeType=text/plain`;
|
|
51
|
+
const exportRes = yield axiosClient.get(exportUrl, {
|
|
52
|
+
headers: {
|
|
53
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
54
|
+
},
|
|
55
|
+
responseType: "text",
|
|
56
|
+
});
|
|
57
|
+
content = exportRes.data;
|
|
58
|
+
}
|
|
59
|
+
else if (mimeType === "application/pdf") {
|
|
60
|
+
return {
|
|
61
|
+
success: false,
|
|
62
|
+
error: "PDF files are not supported for text extraction",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
else if (mimeType === "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
|
|
66
|
+
mimeType === "application/msword") {
|
|
67
|
+
// Word documents (.docx or .doc) - download and extract text using mammoth
|
|
68
|
+
const downloadUrl = `https://www.googleapis.com/drive/v3/files/${encodeURIComponent(fileId)}?alt=media`;
|
|
69
|
+
const downloadRes = yield axiosClient.get(downloadUrl, {
|
|
70
|
+
headers: {
|
|
71
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
72
|
+
},
|
|
73
|
+
responseType: "arraybuffer",
|
|
74
|
+
});
|
|
75
|
+
try {
|
|
76
|
+
// mammoth works with .docx files. It will ignore formatting and return raw text
|
|
77
|
+
const result = yield mammoth.extractRawText({ buffer: Buffer.from(downloadRes.data) });
|
|
78
|
+
content = result.value; // raw text
|
|
79
|
+
}
|
|
80
|
+
catch (wordError) {
|
|
81
|
+
return {
|
|
82
|
+
success: false,
|
|
83
|
+
error: `Failed to parse Word document: ${wordError instanceof Error ? wordError.message : "Unknown Word error"}`,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else if (mimeType === "text/plain" ||
|
|
88
|
+
mimeType === "text/html" ||
|
|
89
|
+
mimeType === "application/rtf" ||
|
|
90
|
+
(mimeType === null || mimeType === void 0 ? void 0 : mimeType.startsWith("text/"))) {
|
|
91
|
+
// Text-based files
|
|
92
|
+
const downloadUrl = `https://www.googleapis.com/drive/v3/files/${encodeURIComponent(fileId)}?alt=media`;
|
|
93
|
+
const downloadRes = yield axiosClient.get(downloadUrl, {
|
|
94
|
+
headers: {
|
|
95
|
+
Authorization: `Bearer ${authParams.authToken}`,
|
|
96
|
+
},
|
|
97
|
+
responseType: "text",
|
|
98
|
+
});
|
|
99
|
+
content = downloadRes.data;
|
|
100
|
+
}
|
|
101
|
+
else if (mimeType === null || mimeType === void 0 ? void 0 : mimeType.startsWith("image/")) {
|
|
102
|
+
// Skip images
|
|
103
|
+
return {
|
|
104
|
+
success: false,
|
|
105
|
+
error: "Image files are not supported for text extraction",
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
// Unsupported file type
|
|
110
|
+
return {
|
|
111
|
+
success: false,
|
|
112
|
+
error: `Unsupported file type: ${mimeType}`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
content = content.trim();
|
|
116
|
+
return {
|
|
117
|
+
success: true,
|
|
118
|
+
content,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error("Error getting Google Drive file content", error);
|
|
123
|
+
return {
|
|
124
|
+
success: false,
|
|
125
|
+
error: error instanceof Error ? error.message : "Unknown error",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
export default extractContentFromDriveFileId;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const axios_1 = __importDefault(require("axios"));
|
|
16
|
+
const types_1 = require("../../autogen/types");
|
|
17
|
+
const INCLUDED_TYPES = [
|
|
18
|
+
"monument",
|
|
19
|
+
"museum",
|
|
20
|
+
"art_gallery",
|
|
21
|
+
"sculpture",
|
|
22
|
+
"cultural_landmark",
|
|
23
|
+
"historical_place",
|
|
24
|
+
"performing_arts_theater",
|
|
25
|
+
"university",
|
|
26
|
+
"aquarium",
|
|
27
|
+
"botanical_garden",
|
|
28
|
+
"comedy_club",
|
|
29
|
+
"park",
|
|
30
|
+
"movie_theater",
|
|
31
|
+
"national_park",
|
|
32
|
+
"garden",
|
|
33
|
+
"night_club",
|
|
34
|
+
"tourist_attraction",
|
|
35
|
+
"water_park",
|
|
36
|
+
"zoo",
|
|
37
|
+
"bar",
|
|
38
|
+
"restaurant",
|
|
39
|
+
"food_court",
|
|
40
|
+
"bakery",
|
|
41
|
+
"cafe",
|
|
42
|
+
"coffee_shop",
|
|
43
|
+
"pub",
|
|
44
|
+
"wine_bar",
|
|
45
|
+
"spa",
|
|
46
|
+
"beach",
|
|
47
|
+
"market",
|
|
48
|
+
"shopping_mall",
|
|
49
|
+
"stadium",
|
|
50
|
+
];
|
|
51
|
+
const nearbysearch = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
52
|
+
const url = `https://places.googleapis.com/v1/places:searchNearby`;
|
|
53
|
+
const fieldMask = [
|
|
54
|
+
"places.displayName",
|
|
55
|
+
"places.formattedAddress",
|
|
56
|
+
"places.priceLevel",
|
|
57
|
+
"places.rating",
|
|
58
|
+
"places.primaryTypeDisplayName",
|
|
59
|
+
"places.editorialSummary",
|
|
60
|
+
"places.regularOpeningHours",
|
|
61
|
+
].join(",");
|
|
62
|
+
const response = yield axios_1.default.post(url, {
|
|
63
|
+
maxResultCount: 20,
|
|
64
|
+
includedTypes: INCLUDED_TYPES,
|
|
65
|
+
locationRestriction: {
|
|
66
|
+
circle: {
|
|
67
|
+
center: {
|
|
68
|
+
latitude: params.latitude,
|
|
69
|
+
longitude: params.longitude,
|
|
70
|
+
},
|
|
71
|
+
radius: 10000,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
}, {
|
|
75
|
+
headers: {
|
|
76
|
+
"X-Goog-Api-Key": authParams.apiKey,
|
|
77
|
+
"X-Goog-FieldMask": fieldMask,
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
return types_1.googlemapsNearbysearchOutputSchema.parse({
|
|
82
|
+
results: response.data.places.map((place) => {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
return ({
|
|
85
|
+
name: place.displayName.text,
|
|
86
|
+
address: place.formattedAddress,
|
|
87
|
+
priceLevel: place.priceLevel,
|
|
88
|
+
rating: place.rating,
|
|
89
|
+
primaryType: place.primaryTypeDisplayName.text,
|
|
90
|
+
editorialSummary: ((_a = place.editorialSummary) === null || _a === void 0 ? void 0 : _a.text) || "",
|
|
91
|
+
openingHours: ((_b = place.regularOpeningHours) === null || _b === void 0 ? void 0 : _b.weekdayDescriptions.join("\n")) || "",
|
|
92
|
+
});
|
|
93
|
+
}),
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
exports.default = nearbysearch;
|
|
@@ -9,14 +9,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { WebClient } from "@slack/web-api";
|
|
11
11
|
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
12
|
+
import { getSlackChannels } from "./helpers.js";
|
|
12
13
|
const archiveChannel = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
13
14
|
if (!authParams.authToken) {
|
|
14
15
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
15
16
|
}
|
|
16
17
|
try {
|
|
17
18
|
const client = new WebClient(authParams.authToken);
|
|
18
|
-
const {
|
|
19
|
-
const
|
|
19
|
+
const { channelName } = params;
|
|
20
|
+
const allChannels = yield getSlackChannels(client);
|
|
21
|
+
const channel = allChannels.find(channel => channel.name == channelName);
|
|
22
|
+
if (!channel || !channel.id) {
|
|
23
|
+
throw Error(`Channel with name ${channelName} not found`);
|
|
24
|
+
}
|
|
25
|
+
yield client.conversations.join({ channel: channel.id });
|
|
26
|
+
const result = yield client.conversations.archive({ channel: channel.id });
|
|
20
27
|
if (!result.ok) {
|
|
21
28
|
return {
|
|
22
29
|
success: false,
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { WebClient } from "@slack/web-api";
|
|
11
|
+
import { MISSING_AUTH_TOKEN } from "../../util/missingAuthConstants.js";
|
|
12
|
+
import { extractMessageText, SlackUserCache, normalizeChannelOperand } from "./searchSlack.js";
|
|
13
|
+
/* ===================== Helpers ===================== */
|
|
14
|
+
function searchMessagesInTimeRange(input) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const { client, channel, oldest, latest, limit } = input;
|
|
18
|
+
// Build search query - use wildcard to match all messages
|
|
19
|
+
const parts = [`in:${normalizeChannelOperand(channel)}`];
|
|
20
|
+
if (oldest) {
|
|
21
|
+
parts.push(`after:${oldest}`);
|
|
22
|
+
}
|
|
23
|
+
if (latest) {
|
|
24
|
+
parts.push(`before:${latest}`);
|
|
25
|
+
}
|
|
26
|
+
// Use * as a wildcard to match all messages
|
|
27
|
+
const query = parts.join(" ") + " *";
|
|
28
|
+
const searchRes = yield client.search.messages({ query, count: limit, highlight: true });
|
|
29
|
+
return (_b = (_a = searchRes.messages) === null || _a === void 0 ? void 0 : _a.matches) !== null && _b !== void 0 ? _b : [];
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/* ===================== MAIN EXPORT ===================== */
|
|
33
|
+
const getSlackMessagesInTimeRange = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
34
|
+
if (!authParams.authToken)
|
|
35
|
+
throw new Error(MISSING_AUTH_TOKEN);
|
|
36
|
+
const client = new WebClient(authParams.authToken);
|
|
37
|
+
const cache = new SlackUserCache(client);
|
|
38
|
+
const { channel, oldest, limit = 50 } = params;
|
|
39
|
+
let { latest } = params;
|
|
40
|
+
// Ensure latest doesn't exceed current time
|
|
41
|
+
const now = Math.floor(Date.now() / 1000);
|
|
42
|
+
if (latest && latest > now) {
|
|
43
|
+
latest = now;
|
|
44
|
+
}
|
|
45
|
+
const { user_id: myUserId } = yield client.auth.test();
|
|
46
|
+
if (!myUserId)
|
|
47
|
+
throw new Error("Failed to get my user ID.");
|
|
48
|
+
const meInfo = yield cache.get(myUserId);
|
|
49
|
+
// Search for messages in the channel using search API
|
|
50
|
+
const matches = yield searchMessagesInTimeRange({ client, channel, oldest, latest, limit });
|
|
51
|
+
// Convert matches to results
|
|
52
|
+
const results = yield Promise.all(matches.map((m) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
var _a, _b, _c, _d;
|
|
54
|
+
if (!m.ts || !((_a = m.channel) === null || _a === void 0 ? void 0 : _a.id))
|
|
55
|
+
return null;
|
|
56
|
+
// Get user info for the message author
|
|
57
|
+
const userId = (_b = m.user) !== null && _b !== void 0 ? _b : m.username;
|
|
58
|
+
const userInfo = userId ? yield cache.get(userId) : undefined;
|
|
59
|
+
// Extract text from the match
|
|
60
|
+
const text = (_d = (_c = extractMessageText(m)) !== null && _c !== void 0 ? _c : m.text) !== null && _d !== void 0 ? _d : "";
|
|
61
|
+
return {
|
|
62
|
+
channelId: m.channel.id,
|
|
63
|
+
ts: m.ts,
|
|
64
|
+
text,
|
|
65
|
+
userEmail: userInfo === null || userInfo === void 0 ? void 0 : userInfo.email,
|
|
66
|
+
userName: userInfo === null || userInfo === void 0 ? void 0 : userInfo.name,
|
|
67
|
+
permalink: m.permalink,
|
|
68
|
+
};
|
|
69
|
+
})));
|
|
70
|
+
// Filter out nulls and sort by timestamp descending
|
|
71
|
+
const validResults = results.filter(Boolean).sort((a, b) => Number(b.ts) - Number(a.ts));
|
|
72
|
+
return {
|
|
73
|
+
results: validResults.map(r => ({
|
|
74
|
+
name: r.text || "Untitled",
|
|
75
|
+
url: r.permalink || "",
|
|
76
|
+
contents: r,
|
|
77
|
+
})),
|
|
78
|
+
currentUser: { userId: myUserId, userName: meInfo === null || meInfo === void 0 ? void 0 : meInfo.name, userEmail: meInfo === null || meInfo === void 0 ? void 0 : meInfo.email },
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
export default getSlackMessagesInTimeRange;
|
|
@@ -29,6 +29,17 @@ interface SlackMessage {
|
|
|
29
29
|
thread_ts?: string;
|
|
30
30
|
blocks?: KnownBlock[];
|
|
31
31
|
attachments?: Attachment[];
|
|
32
|
+
reactions?: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
count: number;
|
|
35
|
+
users: string[];
|
|
36
|
+
}>;
|
|
37
|
+
files?: Array<{
|
|
38
|
+
name?: string;
|
|
39
|
+
title?: string;
|
|
40
|
+
mimetype?: string;
|
|
41
|
+
url_private?: string;
|
|
42
|
+
}>;
|
|
32
43
|
}
|
|
33
44
|
/**
|
|
34
45
|
* Extracts all visible text from a Slack message
|
|
@@ -306,6 +306,8 @@ function transformToSlackMessage(message) {
|
|
|
306
306
|
thread_ts: message.thread_ts,
|
|
307
307
|
blocks: message.blocks,
|
|
308
308
|
attachments: message.attachments,
|
|
309
|
+
reactions: message.reactions,
|
|
310
|
+
files: message.files,
|
|
309
311
|
};
|
|
310
312
|
}
|
|
311
313
|
function fetchOneMessage(client, channel, ts) {
|
|
@@ -397,17 +399,45 @@ function searchByTopic(input) {
|
|
|
397
399
|
return (_b = (_a = searchRes.messages) === null || _a === void 0 ? void 0 : _a.matches) !== null && _b !== void 0 ? _b : [];
|
|
398
400
|
});
|
|
399
401
|
}
|
|
402
|
+
/**
|
|
403
|
+
* Deduplicates and merges Slack threads.
|
|
404
|
+
* When multiple search hits point to the same thread (same thread_ts),
|
|
405
|
+
* we merge them into a single result with all unique messages in context.
|
|
406
|
+
*/
|
|
400
407
|
function dedupeAndSort(results) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
409
|
+
// Group by thread: channelId + ts (where ts is the root thread_ts)
|
|
410
|
+
const threadMap = new Map();
|
|
411
|
+
for (const result of results) {
|
|
412
|
+
const threadKey = `${result.channelId}-${result.ts}`;
|
|
413
|
+
const existing = threadMap.get(threadKey);
|
|
414
|
+
if (!existing) {
|
|
415
|
+
// First time seeing this thread
|
|
416
|
+
threadMap.set(threadKey, result);
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
// Merge: dedupe context messages by ts
|
|
420
|
+
const existingTsSet = new Set((_b = (_a = existing.context) === null || _a === void 0 ? void 0 : _a.map(m => m.ts)) !== null && _b !== void 0 ? _b : []);
|
|
421
|
+
const newMessages = ((_c = result.context) !== null && _c !== void 0 ? _c : []).filter(m => !existingTsSet.has(m.ts));
|
|
422
|
+
if (newMessages.length > 0) {
|
|
423
|
+
existing.context = [...((_d = existing.context) !== null && _d !== void 0 ? _d : []), ...newMessages].sort((a, b) => Number(a.ts) - Number(b.ts));
|
|
424
|
+
}
|
|
425
|
+
// Update permalink if missing
|
|
426
|
+
if (!existing.permalink && result.permalink) {
|
|
427
|
+
existing.permalink = result.permalink;
|
|
428
|
+
}
|
|
429
|
+
// Merge members if needed (for DMs/MPIMs)
|
|
430
|
+
if (result.members && result.members.length > 0) {
|
|
431
|
+
const existingMemberIds = new Set((_f = (_e = existing.members) === null || _e === void 0 ? void 0 : _e.map(m => m.userId)) !== null && _f !== void 0 ? _f : []);
|
|
432
|
+
const newMembers = result.members.filter(m => !existingMemberIds.has(m.userId));
|
|
433
|
+
if (newMembers.length > 0) {
|
|
434
|
+
existing.members = [...((_g = existing.members) !== null && _g !== void 0 ? _g : []), ...newMembers];
|
|
435
|
+
}
|
|
436
|
+
}
|
|
408
437
|
}
|
|
409
438
|
}
|
|
410
|
-
|
|
439
|
+
// Sort by timestamp descending (most recent first)
|
|
440
|
+
return Array.from(threadMap.values()).sort((a, b) => Number(b.ts) - Number(a.ts));
|
|
411
441
|
}
|
|
412
442
|
/* ===================== MAIN EXPORT ===================== */
|
|
413
443
|
const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, authParams, }) {
|
|
@@ -415,7 +445,7 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
415
445
|
throw new Error(MISSING_AUTH_TOKEN);
|
|
416
446
|
const client = new WebClient(authParams.authToken);
|
|
417
447
|
const cache = new SlackUserCache(client);
|
|
418
|
-
const { emails, topic, timeRange, limit = 20, channel } = params;
|
|
448
|
+
const { emails, topic, timeRange, limit = 20, channel, fetchAdjacentMessages = true } = params;
|
|
419
449
|
const { user_id: myUserId } = yield client.auth.test();
|
|
420
450
|
if (!myUserId)
|
|
421
451
|
throw new Error("Failed to get my user ID.");
|
|
@@ -466,7 +496,7 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
466
496
|
searchResults.forEach(matches => allMatches.push(...matches));
|
|
467
497
|
const channelInfoCache = new Map();
|
|
468
498
|
const expanded = yield Promise.all(allMatches.map(m => limitHit(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
469
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
499
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _o;
|
|
470
500
|
if (!m.ts || !((_a = m.channel) === null || _a === void 0 ? void 0 : _a.id))
|
|
471
501
|
return null;
|
|
472
502
|
const anchor = yield fetchOneMessage(client, m.channel.id, m.ts);
|
|
@@ -491,10 +521,12 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
491
521
|
yield fetchThread(client, m.channel.id, rootTs),
|
|
492
522
|
(_g = m.permalink) !== null && _g !== void 0 ? _g : (yield getPermalink(client, m.channel.id, rootTs)),
|
|
493
523
|
]
|
|
494
|
-
:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
524
|
+
: fetchAdjacentMessages
|
|
525
|
+
? [
|
|
526
|
+
yield fetchContextWindow(client, m.channel.id, m.ts),
|
|
527
|
+
(_h = m.permalink) !== null && _h !== void 0 ? _h : (yield getPermalink(client, m.channel.id, m.ts)),
|
|
528
|
+
]
|
|
529
|
+
: [[], (_j = m.permalink) !== null && _j !== void 0 ? _j : (yield getPermalink(client, m.channel.id, m.ts))];
|
|
498
530
|
// filter logic
|
|
499
531
|
let passesFilter = false;
|
|
500
532
|
if (channelInfo.isIm || channelInfo.isMpim) {
|
|
@@ -506,17 +538,28 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
506
538
|
}
|
|
507
539
|
if (filteredTargetIds.length && !passesFilter)
|
|
508
540
|
return null;
|
|
509
|
-
const
|
|
541
|
+
const allContext = yield Promise.all(contextMsgs.map((t) => __awaiter(void 0, void 0, void 0, function* () {
|
|
510
542
|
var _a;
|
|
511
543
|
const u = t.user ? yield cache.get(t.user) : undefined;
|
|
512
544
|
const rawText = extractMessageText(t);
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
545
|
+
// Build interaction description
|
|
546
|
+
const interactions = [];
|
|
547
|
+
if (t.reactions && t.reactions.length > 0) {
|
|
548
|
+
interactions.push(`Reactions: ${t.reactions.map(r => `:${r.name}: (${r.count})`).join(", ")}`);
|
|
549
|
+
}
|
|
550
|
+
if (t.files && t.files.length > 0) {
|
|
551
|
+
interactions.push(`Files: ${t.files.map(f => f.title || f.name || "Untitled").join(", ")}`);
|
|
552
|
+
}
|
|
553
|
+
return Object.assign({ ts: t.ts, text: rawText ? yield expandSlackEntities(cache, rawText) : undefined, userEmail: u === null || u === void 0 ? void 0 : u.email, userName: (_a = u === null || u === void 0 ? void 0 : u.name) !== null && _a !== void 0 ? _a : t.username }, (interactions.length > 0 ? { interactions: interactions.join(" | ") } : {}));
|
|
519
554
|
})));
|
|
555
|
+
// Deduplicate by timestamp - appears the the context array returned can have duplicates
|
|
556
|
+
const seenTs = new Set();
|
|
557
|
+
const context = allContext.filter(msg => {
|
|
558
|
+
if (seenTs.has(msg.ts))
|
|
559
|
+
return false;
|
|
560
|
+
seenTs.add(msg.ts);
|
|
561
|
+
return true;
|
|
562
|
+
});
|
|
520
563
|
const anchorUser = (anchor === null || anchor === void 0 ? void 0 : anchor.user) ? yield cache.get(anchor.user) : undefined;
|
|
521
564
|
const anchorText = extractMessageText(anchor);
|
|
522
565
|
return {
|
|
@@ -524,10 +567,10 @@ const searchSlack = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params,
|
|
|
524
567
|
ts: rootTs,
|
|
525
568
|
text: anchorText ? yield expandSlackEntities(cache, anchorText) : undefined,
|
|
526
569
|
userEmail: anchorUser === null || anchorUser === void 0 ? void 0 : anchorUser.email,
|
|
527
|
-
userName: (
|
|
570
|
+
userName: (_k = anchorUser === null || anchorUser === void 0 ? void 0 : anchorUser.name) !== null && _k !== void 0 ? _k : anchor === null || anchor === void 0 ? void 0 : anchor.username,
|
|
528
571
|
context,
|
|
529
|
-
permalink: (
|
|
530
|
-
members: ((
|
|
572
|
+
permalink: (_l = m.permalink) !== null && _l !== void 0 ? _l : permalink,
|
|
573
|
+
members: ((_o = channelInfo.members) !== null && _o !== void 0 ? _o : []).map(uid => {
|
|
531
574
|
const u = cache.getSync(uid);
|
|
532
575
|
return { userId: uid, userEmail: u === null || u === void 0 ? void 0 : u.email, userName: u === null || u === void 0 ? void 0 : u.name };
|
|
533
576
|
}),
|