app.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const TelegramBot = require("node-telegram-bot-api");
  2. // replace the value below with the Telegram token you receive from @BotFather
  3. const TOKEN = "AAHk_qlAnVQX2xjUUUFMnKzSuX3knHOidYY";
  4. /*
  5. Use this token to access the HTTP API:
  6. 7542722102:AAHk_qlAnVQX2xjUUUFMnKzSuX3knHOidYY
  7. */
  8. // Create a bot that uses 'polling' to fetch new updates
  9. // const bot = new TelegramBot(token, { polling: true });
  10. const options = {
  11. webHook: {
  12. // Just use 443 directly
  13. port: 443,
  14. },
  15. };
  16. // You can use 'now alias <your deployment url> <custom url>' to assign fixed
  17. // domain.
  18. // See: https://zeit.co/blog/now-alias
  19. // Or just use NOW_URL to get deployment url from env.
  20. const url = 'https://bot.10adyp.top/webHook' || process.env.NOW_URL;
  21. const bot = new TelegramBot(TOKEN, options);
  22. // This informs the Telegram servers of the new webhook.
  23. // Note: we do not need to pass in the cert, as it already provided
  24. bot.setWebHook(`${url}/bot${TOKEN}`);
  25. // Just to ping!
  26. bot.on('message', function onMessage(msg) {
  27. bot.sendMessage(msg.chat.id, 'I am alive on Zeit Now!');
  28. });