mirror of
https://github.com/plankanban/planka.git
synced 2025-07-18 20:59:44 +02:00
feat: Google Chat notifications (#867)
This commit is contained in:
parent
9699fbe76a
commit
8fd0f682d9
6 changed files with 65 additions and 9 deletions
|
@ -72,6 +72,7 @@ services:
|
||||||
|
|
||||||
# - SLACK_BOT_TOKEN=
|
# - SLACK_BOT_TOKEN=
|
||||||
# - SLACK_CHANNEL_ID=
|
# - SLACK_CHANNEL_ID=
|
||||||
|
# - GOOGLE_CHAT_WEBHOOK_URL=
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
|
@ -61,6 +61,7 @@ SECRET_KEY=notsecretkey
|
||||||
|
|
||||||
# SLACK_BOT_TOKEN=
|
# SLACK_BOT_TOKEN=
|
||||||
# SLACK_CHANNEL_ID=
|
# SLACK_CHANNEL_ID=
|
||||||
|
# GOOGLE_CHAT_WEBHOOK_URL=
|
||||||
|
|
||||||
## Do not edit this
|
## Do not edit this
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ const valuesValidator = (value) => {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const buildAndSendSlackMessage = async (card, action, actorUser) => {
|
const buildAndSendMessage = async (card, action, actorUser, send) => {
|
||||||
const cardLink = `<${sails.config.custom.baseUrl}/cards/${card.id}|${card.name}>`;
|
const cardLink = `<${sails.config.custom.baseUrl}/cards/${card.id}|${card.name}>`;
|
||||||
|
|
||||||
let markdown;
|
let markdown;
|
||||||
|
@ -35,7 +35,7 @@ const buildAndSendSlackMessage = async (card, action, actorUser) => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await sails.helpers.utils.sendSlackMessage(markdown);
|
await send(markdown);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -94,10 +94,6 @@ module.exports = {
|
||||||
user: values.user,
|
user: values.user,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sails.config.custom.slackBotToken) {
|
|
||||||
buildAndSendSlackMessage(values.card, action, values.user);
|
|
||||||
}
|
|
||||||
|
|
||||||
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
|
const subscriptionUserIds = await sails.helpers.cards.getSubscriptionUserIds(
|
||||||
action.cardId,
|
action.cardId,
|
||||||
action.userId,
|
action.userId,
|
||||||
|
@ -119,6 +115,18 @@ module.exports = {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (sails.config.custom.slackBotToken) {
|
||||||
|
buildAndSendMessage(values.card, action, values.user, sails.helpers.utils.sendSlackMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sails.config.custom.googleChatWebhookUrl) {
|
||||||
|
buildAndSendMessage(
|
||||||
|
values.card,
|
||||||
|
action,
|
||||||
|
values.user,
|
||||||
|
sails.helpers.utils.sendGoogleChatMessage,
|
||||||
|
);
|
||||||
|
}
|
||||||
return action;
|
return action;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const buildAndSendSlackMessage = async (card, actorUser) => {
|
const buildAndSendMessage = async (card, actorUser, send) => {
|
||||||
await sails.helpers.utils.sendSlackMessage(`*${card.name}* was deleted by ${actorUser.name}`);
|
await send(`*${card.name}* was deleted by ${actorUser.name}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -56,7 +56,11 @@ module.exports = {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (sails.config.custom.slackBotToken) {
|
if (sails.config.custom.slackBotToken) {
|
||||||
buildAndSendSlackMessage(card, inputs.actorUser);
|
buildAndSendMessage(card, inputs.actorUser, sails.helpers.utils.sendSlackMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sails.config.custom.googleChatWebhookUrl) {
|
||||||
|
buildAndSendMessage(card, inputs.actorUser, sails.helpers.utils.sendGoogleChatMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
41
server/api/helpers/utils/send-google-chat-message.js
Normal file
41
server/api/helpers/utils/send-google-chat-message.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
module.exports = {
|
||||||
|
inputs: {
|
||||||
|
markdown: {
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
async fn(inputs) {
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json; charset=utf-8',
|
||||||
|
};
|
||||||
|
|
||||||
|
const body = {
|
||||||
|
text: inputs.markdown,
|
||||||
|
};
|
||||||
|
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await fetch(sails.config.custom.googleChatWebhookUrl, {
|
||||||
|
headers,
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
sails.log.error(`Error sending to Google Chat: ${error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
sails.log.error(`Error sending to Google Chat: ${response.error}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const responseJson = await response.json();
|
||||||
|
|
||||||
|
if (!responseJson.ok) {
|
||||||
|
sails.log.error(`Error sending to Google Chat: ${responseJson.error}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
|
@ -77,4 +77,5 @@ module.exports.custom = {
|
||||||
|
|
||||||
slackBotToken: process.env.SLACK_BOT_TOKEN,
|
slackBotToken: process.env.SLACK_BOT_TOKEN,
|
||||||
slackChannelId: process.env.SLACK_CHANNEL_ID,
|
slackChannelId: process.env.SLACK_CHANNEL_ID,
|
||||||
|
googleChatWebhookUrl: process.env.GOOGLE_CHAT_WEBHOOK_URL,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue