aboutsummaryrefslogtreecommitdiff
path: root/vnext
diff options
context:
space:
mode:
Diffstat (limited to 'vnext')
-rw-r--r--vnext/server/durov.js12
-rw-r--r--vnext/server/index.js4
2 files changed, 15 insertions, 1 deletions
diff --git a/vnext/server/durov.js b/vnext/server/durov.js
index acd891587..df33f7433 100644
--- a/vnext/server/durov.js
+++ b/vnext/server/durov.js
@@ -7,13 +7,23 @@ import config from 'config';
import { formatQuote, formatTitle } from './common/MessageUtils';
import { format } from '../src/utils/embed';
-const sender = new TelegramBot(config.get('service.durov.token'), { polling: true });
+const bot_token = config.get('service.durov.token');
+
+const sender = new TelegramBot(bot_token);
const demouser = config.get('service.durov.demouser');
+sender.setWebHook(`${config.get('service.baseURL')}/api/${bot_token}`).then(() => {
+ log('Webhook is set');
+}).catch(console.log);
sender.on('message', msg => {
log(`MESSAGE: ${JSON.stringify(msg)}`);
});
+export const webhook = (req, res) => {
+ sender.processUpdate(JSON.parse(req.body));
+ res.sendStatus(200);
+};
+
/**
* @param {import('../src/api').Message} msg
* @param {string[]} subscribers
diff --git a/vnext/server/index.js b/vnext/server/index.js
index 891220698..b4c637bf8 100644
--- a/vnext/server/index.js
+++ b/vnext/server/index.js
@@ -10,8 +10,11 @@ import event from './middleware/event';
import oembed from './middleware/oembed';
import urlExpand from './middleware/urlexpand';
+const bot_token = config.get('service.durov.token');
+
const PORT = 8081;
import path from 'path';
+import { webhook } from './durov';
// initialize the application and create the routes
const app = express();
@@ -22,6 +25,7 @@ const router = express.Router();
router.post('/api/sender', event);
router.get('/api/oembed', oembed);
router.get('/api/urlexpand', urlExpand);
+router.post(`/api/${bot_token}`, webhook);
router.use('^/$', serverRenderer);
const STATIC_ROOT = config.get('service.static_root') || path.resolve(__dirname, 'public');