@nitra/telegram 1.1.1 → 1.1.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +5 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nitra/telegram",
3
3
  "description": "telegram helper",
4
- "version": "1.1.1",
4
+ "version": "1.1.2",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "files": [
package/src/index.js CHANGED
@@ -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=${env.TELEGRAM_CHAT_ID}&text=${text}`
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.parse_mode.toLowerCase() === 'html') {
21
+ if (params?.parse_mode?.toLowerCase() === 'html') {
20
22
  url += '&parse_mode=HTML'
21
23
  }
22
24
  let res