diff --git a/README.md b/README.md index fc2bcac..d7a85f8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ -# bml-tg-notify -Push Notification BML Transcations to Telegram +# BML-TG-NOTIFICATION +## Push Notification BML Transcations to Telegram + +### Requriements +`curl` `jq` +- Install with whatever package manager you use. + +### Setup +``` +git clone https://github.com/shihaamabr/bml-tg-notify.git +cd bml-tg-notify +chmod +x bml-tg-notify.sh +./bml.sh +``` +- `mv env.sample .env` +- Edit the contents of .env to your config\ +#### .env Sample +``` +BML_USERNAME='' #Your BML Username +BML_PASSWORD='' #Your BML Password +BML_ACCOUNTID='' #Your BML Account ID, NOT ACCOUNT NUMBER! +CURRENCY='MVR' #Change if you're setting to a USD Account. +TG_BOT_TOKEN='' #Your Telegram Bot token, This can be optiained by talking to BotFather on Telegram https://t.me/BotFather +TG_CHATID='' #Your Telegram Chat ID +``` +`echo XX > delay` +- where XX is the time in seconds you want to delay script run.\ +- Please note that if the XX value is less than a certain value, you could get rate limited. + +``` +chmod +x bml-tg-notify.sh +./bml-tg-notify.sh +``` + +### Bugs +- You tell me :) diff --git a/bml-tg-notify.sh b/bml-tg-notify.sh new file mode 100755 index 0000000..0b6974d --- /dev/null +++ b/bml-tg-notify.sh @@ -0,0 +1,54 @@ +#!/bin/bash +source .env +mkdir -p ~/.cache/bml-cli/ +TG_BOTAPI='https://api.telegram.org/bot' +BML_URL='https://www.bankofmaldives.com.mv/internetbanking/api' +COOKIE=~/.cache/bml-cli/cookie + +while true; do +LOGIN=$(curl -s -c $COOKIE $BML_URL/login --data-raw username=$BML_USERNAME --data-raw password=${BML_PASSWORD} | jq -r .code) +if [ "$LOGIN" = "0" ] +then + PROFILE=$(curl -s -b $COOKIE $BML_URL/profile | jq -r '.payload | .profile | .[] | .profile' | head -n 1) + curl -s -b $COOKIE $BML_URL/profile --data-raw profile=$PROFILE > /dev/null +else + echo Something went wrong.. Probably your account locked or wrong username password OR your IP Blocked by CF + echo Code: $LOGIN + exit +fi + +CHECKDIFF1=$(echo $HISTORY | wc -c) +HISTORY=$(curl -s -b $COOKIE $BML_URL/account/$BML_ACCOUNTID/history/today | jq -r '.payload | .history | .[]') +CHECKDIFF2=$(echo $HISTORY | wc -c) +DELAY=$(cat delay) + +if [ "$CHECKDIFF1" != "$CHECKDIFF2" ] +then + DESCRIPTION=$(echo $HISTORY | jq -r .description | head -n1) + AMOUNT=$(echo $HISTORY | jq -r .amount | head -n1) + if [ "$DESCRIPTION" = "Transfer Credit" ] + then + FROMTO=From + ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) + elif [ "$DESCRIPTION" = "Transfer Debit" ] + then + FROMTO=To + ENTITY=$(echo $HISTORY | jq -r .narrative3 | head -n1) + elif [ "$DESCRIPTION" = "Salary" ] + then + FROMTO=From + ENTITY=$(echo $HISTORY | jq -r .narrative2 | head -n1) + fi + echo $DESCRIPTION + echo $FROMTO: $ENTITY + echo $CURRENCY: $AMOUNT + DESCRIPTION=`echo $DESCRIPTION | sed "s/ /%20/g"` #Fix spaces + ENTITY=`echo $ENTITY | sed "s/ /%20/g"` #Fix spaces + TGTEXT=$(echo $DESCRIPTION%0A$FROMTO:%20$ENTITY%0A$CURRENCY:%20$AMOUNT) + curl -s $TG_BOTAPI$TG_BOT_TOKEN/sendMessage?chat_id=$TG_CHATID'&'text=$TGTEXT > /dev/null + echo "Next check in $DELAY seconds" +else + echo "nothing new..checking again in $DELAY seconds" +fi +sleep $DELAY +done diff --git a/delay b/delay new file mode 100644 index 0000000..7273c0f --- /dev/null +++ b/delay @@ -0,0 +1 @@ +25 diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..1869676 --- /dev/null +++ b/env.sample @@ -0,0 +1,6 @@ +BML_USERNAME='' +BML_PASSWORD='' +BML_ACCOUNTID='' +CURRENCY='MVR' +TG_BOT_TOKEN='' +TG_CHATID=''