@nitra/telegram 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/index.js +7 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitra/telegram",
|
|
3
3
|
"description": "telegram helper",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"files": [
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"homepage": "https://github.com/nitra/telegram",
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@nitra/
|
|
27
|
-
"@nitra/
|
|
26
|
+
"@nitra/check-env": "^3.2.0",
|
|
27
|
+
"@nitra/pino": "^1.5.1"
|
|
28
28
|
},
|
|
29
29
|
"engines": {
|
|
30
30
|
"node": ">=22.0.0"
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { checkEnv } from '@nitra/check-env'
|
|
2
|
+
import { log } from '@nitra/pino'
|
|
3
3
|
import { env } from 'node:process'
|
|
4
4
|
|
|
5
5
|
checkEnv(['TELEGRAM_BOT_TOKEN', 'TELEGRAM_CHAT_ID'])
|
|
@@ -8,15 +8,17 @@ export const MAX_TELEGRAM_MSG_LENGTH = 4096
|
|
|
8
8
|
|
|
9
9
|
export const sendMessage = async (text, params) => {
|
|
10
10
|
const currentHour = new Date().getHours()
|
|
11
|
-
if (currentHour >= 8 && currentHour <= 18) {
|
|
11
|
+
if (process.env.TELEGRAM_ROUND_CLOCK || (currentHour >= 8 && currentHour <= 18)) {
|
|
12
12
|
// Max length of a Telegram message is 4096 characters
|
|
13
13
|
if (text >= MAX_TELEGRAM_MSG_LENGTH) {
|
|
14
14
|
text = text.slice(0, MAX_TELEGRAM_MSG_LENGTH)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
let url = `https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage?chat_id=${
|
|
17
|
+
let url = `https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage?chat_id=${
|
|
18
|
+
env.TELEGRAM_CHAT_ID
|
|
19
|
+
}&text=${encodeURIComponent(text)}`
|
|
18
20
|
|
|
19
|
-
if (params
|
|
21
|
+
if (params?.parse_mode?.toLowerCase() === 'html') {
|
|
20
22
|
url += '&parse_mode=HTML'
|
|
21
23
|
}
|
|
22
24
|
let res
|