Skip to content

Instantly share code, notes, and snippets.

@taciturnaxolotl
Created December 12, 2024 03:30
Show Gist options
  • Select an option

  • Save taciturnaxolotl/309d1f7a35e1675e7700294f25bb5a91 to your computer and use it in GitHub Desktop.

Select an option

Save taciturnaxolotl/309d1f7a35e1675e7700294f25bb5a91 to your computer and use it in GitHub Desktop.
Watermark your messages in slack via Proxypin
console.log("Request handler started");
async function onRequest(context, request) {
console.log("Incoming request:", context);
if (!context.session.channelHistory) {
context.session.channelHistory = [];
}
const k = JSON.parse(request.body);
const k2 = JSON.parse(k.blocks);
const channelId = k.channel;
const now = Date.now();
const lastMessage = context.session.channelHistory.find(
(msg) => msg.channelId === channelId,
);
const lastMessageTime = lastMessage ? lastMessage.timestamp : 0;
if (now - lastMessageTime > 1800000) {
k2.push({
type: "divider",
});
k2.push({
type: "context",
elements: [
{
type: "mrkdwn",
text: "_sent from ios_",
},
],
});
}
context.session.channelHistory = context.session.channelHistory.filter(
(msg) => msg.channelId !== channelId,
);
context.session.channelHistory.push({
channelId,
timestamp: now,
});
k.blocks = JSON.stringify(k2);
request.body = JSON.stringify(k);
return request;
}
async function onResponse(context, request, response) {
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment