mirror of
https://github.com/plankanban/planka.git
synced 2025-08-05 21:45:30 +02:00
feat: add sendGoogleChatMessage util function
This commit is contained in:
parent
67f4c66ff0
commit
c7d201baaf
1 changed files with 41 additions and 0 deletions
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}`);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
Loading…
Add table
Add a link
Reference in a new issue