From 43d0a0048f5bcc40c2f7f0bcf420bfb1e248390c Mon Sep 17 00:00:00 2001 From: Gayatri Date: Wed, 26 Jan 2022 18:32:28 +0530 Subject: [PATCH 1/2] Set Webhook on Telegram Bot --- .env | 6 ++++++ lib/telebot.js | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..99b5ae7 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +// you have to need to here give (Telegram API Token) +Token=https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe + + + // you have to need to add here ngrok server_url (ngrok http 5000 using this command) +SERVER_URL=https://0794-103-165-12-247.ngrok.io \ No newline at end of file diff --git a/lib/telebot.js b/lib/telebot.js index 1670ec8..5de48d1 100644 --- a/lib/telebot.js +++ b/lib/telebot.js @@ -7,6 +7,26 @@ const BUILDIN_PLUGINS_FOLDER = '../plugins/'; const BUILDIN_PLUGINS = ['regExpMessage', 'shortReply']; const USER_PLUGIN_FOLDER = '../plugins/'; +const {TOKEN, SERVER_URL} = process.env +const TELEGRAM_API=`https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe` +const URI = `/webhook/${TOKEN}` +const WEBHOOK_URL = SERVER_URL+URI + +const app = express() +app.use(bodyparser.json()) +const init = async () => { + const res = await axios.get(`${TELEGRAM_API}/setWebhook?url=${WEBHOOK_URL}`) + console.log(res.data) + +} +app.post(URI, async (req, res) => { + console.log(req.body) + return re.send() +}) +app.listen(process.env.PORT || 5000, async () =>{ + console.log('app running on port', process.env.PORT || 5000) + await init() +}) class TeleBot { From 9f824f87a1346dc99799eb3a0672627f8e93dd34 Mon Sep 17 00:00:00 2001 From: Gayatri Singh <88123749+gayatrisingh31@users.noreply.github.com> Date: Wed, 26 Jan 2022 18:44:45 +0530 Subject: [PATCH 2/2] Update .env --- .env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 99b5ae7..4e3bdaf 100644 --- a/.env +++ b/.env @@ -1,6 +1,6 @@ // you have to need to here give (Telegram API Token) -Token=https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe +TOKEN=https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/getMe // you have to need to add here ngrok server_url (ngrok http 5000 using this command) -SERVER_URL=https://0794-103-165-12-247.ngrok.io \ No newline at end of file +SERVER_URL=https://0794-103-165-12-247.ngrok.io