-
-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Telegram bot notifications (#928)
- Loading branch information
Showing
7 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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', | ||
}; | ||
|
||
if (sails.config.custom.telegramThreadId) { | ||
body.message_thread_id = sails.config.custom.telegramThreadId; | ||
} | ||
|
||
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}`); | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters