iobroker.telegram 1.15.3 → 1.15.5

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/README.md CHANGED
@@ -26,7 +26,7 @@ Use Telegram service to communicate with ioBroker
26
26
  Placeholder for the next version (at the beginning of the line):
27
27
  ### **WORK IN PROGRESS**
28
28
  -->
29
- ### 1.15.3 (2023-02-16)
29
+ ### 1.15.5 (2023-02-16)
30
30
  * (bluefox) Added possibility to set `parse_mode` in the text message
31
31
 
32
32
  ### 1.15.2 (2022-11-04)
package/io-package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "telegram",
4
- "version": "1.15.3",
4
+ "version": "1.15.5",
5
5
  "news": {
6
- "1.15.3": {
6
+ "1.15.5": {
7
7
  "en": "Added possibility to set `parse_mode` in the text message",
8
8
  "de": "Möglichkeit zur Einstellung parse_mode in der Textnachricht",
9
9
  "ru": "Добавлена возможность установки parse_mode в текстовом сообщении",
package/main.js CHANGED
@@ -2,7 +2,7 @@
2
2
  *
3
3
  * ioBroker telegram Adapter
4
4
  *
5
- * Copyright (c) 2016-2022 bluefox <dogafox@gmail.com>
5
+ * Copyright (c) 2016-2023 bluefox <dogafox@gmail.com>
6
6
  *
7
7
  * MIT License
8
8
  *
@@ -946,18 +946,21 @@ function _sendMessageHelper(dest, name, text, options) {
946
946
  });
947
947
  }
948
948
  } else {
949
- adapter.log.debug(`Send message to "${name}": ${text}`);
950
- if (text.startsWith('<MarkdownV2>') && text.endsWith('</MarkdownV2>')) {
951
- options = options || {};
952
- options.parse_mode = 'MarkdownV2';
953
- } else
954
- if (text.startsWith('<HTML>') && text.endsWith('</HTML>')) {
955
- options = options || {};
956
- options.parse_mode = 'HTML';
957
- } else
958
- if (text.startsWith('<Markdown>') && text.endsWith('</Markdown>')) {
959
- options = options || {};
960
- options.parse_mode = 'Markdown';
949
+ adapter.log.debug(`Send message to [${name}]: "${text}"`);
950
+ if (text && typeof text === 'string') {
951
+ if (text.startsWith('<MarkdownV2>') && text.endsWith('</MarkdownV2>')) {
952
+ options = options || {};
953
+ options.parse_mode = 'MarkdownV2';
954
+ text = text.substring(12, text.length - 13);
955
+ } else if (text.startsWith('<HTML>') && text.endsWith('</HTML>')) {
956
+ options = options || {};
957
+ options.parse_mode = 'HTML';
958
+ text = text.substring(6, text.length - 7);
959
+ } else if (text.startsWith('<Markdown>') && text.endsWith('</Markdown>')) {
960
+ options = options || {};
961
+ options.parse_mode = 'Markdown';
962
+ text = text.substring(10, text.length - 11);
963
+ }
961
964
  }
962
965
 
963
966
  bot && bot.sendMessage(dest, text || '', options)
@@ -1013,6 +1016,21 @@ function sendMessage(text, user, chatId, options) {
1013
1016
 
1014
1017
  options = options || {};
1015
1018
 
1019
+ if (text && typeof text === 'string') {
1020
+ if (text && text.startsWith('<MarkdownV2>') && text.endsWith('</MarkdownV2>')) {
1021
+ options.parse_mode = 'MarkdownV2';
1022
+ text = text.substring(12, text.length - 13);
1023
+ } else
1024
+ if (text && text.startsWith('<HTML>') && text.endsWith('</HTML>')) {
1025
+ options.parse_mode = 'HTML';
1026
+ text = text.substring(6, text.length - 7);
1027
+ } else
1028
+ if (text && text.startsWith('<Markdown>') && text.endsWith('</Markdown>')) {
1029
+ options.parse_mode = 'Markdown';
1030
+ text = text.substring(10, text.length - 11);
1031
+ }
1032
+ }
1033
+
1016
1034
  let tPromiseList = [];
1017
1035
  // convert
1018
1036
  if (text !== undefined && text !== null && typeof text !== 'object') {
@@ -1024,8 +1042,7 @@ function sendMessage(text, user, chatId, options) {
1024
1042
  .then(results =>
1025
1043
  results.reduce((e, acc) => acc + e, 0))
1026
1044
  .catch(e => e);
1027
- }
1028
- else if (user) {
1045
+ } else if (user) {
1029
1046
  if (typeof user !== 'string' && !(user instanceof Array)) {
1030
1047
  adapter.log.warn(`Invalid type of user parameter: ${typeof user}. Expected is string or array.`);
1031
1048
  }
@@ -1812,8 +1829,10 @@ function processTelegramText(msg) {
1812
1829
  m = null;
1813
1830
  }
1814
1831
  if (msg) {
1815
- if (err) bot.sendMessage(msg.from.id, err)
1816
- .catch(error => adapter.log.error(`send Message Error: ${error}`));
1832
+ if (err) {
1833
+ bot.sendMessage(msg.from.id, err)
1834
+ .catch(error => adapter.log.error(`send Message Error: ${error}`));
1835
+ }
1817
1836
  if (state) {
1818
1837
  bot.sendMessage(msg.from.id, state.val.toString())
1819
1838
  .catch(error => adapter.log.error(`send Message Error: ${error}`));
@@ -1837,8 +1856,24 @@ function processTelegramText(msg) {
1837
1856
  user
1838
1857
  }, response => {
1839
1858
  if (response && response.response) {
1840
- adapter.log.debug(`Send response: ${response.response}`);
1841
- bot.sendMessage(response.id, response.response).catch(error => adapter.log.error(`send Message Error: ${error}`));
1859
+ let text = response.response;
1860
+ let options;
1861
+ if (text && typeof text === 'string') {
1862
+ if (text.startsWith('<MarkdownV2>') && text.endsWith('</MarkdownV2>')) {
1863
+ options = {parse_mode: 'MarkdownV2'};
1864
+ text = text.substring(12, text.length - 13);
1865
+ } else if (text.startsWith('<HTML>') && text.endsWith('</HTML>')) {
1866
+ options = {parse_mode: 'HTML'};
1867
+ text = text.substring(6, text.length - 7);
1868
+ } else if (text.startsWith('<Markdown>') && text.endsWith('</Markdown>')) {
1869
+ options = {parse_mode: 'Markdown'};
1870
+ text = text.substring(10, text.length - 11);
1871
+ }
1872
+ }
1873
+
1874
+ adapter.log.debug(`Send response: ${text}`);
1875
+ bot.sendMessage(response.id, text, options)
1876
+ .catch(error => adapter.log.error(`send Message Error: ${error}`));
1842
1877
  }
1843
1878
  });
1844
1879
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "iobroker.telegram",
3
3
  "description": "The adapter allows to send and receive telegram messages from ioBroker and to be a broker.",
4
- "version": "1.15.3",
4
+ "version": "1.15.5",
5
5
  "author": {
6
6
  "name": "bluefox",
7
7
  "email": "dogafox@gmail.com"