You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
node-telegram-bot-api/examples/httpsWebHook.js

30 lines
786 B

/**
* This example demonstrates setting up a webook, using a
* self-signed certificate.
*/
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
const TelegramBot = require('..');
const options = {
webHook: {
port: 443,
key: `${__dirname}/key.pem`, // Path to file with PEM private key
cert: `${__dirname}/crt.pem` // Path to file with PEM certificate
}
};
// 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,
});
// Just to ping!
bot.on('message', function onMessage(msg) {
bot.sendMessage(msg.chat.id, "I'm alive!");
});