Giter VIP home page Giter VIP logo

Comments (24)

CJPCNZ avatar CJPCNZ commented on July 30, 2024 1

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.

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024 1

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.

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024 1

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"

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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.

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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.

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

thank you very much!

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

Dear CJPCNZ,

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

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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!!! πŸ‘

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

Thank you so much for your detailed explanation. :D

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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.

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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?

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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.

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

here is my screencap following your instruction;
image

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

Hi @xiNeRoar how did you get on with testing?

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

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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.

from custompush.

xiNeRoar avatar xiNeRoar commented on July 30, 2024

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

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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

Thanks!

from custompush.

CJPCNZ avatar CJPCNZ commented on July 30, 2024

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

from custompush.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.