2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-23 10:27:49 +00:00
node-telegram-bot-api/examples/openShiftWebHook.js
GochoMugo 0174b875ff
[examples] Update examples
Feature:

  * Add example demonstrating use of inline keyboards
    and callback queries (see PR #150)
  * Use token from environment variable, if available

References:

  * PR #150 - Provided example with inline keyboard and callbacks:
    https://github.com/yagop/node-telegram-bot-api/pull/150
2017-01-07 18:30:07 +03:00

33 lines
1003 B
JavaScript

/**
* This example demonstrates setting up webhook
* on the OpenShift platform.
*/
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
const TelegramBot = require('..');
// See https://developers.openshift.com/en/node-js-environment-variables.html
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}`);
// Just to ping!
bot.on('message', function onMessage(msg) {
bot.sendMessage(msg.chat.id, "I'm alive on OpenShift!");
});