{"id":1277,"date":"2018-09-18T20:24:35","date_gmt":"2018-09-18T19:24:35","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=1277"},"modified":"2018-09-18T20:24:35","modified_gmt":"2018-09-18T19:24:35","slug":"node-telegram-bot-api","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/node-telegram-bot-api\/","title":{"rendered":"Node Telegram Bot Api"},"content":{"rendered":"<p>Source:\u00a0<a href=\"https:\/\/github.com\/yagop\/node-telegram-bot-api\">https:\/\/github.com\/yagop\/node-telegram-bot-api<\/a><\/p>\n<pre class=\"lang:js decode:true  \">const TelegramBot = require('node-telegram-bot-api');\r\n\r\n\/\/ replace the value below with the Telegram token you receive from @BotFather\r\nconst token = 'YOUR_TELEGRAM_BOT_TOKEN';\r\n\r\n\/\/ Create a bot that uses 'polling' to fetch new updates\r\nconst bot = new TelegramBot(token, {polling: true});\r\n\r\n\/\/ Matches \"\/echo [whatever]\"\r\nbot.onText(\/\\\/echo (.+)\/, (msg, match) =&gt; {\r\n  \/\/ 'msg' is the received Message from Telegram\r\n  \/\/ 'match' is the result of executing the regexp above on the text content\r\n  \/\/ of the message\r\n\r\n  const chatId = msg.chat.id;\r\n  const resp = match[1]; \/\/ the captured \"whatever\"\r\n\r\n  \/\/ send back the matched \"whatever\" to the chat\r\n  bot.sendMessage(chatId, resp);\r\n});\r\n\r\n\/\/ Listen for any kind of message. There are different kinds of\r\n\/\/ messages.\r\nbot.on('message', (msg) =&gt; {\r\n  const chatId = msg.chat.id;\r\n\r\n  \/\/ send a message to the chat acknowledging receipt of their message\r\n  bot.sendMessage(chatId, 'Received your message');\r\n});<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source:\u00a0https:\/\/github.com\/yagop\/node-telegram-bot-api const TelegramBot = require(&#8216;node-telegram-bot-api&#8217;); \/\/ replace the value below with the Telegram token you receive from @BotFather const token = &#8216;YOUR_TELEGRAM_BOT_TOKEN&#8217;; \/\/ Create a bot that uses &#8216;polling&#8217; to fetch new updates const bot = new TelegramBot(token, {polling: true}); \/\/ Matches &#8220;\/echo [whatever]&#8221; bot.onText(\/\\\/echo (.+)\/, (msg, match) =&gt; { \/\/ &#8216;msg&#8217; is the received [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1277","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=1277"}],"version-history":[{"count":1,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1277\/revisions"}],"predecessor-version":[{"id":1278,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/1277\/revisions\/1278"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=1277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=1277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=1277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}