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 +1 -1
- package/io-package.json +2 -2
- package/main.js +54 -19
- package/package.json +1 -1
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.
|
|
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.
|
|
4
|
+
"version": "1.15.5",
|
|
5
5
|
"news": {
|
|
6
|
-
"1.15.
|
|
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-
|
|
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
|
|
950
|
-
if (text
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
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)
|
|
1816
|
-
.
|
|
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
|
-
|
|
1841
|
-
|
|
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