From 7d02862b0c4493e40c4450e877567b6c270b75ba Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 11:34:44 +0530 Subject: [PATCH 01/14] Update index.js --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 34fa95f..ca03b92 100644 --- a/index.js +++ b/index.js @@ -2,8 +2,8 @@ const TelegramBot = require('node-telegram-bot-api'); 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, From 1f336d493769fdb2c4a709944a4e68eab89cdea2 Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 11:38:41 +0530 Subject: [PATCH 02/14] Update index.js --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index ca03b92..cc16df7 100644 --- a/index.js +++ b/index.js @@ -11,3 +11,10 @@ const port = process.env.PORT || 443, } }); bot.setWebHook(externalUrl + ':443/bot' + token); + +bot.on('message', (msg) => { + const chatId = msg.chat.id + console.log(msg) +// send a message to the chat acknowledging receipt of their message + bot.sendMessage(chatId, "Wassup") + }) From 79bb5bedfa32caba4c96c102f6e2a2eb0ef44a72 Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 11:40:51 +0530 Subject: [PATCH 03/14] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index cc16df7..155ad08 100644 --- a/index.js +++ b/index.js @@ -16,5 +16,5 @@ bot.on('message', (msg) => { const chatId = msg.chat.id console.log(msg) // send a message to the chat acknowledging receipt of their message - bot.sendMessage(chatId, "Wassup") + bot.sendMessage(chatId, "WTF") }) From cc93c261ab7f2ad23b8d8be24e72a9dda9d6499b Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:23:54 +0530 Subject: [PATCH 04/14] Update index.js --- index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 155ad08..ae96f05 100644 --- a/index.js +++ b/index.js @@ -12,9 +12,17 @@ const port = process.env.PORT || 443, }); bot.setWebHook(externalUrl + ':443/bot' + token); + bot.on('message', (msg) => { const chatId = msg.chat.id - console.log(msg) -// send a message to the chat acknowledging receipt of their message - bot.sendMessage(chatId, "WTF") - }) + console.log(msg.text) + + request("https://pokeapi.co/api/v2/pokemon/" + msg.text,function(err,body,response){ + + let data = JSON.parse(response) + for(let i =0; i < data.ablities.length; i++} { + + bot.sendMessage(chatId,data.ablities[i].name) + }) + + }) From 4d9ab0f03a961f1c99fff6003c1b33f40162077e Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:26:02 +0530 Subject: [PATCH 05/14] Update package.json --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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" } } From da9f3ac7ca3efacbafe3da39c86953051ea9764d Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:27:17 +0530 Subject: [PATCH 06/14] Update index.js --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index ae96f05..b4576f7 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,5 @@ 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 From 39da4c58b0c04ebbea4756c97ad137f534490485 Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:28:04 +0530 Subject: [PATCH 07/14] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b4576f7..9c3ef19 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ bot.on('message', (msg) => { request("https://pokeapi.co/api/v2/pokemon/" + msg.text,function(err,body,response){ let data = JSON.parse(response) - for(let i =0; i < data.ablities.length; i++} { + for(let i =0; i < data.ablities.length; i++) { bot.sendMessage(chatId,data.ablities[i].name) }) From 66158078d71b08fd3ee801ca5f22677053c1949c Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:28:55 +0530 Subject: [PATCH 08/14] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 9c3ef19..288078e 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,6 @@ bot.on('message', (msg) => { for(let i =0; i < data.ablities.length; i++) { bot.sendMessage(chatId,data.ablities[i].name) - }) + } }) From 51d9af5301dea870001b3c64ad7dba399264eb88 Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:30:17 +0530 Subject: [PATCH 09/14] Update index.js --- index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 288078e..35c68dc 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,6 @@ 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) @@ -26,4 +25,6 @@ bot.on('message', (msg) => { bot.sendMessage(chatId,data.ablities[i].name) } - }) +}) + +}) From 4694b477a0ff05d54a79b2c8473d055d4b7dca2a Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:35:07 +0530 Subject: [PATCH 10/14] Update index.js --- index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 35c68dc..7851352 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,13 @@ bot.on('message', (msg) => { const chatId = msg.chat.id console.log(msg.text) - request("https://pokeapi.co/api/v2/pokemon/" + msg.text,function(err,body,response){ + 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.ablities.length; i++) { From 42e2b48bd357691e3b265046c0fcb3e24f57ec85 Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:36:52 +0530 Subject: [PATCH 11/14] Update index.js --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7851352..100ed3a 100644 --- a/index.js +++ b/index.js @@ -25,9 +25,9 @@ bot.on('message', (msg) => { } let data = JSON.parse(response) - for(let i =0; i < data.ablities.length; i++) { + for(let i =0; i < data.abilities.length; i++) { - bot.sendMessage(chatId,data.ablities[i].name) + bot.sendMessage(chatId,data.abilities[i].name) } }) From c2806d8d3948391ffe947396ed8facb6a9b727a8 Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:42:29 +0530 Subject: [PATCH 12/14] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 100ed3a..9d79a1e 100644 --- a/index.js +++ b/index.js @@ -26,7 +26,7 @@ bot.on('message', (msg) => { 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].name) } From be1b7cc155e4a0e8f0bbefaf32c5416cd6ba234d Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:45:37 +0530 Subject: [PATCH 13/14] Update index.js --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9d79a1e..ec2325b 100644 --- a/index.js +++ b/index.js @@ -25,9 +25,9 @@ bot.on('message', (msg) => { } let data = JSON.parse(response) - for(let i =0; i < data.abilities.length; i++) { + for(let i =0; i < data.abilities.ability.length; i++) { console.log(data.abilities[i]) - bot.sendMessage(chatId,data.abilities[i].name) + bot.sendMessage(chatId,data.abilities[i].ability.name) } }) From fbfd2be9729a57109e1c58b9c861ae0324776d6e Mon Sep 17 00:00:00 2001 From: ajugjacob <48448384+ajugjacob@users.noreply.github.com> Date: Sun, 31 Mar 2019 12:46:56 +0530 Subject: [PATCH 14/14] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index ec2325b..14b536d 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,7 @@ bot.on('message', (msg) => { } let data = JSON.parse(response) - for(let i =0; i < data.abilities.ability.length; i++) { + for(let i =0; i < data.abilities.length; i++) { console.log(data.abilities[i]) bot.sendMessage(chatId,data.abilities[i].ability.name) }