2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-23 02:17:16 +00:00

31 lines
802 B
JavaScript
Raw Normal View History

2017-01-07 12:44:29 +03:00
/**
* This example demonstrates setting up a webook, using a
* self-signed certificate.
*/
2015-06-29 00:37:40 +02:00
2017-01-07 12:44:29 +03:00
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
2017-12-07 12:30:44 +03:00
const TelegramBot = require('../..');
2017-01-07 12:44:29 +03:00
const options = {
2015-06-29 00:37:40 +02:00
webHook: {
port: 443,
key: `${__dirname}/../ssl/key.pem`, // Path to file with PEM private key
cert: `${__dirname}/../ssl/crt.pem` // Path to file with PEM certificate
2015-06-29 00:37:40 +02:00
}
};
2017-01-07 12:44:29 +03:00
// This URL must route to the port set above (i.e. 443)
const url = 'https://<PUBLIC-URL>';
const bot = new TelegramBot(TOKEN, options);
// This informs the Telegram servers of the new webhook.
bot.setWebHook(`${url}/bot${TOKEN}`, {
certificate: options.webHook.cert,
});
2015-06-29 00:37:40 +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!');
2017-01-07 12:44:29 +03:00
});