Spaces:
Paused
Paused
djmuted
commited on
Commit
•
e6f4b4a
1
Parent(s):
0e39520
Fix config
Browse files- src/config.js +0 -7
- src/slack.js +7 -3
- src/utils.js +9 -9
src/config.js
DELETED
@@ -1,7 +0,0 @@
|
|
1 |
-
module.exports = {
|
2 |
-
TOKEN: process.env.TOKEN,
|
3 |
-
COOKIE: process.env.COOKIE,
|
4 |
-
TEAM_ID: process.env.TEAM_ID,
|
5 |
-
CLAUDE: process.env.CLAUDE,
|
6 |
-
API_KEY: process.env.API_KEY,
|
7 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/slack.js
CHANGED
@@ -3,10 +3,11 @@ const { v4: uuidv4 } = require('uuid');
|
|
3 |
const https = require('https');
|
4 |
const WebSocket = require('ws');
|
5 |
|
6 |
-
const { readBody,
|
7 |
|
8 |
async function sendPromptMessage(config, prompt) {
|
9 |
-
const form = createBaseForm();
|
|
|
10 |
|
11 |
form.append('ts', convertToUnixTime(new Date()));
|
12 |
form.append('type', 'message');
|
@@ -42,7 +43,8 @@ async function sendPromptMessage(config, prompt) {
|
|
42 |
}
|
43 |
|
44 |
async function sendChatReset(config) {
|
45 |
-
const form = createBaseForm();
|
|
|
46 |
|
47 |
form.append('command', '/reset');
|
48 |
form.append('disp', '/reset');
|
@@ -74,6 +76,8 @@ async function sendChatReset(config) {
|
|
74 |
}
|
75 |
|
76 |
async function waitForWebSocketResponse(config, messages, onData) {
|
|
|
|
|
77 |
return new Promise(async (resolve, reject) => {
|
78 |
const websocketURL = `wss://wss-primary.slack.com/?token=${config.token}`;
|
79 |
|
|
|
3 |
const https = require('https');
|
4 |
const WebSocket = require('ws');
|
5 |
|
6 |
+
const { readBody, genHeaders, createBaseForm, convertToUnixTime, currentTime, buildPrompt } = require('./utils');
|
7 |
|
8 |
async function sendPromptMessage(config, prompt) {
|
9 |
+
const form = createBaseForm(config);
|
10 |
+
const headers = genHeaders(config);
|
11 |
|
12 |
form.append('ts', convertToUnixTime(new Date()));
|
13 |
form.append('type', 'message');
|
|
|
43 |
}
|
44 |
|
45 |
async function sendChatReset(config) {
|
46 |
+
const form = createBaseForm(config);
|
47 |
+
const headers = genHeaders(config);
|
48 |
|
49 |
form.append('command', '/reset');
|
50 |
form.append('disp', '/reset');
|
|
|
76 |
}
|
77 |
|
78 |
async function waitForWebSocketResponse(config, messages, onData) {
|
79 |
+
const headers = genHeaders(config);
|
80 |
+
|
81 |
return new Promise(async (resolve, reject) => {
|
82 |
const websocketURL = `wss://wss-primary.slack.com/?token=${config.token}`;
|
83 |
|
src/utils.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
const FormData = require('form-data');
|
2 |
|
3 |
-
const { TOKEN, COOKIE, TEAM_ID, CLAUDE } = require('./config');
|
4 |
-
|
5 |
const wait = (duration) => {
|
6 |
return new Promise((resolve) => {
|
7 |
setTimeout(() => {
|
@@ -63,9 +61,11 @@ const currentTime = () => {
|
|
63 |
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
|
64 |
};
|
65 |
|
66 |
-
const
|
67 |
-
|
68 |
-
|
|
|
|
|
69 |
}
|
70 |
|
71 |
function splitJsonArray(jsonArray, maxLength) {
|
@@ -101,10 +101,10 @@ function convertToUnixTime(date) {
|
|
101 |
return `${unixTime}.xxxxx${randomDigit}`;
|
102 |
}
|
103 |
|
104 |
-
function createBaseForm() {
|
105 |
const form = new FormData();
|
106 |
-
form.append('token',
|
107 |
-
form.append('channel', `${
|
108 |
form.append('_x_mode', 'online');
|
109 |
form.append('_x_sonic', 'true');
|
110 |
return form;
|
@@ -148,7 +148,7 @@ module.exports = {
|
|
148 |
readBody,
|
149 |
preparePrompt,
|
150 |
currentTime,
|
151 |
-
|
152 |
convertToUnixTime,
|
153 |
createBaseForm,
|
154 |
splitJsonArray,
|
|
|
1 |
const FormData = require('form-data');
|
2 |
|
|
|
|
|
3 |
const wait = (duration) => {
|
4 |
return new Promise((resolve) => {
|
5 |
setTimeout(() => {
|
|
|
61 |
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
|
62 |
};
|
63 |
|
64 |
+
const genHeaders = (config) => {
|
65 |
+
return {
|
66 |
+
'Cookie': `d=${config.cookie};`,
|
67 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/112.0',
|
68 |
+
}
|
69 |
}
|
70 |
|
71 |
function splitJsonArray(jsonArray, maxLength) {
|
|
|
101 |
return `${unixTime}.xxxxx${randomDigit}`;
|
102 |
}
|
103 |
|
104 |
+
function createBaseForm(config) {
|
105 |
const form = new FormData();
|
106 |
+
form.append('token', config.token);
|
107 |
+
form.append('channel', `${config.claudeId}`);
|
108 |
form.append('_x_mode', 'online');
|
109 |
form.append('_x_sonic', 'true');
|
110 |
return form;
|
|
|
148 |
readBody,
|
149 |
preparePrompt,
|
150 |
currentTime,
|
151 |
+
genHeaders,
|
152 |
convertToUnixTime,
|
153 |
createBaseForm,
|
154 |
splitJsonArray,
|