From 71b7f680d62766ece9e6437728df196d47246910 Mon Sep 17 00:00:00 2001 From: Diego Palacios Date: Wed, 7 Aug 2024 21:56:04 +0100 Subject: [PATCH] feat(telegram): adds workflow and script for telegram --- .github/workflows/telegram-notify.yml | 28 +++++++++++ package-lock.json | 70 +++++++++++++++++++++++++-- package.json | 4 +- scripts/notify-telegram.js | 63 ++++++++++++++++++++++++ yarn.lock | 25 +++++++++- 5 files changed, 183 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/telegram-notify.yml create mode 100644 scripts/notify-telegram.js diff --git a/.github/workflows/telegram-notify.yml b/.github/workflows/telegram-notify.yml new file mode 100644 index 0000000..2e32664 --- /dev/null +++ b/.github/workflows/telegram-notify.yml @@ -0,0 +1,28 @@ +name: Notify Telegram on JSON Update + +on: + push: + paths: + - './build/voltage-swap-default.tokenlist.json' + +jobs: + notify: + environment: TELEGRAM + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: '14' + + - name: Install dependencies + run: npm install + + - name: Run notify script + run: npm run notify:telegram + env: + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} diff --git a/package-lock.json b/package-lock.json index 21252da..079f4c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@voltage-finance/swap-default-token-list", - "version": "3.25.0", + "version": "3.26.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@voltage-finance/swap-default-token-list", - "version": "3.25.0", + "version": "3.26.0", "license": "GPL-3.0-or-later", "devDependencies": { "@ethersproject/address": "^5.0.2", @@ -15,6 +15,7 @@ "@voltage-finance/v3-periphery": "^1.0.2", "@voltage-finance/v3-sdk": "^1.0.10", "ajv": "^6.12.3", + "axios": "^1.7.3", "chai": "^4.2.0", "ethers": "^6.13.1", "graphql": "^15.9.0", @@ -1500,6 +1501,31 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k= sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "dev": true }, + "node_modules/axios": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", + "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/axios/node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -2510,7 +2536,6 @@ "url": "https://github.com/sponsors/RubenVerborgh" } ], - "peer": true, "engines": { "node": ">=4.0" }, @@ -4285,6 +4310,12 @@ "node": ">= 0.6.0" } }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "node_modules/punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", @@ -6477,6 +6508,30 @@ "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k= sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "dev": true }, + "axios": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz", + "integrity": "sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw==", + "dev": true, + "requires": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + }, + "dependencies": { + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -7287,8 +7342,7 @@ "version": "1.15.6", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", - "dev": true, - "peer": true + "dev": true }, "form-data": { "version": "3.0.0", @@ -8627,6 +8681,12 @@ "integrity": "sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8= sha512-oNpcutj+nYX2FjdEW7PGltWhXulAnFlM0My/k48L90hARCOJtvBbQXc/6itV2jDvU5xAAtonP+r6wmQgCcbAUA==", "dev": true }, + "proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "dev": true + }, "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", diff --git a/package.json b/package.json index 3ecef57..d455e21 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "test": "mocha", "build": "rimraf build && mkdir -p build && node src/write.js > build/voltage-swap-default.tokenlist.json", "prepublishOnly": "npm test && npm run build", - "analyze": "node scripts/analyze.js" + "analyze": "node scripts/analyze.js", + "notify:telegram": "node scripts/notify-telegram.js" }, "files": [ "build/voltage-swap-default.tokenlist.json" @@ -36,6 +37,7 @@ "@voltage-finance/v3-periphery": "^1.0.2", "@voltage-finance/v3-sdk": "^1.0.10", "ajv": "^6.12.3", + "axios": "^1.7.3", "chai": "^4.2.0", "ethers": "^6.13.1", "graphql": "^15.9.0", diff --git a/scripts/notify-telegram.js b/scripts/notify-telegram.js new file mode 100644 index 0000000..204fe24 --- /dev/null +++ b/scripts/notify-telegram.js @@ -0,0 +1,63 @@ +const axios = require('axios') + +// const token = process.env.TELEGRAM_BOT_TOKEN +// const chatId = process.env.TELEGRAM_CHAT_ID +const TELEGRAM_BOT_TOKEN = '' +const TELEGRAM_CHAT_ID = '' + +if (!TELEGRAM_BOT_TOKEN || !TELEGRAM_CHAT_ID) { + throw new Error('TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID is not set') +} + +async function sendMessage(chatId) { + const url = `https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage` + + // const currentTokenList = await getCurrentTokenList() + // const newToken = await getNewToken(newTokenList, currentTokenList) + + // if (!newToken) { + // console.log('No new token has been added') + // return + // } + + // mock + const newToken = { + name: 'Dai Stablecoin V2', + address: '0x2502F488D481Df4F5054330C71b95d93D41625C2', + symbol: 'DAI V2', + decimals: 18, + chainId: 122, + logoURI: + 'https://raw.githubusercontent.com/voltfinance/swap-default-token-list/master/logos/0x440B63C0e7b21a57A3784D8AB8E819B9dA383FDf/logo.png', + } + + const text = ` + There has been a new listing! + - Token address: ${newToken.address} + - Name: ${newToken.name} + - Symbol: ${newToken.symbol} + - Decimals: ${newToken.decimals} + ` + + try { + console.log(text) + const response = await axios.post(url, { + chat_id: chatId, + text: text, + }) + console.log('Message sent:', response.data) + } catch (error) { + if (axios.isAxiosError(error)) { + console.error('Axios error message:', error.message) + if (error.response) { + console.error('Response data:', error.response.data) + console.error('Response status:', error.response.status) + console.error('Response headers:', error.response.headers) + } + } else { + console.error('Unexpected error:', error) + } + } +} + +sendMessage(TELEGRAM_CHAT_ID) diff --git a/yarn.lock b/yarn.lock index 2018bc7..cd7b827 100644 --- a/yarn.lock +++ b/yarn.lock @@ -746,6 +746,15 @@ asynckit@^0.4.0: resolved "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== +axios@^1.7.3: + version "1.7.3" + resolved "https://registry.npmjs.org/axios/-/axios-1.7.3.tgz" + integrity sha512-Ar7ND9pU99eJ9GpoGQKhKf58GpUOgnzuaB7ueNQ5BMi0p+LZ5oaEnfF999fAArcTIBwXTCHAmGcHOZJaWPq9Nw== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + balanced-match@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz" @@ -1410,7 +1419,7 @@ flat@^5.0.2: resolved "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz" integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ== -follow-redirects@^1.12.1: +follow-redirects@^1.12.1, follow-redirects@^1.15.6: version "1.15.6" resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz" integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== @@ -1424,6 +1433,15 @@ form-data@^3.0.0: combined-stream "^1.0.8" mime-types "^2.1.12" +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + fp-ts@^1.0.0, fp-ts@1.19.3: version "1.19.3" resolved "https://registry.npmjs.org/fp-ts/-/fp-ts-1.19.3.tgz" @@ -2156,6 +2174,11 @@ process@~0.5.1: resolved "https://registry.npmjs.org/process/-/process-0.5.2.tgz" integrity sha1-FjjYqONML0QKkduVq5rrZ3/Bhc8= sha512-oNpcutj+nYX2FjdEW7PGltWhXulAnFlM0My/k48L90hARCOJtvBbQXc/6itV2jDvU5xAAtonP+r6wmQgCcbAUA== +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + punycode@^2.1.0: version "2.1.1" resolved "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz"