Create New App
1. Create New App填入 App Name 及 選擇 workspace
2. 維護 Base Information
維護 App Name & Short description & App icon & background color
3. 維護 Oauth & Permissions
Add an Oauth Scope
incoming-webhook
channels:read
This scope lets an app "View basic information about public channels in the workspace"
chat:write:bot
This scope lets an app "Send messages as your slack app"
4. Install App into your workspace
Code Example
Send messages exampleDotNet Code Send Message 2 Slack
private void send2stalck(string path,string query,string header,string body,string message)
{
Dictionary dictQuery = new Dictionary();
dictQuery.Add("channel", @"slack channel");
dictQuery.Add("token", @"slack token");
dictQuery.Add("text", message);
JArray jaFields = new JArray();
var joEnv = new JObject() { { "title", "env" }, { "value", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") }, { "short", true } };
var joPath = new JObject() { { "title", "path" }, { "value", path }, { "short", true } };
var joTimestamp = new JObject() { { "title", "timestamp" }, { "value", System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }, { "short", true } };
var joQuery = new JObject() { { "title", "query parameter" }, { "value", query }, { "short", true } };
var joHeader = new JObject() { { "title", "header parameter" }, { "value", header }, { "short", false } };
var joBody = new JObject() { { "title", "body" }, { "value", body }, { "short", false } };
var joMessage = new JObject() { { "title", "message" }, { "value", message }, { "short", false } };
jaFields.Add(joEnv);
jaFields.Add(joPath);
jaFields.Add(joTimestamp);
jaFields.Add(joQuery);
jaFields.Add(joHeader);
jaFields.Add(joBody);
jaFields.Add(joMessage);
JObject joField = new JObject() { { "fields", jaFields } };
JArray ja = new JArray();
ja.Add(joField);
string strAttachments = JsonConvert.SerializeObject(ja);
dictQuery.Add("attachments", WebUtility.UrlEncode(strAttachments));
httpReqService service = new httpReqService().WithSlack();
JObject joReturn = service.sendRequest("/chat.postMessage", "GET", dictQuery, null, null);
}
留言
張貼留言