mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-28 12:57:38 +00:00
examples: Add webhook example for Zeit Now
References: * Original PR #274: https://github.com/yagop/node-telegram-bot-api/pull/274 * PR-by: @Ferrari
This commit is contained in:
parent
d4a469df6b
commit
0441c99b97
32
examples/nowWebHook.js
Normal file
32
examples/nowWebHook.js
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* This example demonstrates setting up webhook on Zeit Now platform.
|
||||
* Attention: You have to use webhook with Zeit Now only, polling doesn't
|
||||
* work.
|
||||
*/
|
||||
|
||||
|
||||
const TOKEN = process.env.TELEGRAM_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN';
|
||||
const TelegramBot = require('..');
|
||||
const options = {
|
||||
webHook: {
|
||||
// Just use 443 directly
|
||||
port: 443
|
||||
}
|
||||
};
|
||||
// You can use 'now alias <your deployment url> <custom url>' to assign fixed
|
||||
// domain.
|
||||
// See: https://zeit.co/blog/now-alias
|
||||
// Or just use NOW_URL to get deployment url from env.
|
||||
const url = 'YOUR_DOMAIN_ALIAS' || process.env.NOW_URL;
|
||||
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 am alive on Zeit Now!');
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user