Slack - henk52/knowledgesharing GitHub Wiki
Slack
Introduction
Purpose
Recipies
Find messages where alpha mentioned beta
- ctlr-k
- @alpha from:@beta
slack applications
creating a slack-app in slack
Webhooks
Verify slack webhook
-
TODO if there are multiple jsons should I verify the header of each?
-
TODO how do I get the known secret, from the slack app thingy, from a secure storage so it is not part of the code?
-
TODO HMAC
The signature is created by hashing the request body with the SHA-256 function, and combining it with an HMAC signing secret. The resulting signature is unique to each request and doesn't contain any secret information, keeping your app secure.
function encodeFormData(data) {
const encodedData = Object.keys(data)
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
.join('&')
.replaceAll("%20", "+") // Slack does not encode "+" signs
.replaceAll("*", "%2A") // Slack encodes "*" signs
.replaceAll("~", "%7E"); // Slack encodes "~" signs
return encodedData;
}
function buildSignatureBaseString(requestJson) {
const version = "v0"; // Slack Webhook version (Always v0 for the moment)
const timestamp = requestJson.headers["x-slack-request-timestamp"];
const body = requestJson.body;
const encodedBody = encodeFormData(body);
const signatureBaseString = `${version}:${timestamp}:${encodedBody}`;
return signatureBaseString;
}
# TODO this only gets the first message, what about the rest of the messages?
const requestJson = $input.first().json;
const signatureBaseString = buildSignatureBaseString(requestJson);
const requestSignature = requestJson.headers["x-slack-signature"];
console.log({
signatureBaseString,
requestSignature
});
return {
json: {
signatureBaseString,
requestSignature
},
pairedItem: 0
}
Slack messaging
-
conversation -
-
thread -
- Before a message has any replies, we call it an unthreaded message.
- Once a message has replies, it becomes a parent message.
- Any child messages of that parent message are called threaded replies.
- The whole bundle of parent message and replies is referred to as a thread
- Each of the messages within a thread, whether parent or reply, is a threaded message.
-
if a user invokes one of your app's slash commands that performs some action on a third-party service, an ephemeral message might be the most suitable way to inform that user of the success of the action. https://docs.slack.dev/messaging/
TODO
- TODO write a local js script for sending messages to a channel
- TODO write code for receiving gitlab webhook
- TODO how to host a lambda locally
- TODO how to handle data handling like in n8n
- record the data?
- TODO how to find MR messages to add various bump operations
- https://docs.slack.dev/messaging/retrieving-messages/
- use 'user.info' ?