0

I need to share/send files via slack. I created an app, and I can send message successfully, but I can send files

This is my code

var client1 = new SlackClient("https://hooks.slack.com/services/XXXXXXXXXXXXXX");
        var slackMessage = new SlackMessage
        {
            Channel = "#test",
            Text = "test",
            IconEmoji = Slack.Webhooks.Emoji.Octocat,                
        };

         client1.Post(slackMessage);

Thank you for your help

user1817661
  • 83
  • 1
  • 6

1 Answers1

0

You can't send file through slack webhook as mentioned here

Here you have thread with examples how to do that by slack files api

public void UploadFile(string token, string filePath, string channel)
{
var client = new RestClient("https://slack.com");

var request = new RestRequest("api/files.upload", Method.POST);
request.AddParameter("token", token);
request.AddParameter("channels", channel);

var fileInfo = new FileInfo(filePath);
request.AddFile("file", File.ReadAllBytes(filePath), fileInfo.Name, contentType:"multipart/form-data");

//Execute the request
var response = client.Execute(request);
var content = response.Content;
}

by @ive2

Wojna
  • 136
  • 1
  • 17