Code Monkey home page Code Monkey logo

Comments (7)

filmaj avatar filmaj commented on July 18, 2024 2

@theshdb totally understand, and I mirror your sentiment and I have raised it internally. However, I am only one voice internally and many considerations go into what we do or do not do with the APIs. Priority and product decisions are made by leadership above my paygrade, unfortunately, however, leadership does pay attention to customer feedback that comes in via emails to [email protected]. Please consider emailing there and telling them you have a feature request / complaint about the deprecated API and what you'd like to see as a customer with regards to the new API.

As for retrieving the DM ID, you can use the conversations.open API and provide the U.... encoded user ID as part of the users argument. That should return a payload that looks like:

{
    "ok": true,
    "no_op": true,
    "already_open": true,
    "channel": {
        "id": "D05TKNSGFL3"
    }
}

from bolt-js.

theshdb avatar theshdb commented on July 18, 2024 1

Thanks for the clarification @filmaj. I'm aware of this functionality. However, my concern is that the deprecated method files.upload allowed us to use Slack userId to post a file in a direct message. So, why are we no longer supporting it in the new API? Can we not update the regex to include U?

If no, then is it possible to retrieve a direct message ID using the Slack user ID via an API?

from bolt-js.

theshdb avatar theshdb commented on July 18, 2024 1

Got it @filmaj. Thanks for providing the solution on how to get the direct message ID.

This is what I'm using now as an alternate solution to post a file to a DM using a Slack user ID.

if (channelId.startsWith("U")) {
          const conversationsResponse = await web.conversations.open({
            users: channelId,
          });
          channelId = conversationsResponse.channel.id;
        }

from bolt-js.

filmaj avatar filmaj commented on July 18, 2024 1

Great, glad you got it working. I will close this issue now but if there are any more questions here feel free to re-open or file a new issue.

from bolt-js.

filmaj avatar filmaj commented on July 18, 2024

Have you tried using the encoded D1234ABCD direct message ID instead of the U1234ABCD user ID to the channels list? As the error states, it does not allow passing user IDs into channel_id; this parameter only accepts encoded IDs for public channels , group and direct msgs (IDs that start with C, G, D and Z).

In the Slack client, if you click on a direct message header's user name and scroll all the way down, you should be able to find the D... encoded ID for a direct message that this API accepts:

Screenshot 2024-05-15 at 9 21 51 AM

from bolt-js.

william84531 avatar william84531 commented on July 18, 2024

@filmaj I got some problems I have upload the file to the server succeed,but I can not see the files in my channel. I have added the channel ID in my UploadPayload but it still didn't work

    // Step 2: Upload file
    using (var fileStream = new FileStream(screenshotPath, FileMode.Open, FileAccess.Read))
    {
        var fileContent = new StreamContent(fileStream);
        fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

        var uploadFileContent = new MultipartFormDataContent();
        uploadFileContent.Add(fileContent, "file", fileName);

        LogToFile($"上傳檔案的請求 URL: {uploadUrl}");

        var uploadResponse = await client.PutAsync(uploadUrl, uploadFileContent);
        var uploadResponseContent = await uploadResponse.Content.ReadAsStringAsync();
        if (!uploadResponse.IsSuccessStatusCode)
        {
            return;
        }
    }

    // Step 3: Complete Upload
    var completeUploadPayload = new
    {
        files = new[]
        {
    new
    {
        id = fileId,
        title = fileName
    }
},
        channel_id = "C076Q68GWTY"
    };

    var completeUploadPayloadJson = JsonConvert.SerializeObject(completeUploadPayload);
    var completeUploadContent = new StringContent(completeUploadPayloadJson, Encoding.UTF8, "application/json");

    var completeUploadResponse = await client.PostAsync("https://slack.com/api/files.completeUploadExternal", completeUploadContent);
    var completeUploadResponseContent = await completeUploadResponse.Content.ReadAsStringAsync();
    dynamic completeUploadResult = JsonConvert.DeserializeObject(completeUploadResponseContent);

    if (completeUploadResult.ok == false)
    {
        return;
    }

from bolt-js.

seratch avatar seratch commented on July 18, 2024

@william84531 The files should be shared in the channel members by the API call, but it's not visible because you haven't posted a message with them. You can add "initial_comment" parameter in addition to "channel_id" for posting a message with files.

If that's not the case, a different factor might be causing the issue. If so, I'd suggest trying any of the official Node/Python/Java SDKs first and then checking the difference in your C# code.

from bolt-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.