mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-22 18:07:16 +00:00
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
31 lines
786 B
JavaScript
31 lines
786 B
JavaScript
/**
|
|
* 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!");
|
|
});
|