aboutsummaryrefslogtreecommitdiff
path: root/vnext/server/durov.js
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-13 10:28:31 +0300
committerGravatar Vitaly Takmazov2023-01-14 10:06:45 +0300
commite3c378cbf1d502263c61d3b9c31cd270bc3ae239 (patch)
tree9e038f42349671407e6f5906681de6448565f8eb /vnext/server/durov.js
parentd94eec89b104e5c839d76c74ce94e83960d49c31 (diff)
vnext: Telegram bot (WIP)
Diffstat (limited to 'vnext/server/durov.js')
-rw-r--r--vnext/server/durov.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/vnext/server/durov.js b/vnext/server/durov.js
new file mode 100644
index 00000000..0f70133d
--- /dev/null
+++ b/vnext/server/durov.js
@@ -0,0 +1,33 @@
+import TelegramBot from 'node-telegram-bot-api';
+import debug from 'debug';
+var log = debug('durov');
+import config from 'config';
+
+
+import { formatMessage, formatQuote, formatTitle } from './common/MessageUtils';
+import { format } from '../src/utils/embed';
+
+const sender = new TelegramBot(config.get('service.durov.token'), { polling: true });
+const demouser = config.get('service.durov.demouser');
+
+sender.on('message', msg => {
+ log(`MESSAGE: ${JSON.stringify(msg)}`);
+});
+
+/**
+ * @param {import('../src/api').Message} msg
+ * @param {string[]} subscribers
+ */
+export const sendTelegramNotification = (msg, subscribers) => {
+ log(`Telegram event: ${JSON.stringify(msg)}, ${subscribers} ${subscribers.length}`);
+ if (!msg.service) {
+ if (subscribers && subscribers.includes(demouser)) {
+ const message = `${formatTitle(msg)}\n${formatQuote(msg)}\n${format(msg.body, msg.uid, false)}`;
+ log(message);
+ sender.sendMessage(demouser, message, {
+ parse_mode: 'HTML',
+ disable_web_page_preview: true
+ }).then(log).catch(log);
+ }
+ }
+};