slackapi / node-slack-sdk

Slack Developer Kit for Node.js
https://slack.dev/node-slack-sdk
MIT License
3.27k stars 659 forks source link

files.uploadV2 returning inconsistent response #1865

Open parthks13 opened 1 month ago

parthks13 commented 1 month ago

Packages:

@slack/bolt": "^3.11.0"

Reproducible in: Its happening intermittently.

Node.js runtime version - 14.17.0

I have an application which is used to post a slack message containing a file to a channel. After posting the message, it also sends another message in thread. To get the thread id of the original thread, I use result of files.uploadV2. But in some random scenarios, it sends an inconsistent response where the application cant find the thread id and hence fails.

` // Upload file and post initial message

    const result = await client.files.uploadV2({
      channel_id: SLACK_CHANNEL,
      content: formData.userOncallDescr,
      filename: `oncall-screening-case-${formData.userCaseNum}.txt`,
      initial_comment: message,
    });
if (result.ok) {
  const [firstFile] = result.files;
  const [firstSubFile] = firstFile.files;
  const { shares: { private: privateShares } } = firstSubFile;
  const channelShares = privateShares['ABCDEF'];` // this is the part which fails randomly

this is the error - Cannot read property 'ABCDEF' of undefined, suggesting the field is missing in the response.

Please can someone help me in understanding why it might be happening / how to fix / alternate approach?

hello-ashleyintech commented 1 month ago

Hi, @parthks13! Thanks for reaching out 🙌

Are you able to send both a successful response where you get no error as well as an unsuccessful response where you do get the mentioned error? This will help me compare what might be deviating in the two calls.

parthks13 commented 1 month ago

Hey @hello-ashleyintech Yes in both the cases the I am able to successfully post the slack message along with the file. In other words, result.ok always comes true but after that the issue comes where I cannot access private shares.

Thanks for the response.

seratch commented 1 month ago

Hi @parthks13, the files.upload v2 method completes the process asynchronously for resource efficiency and performance reasons. If your app needs to continue doing something else right after the files are shared in a channel, please consider polling the files.info API with the file IDs until the "shares" property appears. See also:

github-actions[bot] commented 1 week ago

👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.