Closed xiNeRoar closed 2 years ago
Hi @xiNeRoar, this is not currently supported as Telegram requires app registration but if you have a Telegram API key already then it should be possible.
For Telegram API Key, do you mean telegram bot token?
Yes a bot token is required as well as a chat ID - I've had a read of Telegram's documentation and it seems like it should be straightforward. I'll see if I can write something for you this week and I'll let you know here once it's ready for testing.
thank you very much!
I've just uploaded what I think should work.
Please can you test and let me know which scripts you use (Sonarr/Radarr/Lidarr) and what the outcome is (or any test message). Remember to blank your API key/channel ID.
If you don't have a bot and channel ID already, please be sure to follow the instructions here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
Thanks!
Since i am still at work. I will test it out around 8 to 10 hours later and let you know what is the result. Thank you so much for your help :D
在 2021年5月4日週二 14:18,Chris @.***> 寫道:
I've just uploaded what I think should work.
Please can you test and let me know which scripts you use (Sonarr/Radarr/Lidarr) and what the outcome is (or any test message). Remember to blank your API key/channel ID.
If you don't have a bot and channel ID already, please be sure to follow the instructions here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/CJPCNZ/CustomPush/issues/15#issuecomment-831707916, or unsubscribe https://github.com/notifications/unsubscribe-auth/APZGB6T4ZY2ZMSNYNIYMOUTTL6GUZANCNFSM437B6DJQ .
Dear CJPCNZ,
Here is what i get when trying to use the script.
forgot to mention, i am using the Radarr telegram .ps1 file, and here is the screenshot of my setup; Some more questions that i want to ask;
Thank you for the logs. It seems that the message text is not being sent correctly. I will investigate and update the code and notify you when it is ready.
To answer your questions:
Thank you so much for your detailed explanation. :D
Could you please replace the last line:
Invoke-WebRequest -Method POST -Uri "https://api.telegram.org/bot$pushkey/sendMessage" -UseBasicParsing -Header $headers -Body $pushBody
With:
Invoke-WebRequest -Method POST -Uri "https://api.telegram.org/bot$pushkey/sendMessage" -UseBasicParsing -Header $headers -Body "{ 'chat_id':$pushtag, 'text':$pushmessage }"
If this also fails then there might be an issue with the encoding of the body message.
i still got this message.. does that mean i have to put some dummy message inside the file or what does it mean?
I've found the issue, we needed to ConvertTo-JSON to be compatible with the Telegram API. I've updated the Radarr script for you to test now.
I've found the issue, we needed to ConvertTo-JSON to be compatible with the Telegram API. I've updated the Radarr script for you to test now.
Thanks soooooooo much! finally I got it working right now. Just a little more to ask, i have read through all the documentations but cannot found how to customize the message body..will you possible to explain a little more on this? >< For example, if i would like my message;
Latest Movie :
(Movie title) (Released year) is available right now!
Please login to (http://mydomain.com) to watch!
Movie introduction :
(Movie overview)
(Movie image)
How can i achieve this?
I'm glad it is now working! 😄
I am working on getting the images to send however I have not had time the past two days. I'll hopefully get some time tonight or tomorrow to finish it. In the meantime you can change $pushmessage to a 'here-string' instead like this:
$pushmessage = @"
Latest Movie :
$radarr_movie_title $env:radarr_movie_year is available right now!
Please login to http://mydomain.com to watch!
Movie introduction :
$radarr_description
"@
If the $env:radarr_movie_year doesn't work, just declare it in the first few lines like so:
$radarr_movie_year = $env:radarr_movie_year
All of the fields can be found under the API Schemas at the bottom of the page here: Radarr API
Once I get the image part working I'll let you know.
Sadly I cannot get the image upload working in PowerShell 5.
Can you confirm what version of PowerShell you have? Just type $PSVersiontable
at the prompt
You should get something like this:
PS C:\Users\CJPCNZ> $PSVersiontable
Name Value
---- -----
PSVersion 5.1.19041.906
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.906
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
here is my screencap following your instruction;
Unfortunately the image attachment won't work. For some reason Telegram will not accept images in any format from PowerShell version 5.x however PushBullet seems to manage this without issues.
This one-liner will trigger the install of PowerShell version 7:
iex "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI"
You will need to MANUALLY call this for the telegram image script by updating your Radarr custom script path to:
C:\Program Files\PowerShell\7\pwsh.exe
For PowerShell Version 6.1.0 or higher you can use the following code to send images to Telegram:
# Define required variables
$radarr_movie_id = $env:radarr_movie_id
$radarr_movie_title = $env:radarr_movie_title
$radarr_moviefile_quality = $env:radarr_moviefile_quality
$radarr_movie_year = $env:radarr_movie_year
$apikey="" # Your Radarr API key
$radarr_address="http://localhost:7878" # Your Radarr address (including base_url)
$pushkey="12345678:replace-me-with-real-token" # Your Telegram Bot API key
$pushtag="@channelusername" # Your Teleram Chat ID
# Grab movie information
$radarr_movie=$(Invoke-WebRequest -URI $radarr_address/api/movie/$radarr_movie_id -UseBasicParsing -Header @{"X-Api-Key" = $apikey}) | ConvertFrom-Json
$radarr_description = $radarr_movie | Select-Object -ExpandProperty overview
$radarr_image = $radarr_address + "/MediaCover/" + $radarr_movie_id + "/poster.jpg"
Invoke-WebRequest $radarr_image -UseBasicParsing -OutFile "$PSScriptRoot\poster.jpg"
# Format content
$pushmessage = @"
Latest Movie :
$radarr_movie_title $radarr_movie_year is available right now!
Please login to http://mydomain.com to watch!
Movie introduction :
$radarr_description
"@
# Prepare push notification body
$form = @{
caption = "$pushmessage"
chat_id = $pushtag
photo = Get-Item "$PSScriptRoot\poster.jpg"
}
# Send push notification
Invoke-WebRequest -Method POST -Uri "https://api.telegram.org/bot$pushkey/sendPhoto" -UseBasicParsing -Header $headers -Form $form
Remove-Item "$PSScriptRoot\poster.jpg"
thank you so much!! i will try it out when i have time and will let you know the result. Thank you so much for all the work you have done :D
Hi @xiNeRoar how did you get on with testing?
Let me know if there are any issues or if you would like this closed.
Hi @xiNeRoar how did you get on with testing?
Let me know if there are any issues or if you would like this closed.
Hi @CJPCNZ, sorry for replying late. I have tried it and found it does not work. Can't even send out a proper notification and i do not know why.
Hi @xiNeRoar how did you get on with testing?
Let me know if there are any issues or if you would like this closed.
I can share some screenshot to you later to let you see what is happening
Hi @xiNeRoar are you please able to share logs or screenshots for the error?
Thanks!
Closing as Telegram is now working but sending images is not supported in PowerShell version 5.
As title, can this be use with telegram? If so, may i know how to setup this?