2017-01-07 12:44:29 +03:00
|
|
|
/**
|
|
|
|
* This example demonstrates setting up webhook
|
|
|
|
* on the OpenShift platform.
|
|
|
|
*/
|
2015-06-30 01:09:28 +02:00
|
|
|
|
2017-01-07 12:44:29 +03:00
|
|
|
|
2017-01-07 18:30:07 +03:00
|
|
|
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
|
2017-01-07 12:44:29 +03:00
|
|
|
const TelegramBot = require('..');
|
2015-08-01 17:57:21 +02:00
|
|
|
// See https://developers.openshift.com/en/node-js-environment-variables.html
|
2017-01-07 12:44:29 +03:00
|
|
|
const options = {
|
|
|
|
webHook: {
|
|
|
|
port: process.env.OPENSHIFT_NODEJS_PORT,
|
|
|
|
host: process.env.OPENSHIFT_NODEJS_IP,
|
|
|
|
// you do NOT need to set up certificates since OpenShift provides
|
|
|
|
// the SSL certs already (https://<app-name>.rhcloud.com)
|
|
|
|
},
|
|
|
|
};
|
|
|
|
// OpenShift routes from port :443 to OPENSHIFT_NODEJS_PORT
|
|
|
|
const domain = process.env.OPENSHIFT_APP_DNS;
|
|
|
|
const url = `${domain}:443`;
|
|
|
|
const bot = new TelegramBot(TOKEN, options);
|
|
|
|
|
|
|
|
|
|
|
|
// This informs the Telegram servers of the new webhook.
|
|
|
|
// Note: we do not need to pass in the cert, as it already provided
|
|
|
|
bot.setWebHook(`${url}/bot${TOKEN}`);
|
|
|
|
|
2015-06-30 01:09:28 +02:00
|
|
|
|
2017-01-07 12:44:29 +03:00
|
|
|
// Just to ping!
|
|
|
|
bot.on('message', function onMessage(msg) {
|
2017-01-29 18:59:05 +03:00
|
|
|
bot.sendMessage(msg.chat.id, 'I am alive on OpenShift!');
|
2015-06-30 01:09:28 +02:00
|
|
|
});
|