New App: TelegramBot + Plex API

Hi all,
Like many others I have loads of users on my PMS and I wanted to be able to get quick info from my Plex server whilst chatting away on my favorite messenger app Telegram telegram.org/

For example using a Telegram Bot I can create a command e.g. /tv and have Recently or Newest TV Shows retrieved into my chat.


The project/code is on GitHub, github.com/brownsmart/telegram-plexbot if anyone wants to use and or contribute feel free to go ahead. It currently written in Python, but I want to eventually get it running as a NodeJS app but in the mean time I want to add the following features.

  1. Add notifications where a user enters something like “/tv alert power s02 episode 08” the bot will send a private message to the telegram user letting them know the show has been added. Same for movies and other forms of content.

  2. “/whoswatching” this will query using http://PMS:32000/status/sessions command and parse the XML from “root.findall(‘./Video/User’)” and “root.findall(‘./Video’)” from the User Attributes and from Video the attributes. Problem I have is I think i need to write a simultaneous loop in python to pluck out of one child node in the XML and then go back in deeper to get another child node then push out both attributes using the reply(var1 +’ - ’ + var2) but just cant get it to root.findall, then root.findall again “YET”!!

Hope that its useful to someone.

I have an ubuntu box, how can set this up locally without google app engine?

I don’t want to be dependent on google or a cloud server…

wow this is fantastic, ill test it out this week

I am getting this, but I am seeking a way for requesting stuff too :stuck_out_tongue:

A bot for http://plexrequests.8bits.ca/

I like the idea a lot, got it up and running… but I am facing lots of issues while trying to play with the code :stuck_out_tongue:

For instance, I want to print the title of a movie and ‘full’ link of a poster! Instead of the lengthy Summary

To read the current epoch time:
import time first, then time.time()

To convert epoch to a readable format:
import time first, then time.strftime("%a, %d %b %Y %H:%M:%S +0000",

Sorry I have taken so long to respond, I will go through the posts later today properly with the answers you need.

@elRadix said:
I have an ubuntu box, how can set this up locally without google app engine?

I don’t want to be dependent on google or a cloud server…

I feel the same way as well, but it has a great reporting and logging feature that helps for finding why things don’t work.

Anyway I will put together a guide on how to setup for using your own server, shouldn’t be too hard, though I’m sure it will require SSL certs some I seen with other bots using their own servers but I will confirm later.

@MAJSTATION said:
I am getting this, but I am seeking a way for requesting stuff too :stuck_out_tongue:

A bot for http://plexrequests.8bits.ca/

OMG plex requests is a sick idea gonna fork it and see how I can mash the both together.

@MAJSTATION said:
I like the idea a lot, got it up and running… but I am facing lots of issues while trying to play with the code :stuck_out_tongue:

For instance, I want to print the title of a movie and ‘full’ link of a poster! Instead of the lengthy Summary

I will delve into the Plex API and get the required parts for you. I haven’t learnt how to do a link, text and image output for telegram yet but I think this is the look your going for right?

@MAJSTATION said:
To read the current epoch time:
import time first, then time.time()

To convert epoch to a readable format:
import time first, then time.strftime(“%a, %d %b %Y %H:%M:%S +0000”,

Thanks gonna give this a try!

Is it working with Plex Home?

@Skycryer said:
Is it working with Plex Home?

Don’t see why it wouldn’t, it’s all based on Plex’s API

Because for plex home it Must Support Login

This works nicely, thanks!

btw any way to show the season number? Like S02E05, Right now it only shows:

The Simpsons - Lisa with an ‘S’

And perhaps a way of displaying available subtitles?

This is awesome! Too bad you need to pay for the Google Engine.

EDIT: I see you mentioned that you can use a own server to run the telegram bot. Can you explain how?

@damiantje99 said:
This is awesome! Too bad you need to pay for the Google Engine.

EDIT: I see you mentioned that you can use a own server to run the telegram bot. Can you explain how?

I don’t need to pay for the Google engine it says $0 ?

@mkools said:

@damiantje99 said:
This is awesome! Too bad you need to pay for the Google Engine.

EDIT: I see you mentioned that you can use a own server to run the telegram bot. Can you explain how?

I don’t need to pay for the Google engine it says $0 ?

Hmmm, did you start a trial? I mean, in the discription of telebot and also in the Plexbot is says that you need google compute engine. But thats just a trial and at some point you need to pay for it. Also, i can’t file the place where I can download the .zip. I created a project, but don’t know where to download it.

I’ve managed to download the .zip file, it was on the page itself. Now i’m trying it again. I’ll let you know.

EDIT: I’ve deployed the app with the google app application. (as described in Telebot git) but now i’m getting the following error when i’m going to https://project-id.appspot.com/me. I’ve authenticated the engine app. Also if im going to localhost and than the normal port, it gives me a error 500. The admin port is working fine.

This is the error i’m getting:

Traceback (most recent call last):
File “/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py”, line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File “/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py”, line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File “/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py”, line 85, in LoadObject
obj = import(path[0])
File “/base/data/home/apps/s~romhoffbot-2015/1.389331439447639263/main.py”, line 35
def reply(msg=None, img=None):
^
IndentationError: unexpected indent

so sorry, I dont really monitor this much.

Python is very pedantic and requires a very idoimatic programming style. so if you get “IndentationError: unexpected indent” that means its out of form.