mirror of
https://github.com/plankanban/planka.git
synced 2025-07-24 07:39:44 +02:00
Added new custom service with telegram integration helper functions
Co-authored-by: Elllone <elllone@diklosgroup.ru> on-behalf-of: @DiklosGroup <contact@diklosgroup.ru>
This commit is contained in:
parent
c1c415d4d3
commit
90a4cf27ef
1 changed files with 38 additions and 0 deletions
38
server/api/helpers/utils/send-telegram-message.js
Normal file
38
server/api/helpers/utils/send-telegram-message.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
const POST_MESSAGE_API_URL = (telegramBotToken) =>
|
||||
`https://api.telegram.org/bot${telegramBotToken}/sendMessage`;
|
||||
|
||||
module.exports = {
|
||||
inputs: {
|
||||
html: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
async fn(inputs) {
|
||||
const headers = {
|
||||
'Content-Type': 'application/json; charset=utf-8',
|
||||
};
|
||||
|
||||
const body = {
|
||||
chat_id: sails.config.custom.telegramChatId,
|
||||
text: inputs.html,
|
||||
parse_mode: 'HTML',
|
||||
};
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(POST_MESSAGE_API_URL(sails.config.custom.telegramBotToken), {
|
||||
headers,
|
||||
method: 'POST',
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
} catch (error) {
|
||||
sails.log.error(`Error sending to Telegram: ${error}`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
const responseErrorJson = await response.json();
|
||||
sails.log.error(`Error sending to Telegram: ${responseErrorJson.description}`);
|
||||
}
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue