Skip to content

Commit

Permalink
feat(telegram): adds workflow and script for telegram
Browse files Browse the repository at this point in the history
  • Loading branch information
darkpaladi committed Aug 7, 2024
1 parent 1dfee50 commit 71b7f68
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 7 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/telegram-notify.yml
Original file line number Diff line number Diff line change
@@ -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 }}
70 changes: 65 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions scripts/notify-telegram.js
Original file line number Diff line number Diff line change
@@ -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)
25 changes: 24 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==
Expand All @@ -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, [email protected]:
version "1.19.3"
resolved "https://registry.npmjs.org/fp-ts/-/fp-ts-1.19.3.tgz"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 71b7f68

Please sign in to comment.