Die Datei zeigt den Slack -Kanal nicht anJavaScript

Javascript-Forum
Anonymous
 Die Datei zeigt den Slack -Kanal nicht an

Post by Anonymous »

Ich verwende node.js, ich möchte eine Datei an Slack senden. Ich verwende GetUploadurlexTernal und completeUploadexternal Funktionen. Meine erste Meldung (erfasstes Vorfall .....) wurde in der Kanal und der Datei auch erfolgreich gespeichert, da ich in den Protokollen, die ich gespeichert habe, in dem von mir erwähnten Kanal, den ich erwähnt habe, nicht angezeigt wurde.

Code: Select all

const messageRes = await web.chat.postMessage({
channel: "#jr-developers",
text: "🚨 Incident detected! Please check the attached report below.",
});

console.log("Message sent:", messageRes.ts);
// console.log(messageRes);

// Step 3: Upload file content to the URL using axios
const fileName = "continent.csv";
const fileBuffer = fs.readFileSync(fileName);
const fileLength = fileBuffer.length;

// Step 2: Get upload URL from Slack
const uploadURLRes = await web.files.getUploadURLExternal({
filename: fileName,
length: fileLength,
});

const uploadUrl = uploadURLRes.upload_url;
const fileId = uploadURLRes.file_id;

console.log("Received upload URL from Slack.", uploadUrl, fileId);

await axios.put(uploadUrl, fileBuffer, {
headers: {
"Content-Type": "application/octet-stream",
"Content-Length": fileLength,
},
});

console.log("File uploaded to Slack storage.");
// console.log(axiosRes);

// Step 4: Complete the upload and share in thread
const res = await web.files.completeUploadExternal({
files: [
{
id: fileId,
title: "slack-test",
},
],
channel_id: messageRes.channel,
thread_ts: messageRes.ts,
});

console.log("File attached to thread successfully.");
Dies sind die Protokolle,
{
ok: true,
files: [
{
id: 'F0****J3A',
created: ***,
timestamp: ***,
name: 'continent.csv',
title: 'slack-test',
mimetype: '',
filetype: '',
pretty_type: '',
user: '***',
user_team: '***',
editable: false,
size: 86,
mode: 'hosted',
is_external: false,
external_type: '',
is_public: false,
public_url_shared: false,
display_as_bot: false,
username: '',
url_private: 'https://files.slack.com/files-pri******continent.csv',
url_private_download: 'https://files.slack.com/files-pri*****d ... tinent.csv',
media_display_type: 'unknown',
permalink: 'https://profitops.slack.com/files****continent.csv',
permalink_public: 'https://slack-files.com/*****',
comments_count: 0,
is_starred: false,
shares: {},
channels: [],
groups: [],
ims: [],
has_more_shares: false,
has_rich_preview: false,
file_access: 'visible'
}
],
response_metadata: {
scopes: [
'identify', 'channels:history',
'groups:history', 'im:history',
'mpim:history', 'channels:read',
'groups:read', 'im:read',
'mpim:read', 'users:read',
'channels:write', 'chat:write',
'files:write', 'groups:write',
'im:write', 'mpim:write',
'identity.basic', 'identity.email',
'identity.avatar'
],
acceptedScopes: [ 'files:write' ]
}
}
File attached to thread successfully.
< /code>
Ich habe alles überprüft. Bitte helfen Sie.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post