hello world,
i am quite unaware of coding but i would like to replace pushbullet and get notification on my telegram IM on grab or download of new files.
could anyone be so kind and give me some instruction?
thanks in advance,
cP
hello world,
i am quite unaware of coding but i would like to replace pushbullet and get notification on my telegram IM on grab or download of new files.
could anyone be so kind and give me some instruction?
thanks in advance,
cP
I have a script for bash for telegram. Donât know what system are you using.
using osx, so might work, right?
cheers
cp
Should be ok, this is using telegram bot
#!/bin/sh
### get chatid curl "https://api.telegram.org/bot[BOTTOKEN]/getUpdates?offset=1"
TOKEN='THETOKEN'
URL='https://api.telegram.org/bot'$TOKEN
MSG_URL=$URL'/sendMessage?chat_id='
TG_CHAT_ID="NUMBERID"
size=$(stat -c "%s" "$sonarr_episodefile_path")
sizeMb=$( expr $size / 1048576 )
send_message () {
curl --data-urlencode "text=$2" --data-urlencode "parse_mode=Markdown" "$MSG_URL$1&"
}
MSG=$(printf "*Episode Imported* \n*Source:* $sonarr_episodefile_scenename | $sizeMb MB \n*Destination:* $sonarr_episodefile_path ")
send_message "$TG_CHAT_ID" "$MSG"
You need to place your bot token and chat_id in the script. To get the chat_id you need to send a message to your bot and execute curl as pointed in the beginning of the script or place the url in the browser, donât place the square brackets.
Also donât forget to set the script to executable.
You select in sonarr->connect->custom scripts, select the path where you put the script, and type the name of the script in the field after the slash. There is not grab, just download, upgrade or rename.
The format of the message is the following
Episode Imported Source: Criminal.Minds.S11E11.HDTV.x264-KILLERS | 221 MB Destination: /tv/Criminal Minds/Season 11/Criminal Minds - S11E11 - SDTV - KILLERS.mp4
great!!! works. except that the size is not shown.
one more question:
the tg_chat_id is it the one from my personell account or the one from the bot?
cheers
Is the chat_id, is the chat interaction in between your account and the bot. Send a message to the bot and put the url getupdates in the browser, youâll get a json response. Look for the chat id
Iâm trying to get this to work on ubuntu but having issues. Iâve put the chat_id and token information into the script, set permission to 0755 and in sonarr itâs linked to /scripts/telegram.sh. When I click test notification it says completed successfully but I never receive them and I canât see any reference to this in the logs to try troubleshooting.
Any ideas?
Well, run the script manually, replace $MSG at the end with some random text in between like âtest messageâ
then run /scripts/./telegram.sh in terminal
If you get the text in telegram means is working. Youâll need run debug/trace logs to see what sonarr is doing when the import moment comes.
custom scripts doesnât support on grab, so youâll only get messages when series are imported.
By the way i changed a little bit the script to make it more portable in pure shell /bin/sh
When I run the script in my shell I get info on Telegram, but than
when I add it to the custom script part in Sonarr with
path
/home/to/telegram/notification/go.sh
arguments: none
The test is ok, but I do not see that sonarr is actually testing the script
Traced the log, but Do not see that it is actually starting the shell script.
manually downloaded a show to see if it is functioning, but no info in sonarr âŚ
I think I am doing something wrong in Sonarr âŚ
Sonarr just tests the file exists. Doesnât execute the script. You need to enable debug/trace logs to see whats going on when the import happens.
Probably Sonarr needs to know that after you added the custom script and saved it, the whole âconnectâ part needs to be saved as well. Suddenly 2x I was notified by Telegram that my manually started download was finished (yeah) the sh script and php script (a modified sonar example script for sickbeard) (calling the sh script, duh) âŚ
Cause now the log (traced it) is telling me info
The only thing I modified was the echo -e
the -e was being echoed as message to Telegram as well, so I removed the -e (dunno the meaning for it in my shell = (/bin/bash)
Echo -e is to evaluate breaking lines \n
So the message is receive in the example I posted at the beginning.
Strange Iâll test it again. Did you get the size?
This is what I get (with the -e removed)
Episode Imported
Source: The.
100.S03E02.Wanheda.Part.Two.720p.WEB-DL.DD5.1.H264-DRACULA
| 1405 MB
Destination:/media/usenetTV/The100/Season 3/The 100 - S03E02 -
WEBDL-720p DRACULA.mkv
so yes with size
Ok, i had a typo i believe in the chatid variable i changed that, also i changed echo for printf.
The script should run now in pure shell, without bash.
it runs
I slightly altered it
create an ENV for the chatID, as the TOKEN
cause itâs little unclear that after the = you need to type the chatid âŚ
ok, after messing around for 30 minutes it will be clear that you need to do that, but if you declare it as an environment variable itâs more clear
#!/bin/sh
### get chatid curl "https://api.telegram.org/bot[BOTTOKEN]/getUpdates?offset=1"
TOKEN='THETOKEN'
CHATID='THECHATID'
URL='https://api.telegram.org/bot'$TOKEN
MSG_URL=$URL'/sendMessage?chat_id='$CHATID
TG_CHAT_ID="NUMBERID"
size=$(stat -c "%s" "$sonarr_episodefile_path")
sizeMb=$( expr $size / 1048576 )
send_message () {
res=$(curl --data-urlencode "text=$2" --data-urlencode "parse_mode=Markdown" "$MSG_URL$1&")
}
MSG=$(printf "*Episode Imported* \n*Source:* $sonarr_episodefile_scenename | $sizeMb MB \n*Destination:* $sonarr_episodefile_path ")
send_message "$TG_CHAT_ID" "$MSG"
all worked flawlessly this night.
The telegram TG_CHAT_ID gets appended in the send_message function as the first positional argument $1
curl --data-urlencode "text=$2" --data-urlencode "parse_mode=Markdown" "$MSG_URL$1&"
Your double appending the chatID in curl.
The res=$(curl) that i have in there is also unnecessary so iâll take it out also
WierdâŚ
I think I am missing something
MSG_URL=$URLâ/sendMessage?chat_id=67xxxxxâ
TG_CHAT_ID=âNUMBERIDâ
is giving me with the test following output
./grab.sh
stat: cannot stat ââ: No such file or directory
expr: syntax error
{âokâ:true,âresultâ:{âmessage_idâ:489,âfromâ:{âidâ:xxxx,âfirst_nameâ:âXXX_Sonarrâ,âusernameâ:âXXX_Sonarrbotâ},âchatâ:{âidâ:67xxxxxx,âfirst_nameâ:âJohn Doeâ,âusernameâ:âJohn Doeâ,âtypeâ:âprivateâ},âdateâ:1454333817,âtextâ:âEpisode Imported \nSource: | MB \nDestination:â}}user@media:/home/dennis/Telegram-Grab#
Cannot stat end syntax error is no issue do to executing in shell without sonarr
And Telegram responds
Than try
TOKEN='143xxxxxM0ZdC_K3TkKoWgâ
URL=âhttps://api.telegram.org/botâ$TOKEN
MSG_URL=$URLâ/sendMessage?chat_id='
TG_CHAT_ID=â67334809â
Dunno if this is correct (not, cause ⌠it gives me)
{âokâ:false,âerror_codeâ:400,âdescriptionâ:"[Error]: Bad Request: chat_id is empty"}user@media:/home/dennis/Telegram-Grab# nano -w grab.sh
Thats why I created a ENV for the chatID
(ps I am a nono on programming and bashing but the only remaining question is where the hell do we put the chatid if my examples are incorrect (but do work)
hi there,
the only thing that does not work on my OSX is displaying the filesize.
any hint how to manage this on OSX?
regards,
CP