diff --git a/index.js b/index.js index 34fa95f..14b536d 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,10 @@ const TelegramBot = require('node-telegram-bot-api'); +const request = require('request') const port = process.env.PORT || 443, host = '0.0.0.0', // probably this change is not required - externalUrl = process.env.HOSTURL, - token = process.env.TOKEN || 'YOUR TELEGRAM TOKEN', + externalUrl = 'https://pokemnbot.herokuapp.com', + token = process.env.TOKEN || '876379827:AAEp3CyGAd0QQI7PJKzCXjBGN_PMo8mVFak', bot = new TelegramBot(token, { webHook: { port: port, @@ -11,3 +12,24 @@ const port = process.env.PORT || 443, } }); bot.setWebHook(externalUrl + ':443/bot' + token); + +bot.on('message', (msg) => { + const chatId = msg.chat.id + console.log(msg.text) + + request("https://pokeapi.co/api/v2/pokemon/" + msg.text.toLowerCase(),function(err,body,response){ + + if(response == "Not Found") { + bot.sendMessage(chatId,"Not found") + return + } + + let data = JSON.parse(response) + for(let i =0; i < data.abilities.length; i++) { +console.log(data.abilities[i]) + bot.sendMessage(chatId,data.abilities[i].ability.name) + } + +}) + +}) diff --git a/package.json b/package.json index adaf530..527179b 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "homepage": "https://github.com/ghostpirate/pokebot#readme", "dependencies": { - "node-telegram-bot-api": "^0.30.0" + "node-telegram-bot-api": "^0.30.0", + "request":"^2.88.0" } }