简体   繁体   English

发布消息到松弛

[英]Post a message to slack

I want to post a message to slack on x channel I need to send the following x parameters how do I send the following parameters to a website 我想在x频道上发布一条消息,以发送给我,我需要发送以下x参数如何将以下参数发送到网站

"channel": "XXXXX", "token": "token", "text": "text" “频道”:“ XXXXX”,“令牌”:“令牌”,“文本”:“文本”

I am coding in c# mvc application. 我在c#mvc应用程序中编码。

public async Task<HttpResponseMessage> SendMessageAsync(string message, string channel = null, string userName = null)
{
    using (var client = new HttpClient())
    {
        string url = "https://fake2604.slack.com/api/chat.postMessage?token=myToken&channel=" + channel + "&text=Hello World";

        var payLoad = new
        {
            text = message,
                   channel,
                   userName,
        };

        var serializedPayload = JsonConvert.SerializeObject(payLoad);

        var response = await client.PostAsync(url, new StringContent(serializedPayload, Encoding.UTF8, "application/json"));
        return response;
    }
}

This is not working.It just adds an integration to the channel that I select in the OAuth page which again I got through Add to Slack button. 这是行不通的,它只是向我在OAuth页面中选择的渠道添加了集成,再次通过添加到松弛按钮获得了渠道。

I suppose the problem is with your webhook url which you are adding some more stuff to that.this code definitely work: 我想问题出在您的webhook网址上,您正在向其中添加更多内容。此代码肯定有效:

 public async Task<HttpResponseMessage> SendMessageAsync(string message)
    {
        var payload = new
        {
            text = message,
            channel="x",
            userName="y",
        };
        HttpClient httpClient = new HttpClient();
        var serializedPayload = serializer.ToJson(payload);
        var response = await httpClient.PostAsync("url",
            new StringContent(serializedPayload, Encoding.UTF8, "application/json"));
        return response;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM