【问题标题】:How to send message to specific user from specific user with slack in dot net如何在 dot net 中使用 slack 从特定用户向特定用户发送消息
【发布时间】:2017-07-30 20:21:39
【问题描述】:

我曾尝试使用 chat.postmessage 方法在 slack 中以机器人用户的身份发送消息,并将用户 ID 放在频道的位置。我想从 slack 团队用户中的特定用户 ID 发送任何用户。

【问题讨论】:

  • 您的问题的描述非常广泛。请包括您尝试过的一些代码以及您可能收到的任何错误消息。这将帮助您获得答案。也请看How To Ask

标签: .net c#-4.0


【解决方案1】:

如果你有 Slack 机器人,你必须使用来自 Slack API 的Incoming Webhooks。您只需发送带有JSON 数据的网络请求,例如:

string exampleJson = " { \"text\": \"This is a line of text.\nAnd this is another one.\" }";

var http = (HttpWebRequest)WebRequest.Create(new Uri("YOUR-SLACK-WEBHOOK-URL"));
http.ContentType = "application/json";
http.Method = "POST";

Byte[] bytes = new ASCIIEncoding().GetBytes(exampleJson);

Stream newStream = http.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Close();

new StreamReader(http.GetResponse().GetResponseStream()).ReadToEnd();

【讨论】:

    猜你喜欢
    • 2019-07-24
    • 1970-01-01
    • 1970-01-01
    • 2014-08-14
    • 2015-04-27
    • 1970-01-01
    • 2017-01-13
    相关资源
    最近更新 更多