Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. const TelegramBot = require('node-telegram-bot-api');
  2.  
  3. // replace the value below with the Telegram token you receive from @BotFather
  4. const token = 'YOUR_TELEGRAM_BOT_TOKEN';
  5.  
  6. // Create a bot that uses 'polling' to fetch new updates
  7. const bot = new TelegramBot(token, {polling: true});
  8.  
  9. // Matches "/echo [whatever]"
  10. bot.onText(/\/echo (.+)/, (msg, match) => {
  11. // 'msg' is the received Message from Telegram
  12. // 'match' is the result of executing the regexp above on the text content
  13. // of the message
  14.  
  15. const chatId = msg.chat.id;
  16. const resp = match[1]; // the captured "whatever"
  17.  
  18. // send back the matched "whatever" to the chat
  19. bot.sendMessage(chatId, resp);
  20. });
  21.  
  22. // Listen for any kind of message. There are different kinds of
  23. // messages.
  24. bot.on('message', (msg) => {
  25. const chatId = msg.chat.id;
  26.  
  27. // send a message to the chat acknowledging receipt of their message
  28. bot.sendMessage(chatId, 'Received your message');
  29. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement