Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can it use with telegram? #15

Closed
xiNeRoar opened this issue May 2, 2021 · 24 comments
Closed

Can it use with telegram? #15

xiNeRoar opened this issue May 2, 2021 · 24 comments

Comments

@xiNeRoar
Copy link

xiNeRoar commented May 2, 2021

As title, can this be use with telegram?
If so, may i know how to setup this?

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 2, 2021

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.

@xiNeRoar
Copy link
Author

xiNeRoar commented May 2, 2021

For Telegram API Key, do you mean telegram bot token?

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 2, 2021

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.

@xiNeRoar
Copy link
Author

xiNeRoar commented May 3, 2021

thank you very much!

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 4, 2021

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

@xiNeRoar
Copy link
Author

xiNeRoar commented May 4, 2021 via email

@xiNeRoar
Copy link
Author

xiNeRoar commented May 5, 2021

Dear CJPCNZ,

Here is what i get when trying to use the script.
image

@xiNeRoar
Copy link
Author

xiNeRoar commented May 5, 2021

forgot to mention, i am using the Radarr telegram .ps1 file, and here is the screenshot of my setup;
image
Some more questions that i want to ask;

  1. Can i use telegram "sendPhoto" instead of "sendMessage"? because i want to include the movie poster in my notification.
  2. Where can i have a list of the variables that available? like "radarr_movie_id"? Is there something like "radarr_movie_image"?
  3. May i ask how can i customize the format of the message? configure it in #Format content or #Prepare push notification body?
    Again, thank you very much!!! 👍

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 6, 2021

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:

  1. You can send photo as well. There is a sample of the PushBullet code in this file which I can adapt to Telegram if you want: https://github.com/CJPCNZ/CustomPush/blob/master/Radarr/PushBullet-WithImage.ps1
  2. There is a list of available API endpoints here: https://radarr.video/docs/api/
  3. You can configure the format in #Format content section of the code.

@xiNeRoar
Copy link
Author

xiNeRoar commented May 6, 2021

Thank you so much for your detailed explanation. :D

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 6, 2021

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.

@xiNeRoar
Copy link
Author

xiNeRoar commented May 9, 2021

i still got this message..
image
does that mean i have to put some dummy message inside the file or what does it mean?

CJPCNZ added a commit that referenced this issue May 9, 2021
Convert to JSON for Telegram API
@CJPCNZ
Copy link
Owner

CJPCNZ commented May 9, 2021

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.

@xiNeRoar
Copy link
Author

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?

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 11, 2021

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.

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 14, 2021

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

@xiNeRoar
Copy link
Author

here is my screencap following your instruction;
image

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 15, 2021

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.

I have not done adequate testing of the below steps so please use them at your own risk!

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"

@xiNeRoar
Copy link
Author

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

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 23, 2021

Hi @xiNeRoar how did you get on with testing?

Let me know if there are any issues or if you would like this closed.

@xiNeRoar
Copy link
Author

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.

@xiNeRoar
Copy link
Author

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

@CJPCNZ
Copy link
Owner

CJPCNZ commented May 28, 2021

Hi @xiNeRoar are you please able to share logs or screenshots for the error?

Thanks!

@CJPCNZ CJPCNZ closed this as completed Jul 18, 2021
@CJPCNZ CJPCNZ reopened this Jul 18, 2021
@CJPCNZ
Copy link
Owner

CJPCNZ commented Mar 30, 2022

Closing as Telegram is now working but sending images is not supported in PowerShell version 5.

@CJPCNZ CJPCNZ closed this as completed Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants