# New App: TelegramBot + Plex API

**URL:** <https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572>\
**Category:** Dev/API Corner\
**Tags:** other-dev\
**Created:** [August 7, 2015, 8:05pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572 "2015-08-07T20:05:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [August 7, 2015, 8:05pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/1 "2015-08-07T20:05:58Z")

</div>

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/](https://telegram.org/ "https://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](https://github.com/brownsmart/telegram-plexbot "https://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](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”!!

> **[GitHub - brownsmart/telegram-plexbot: telegram-plexbot - Pull data from Plex API to send...](https://github.com/brownsmart/telegram-plexbot)**
>
> telegram-plexbot - Pull data from Plex API to send as messages to Telegram users.

Hope that its useful to someone.

---

<div class="post-metadata">

**Author:** ![elRadix](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/elradix/32/2680_2.png) [@elRadix](https://forums.plex.tv/u/elRadix)\
**Post date:** [August 11, 2015, 7:35pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/2 "2015-08-11T19:35:04Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![nickdami.co](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/nickdami.co/32/8412_2.png) [@nickdami.co](https://forums.plex.tv/u/nickdami.co)\
**Post date:** [August 12, 2015, 4:27am UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/3 "2015-08-12T04:27:18Z")

</div>

wow this is fantastic, ill test it out this week

---

<div class="post-metadata">

**Author:** ![MAJ-5](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/maj-5/32/6663_2.png) [@MAJ-5](https://forums.plex.tv/u/MAJ-5)\
**Post date:** [August 14, 2015, 9:39am UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/4 "2015-08-14T09:39:35Z")

</div>

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

A bot for [http://plexrequests.8bits.ca/](http://plexrequests.8bits.ca/)

---

<div class="post-metadata">

**Author:** ![MAJ-5](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/maj-5/32/6663_2.png) [@MAJ-5](https://forums.plex.tv/u/MAJ-5)\
**Post date:** [August 15, 2015, 8:50am UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/5 "2015-08-15T08:50:55Z")

</div>

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 😛

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

---

<div class="post-metadata">

**Author:** ![MAJ-5](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/maj-5/32/6663_2.png) [@MAJ-5](https://forums.plex.tv/u/MAJ-5)\
**Post date:** [August 15, 2015, 1:58pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/6 "2015-08-15T13:58:18Z")

</div>

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",`

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [August 15, 2015, 3:14pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/7 "2015-08-15T15:14:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [August 15, 2015, 3:18pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/8 "2015-08-15T15:18:47Z")

</div>

> @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.

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [August 15, 2015, 3:20pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/9 "2015-08-15T15:20:06Z")

</div>

> @MAJSTATION said:  
> I am getting this, but I am seeking a way for requesting stuff too 😛
> 
> A bot for [http://plexrequests.8bits.ca/](http://plexrequests.8bits.ca/)

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

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [August 15, 2015, 3:21pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/10 "2015-08-15T15:21:32Z")

</div>

> @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 😛
> 
> 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?

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [August 15, 2015, 3:22pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/11 "2015-08-15T15:22:13Z")

</div>

> @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!

---

<div class="post-metadata">

**Author:** ![Skycryer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/skycryer/32/85998_2.png) [@Skycryer](https://forums.plex.tv/u/Skycryer)\
**Post date:** [December 8, 2015, 4:05pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/12 "2015-12-08T16:05:57Z")

</div>

Is it working with Plex Home?

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [December 11, 2015, 6:07pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/13 "2015-12-11T18:07:46Z")

</div>

> @Skycryer said:  
> Is it working with Plex Home?

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

---

<div class="post-metadata">

**Author:** ![Skycryer](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/skycryer/32/85998_2.png) [@Skycryer](https://forums.plex.tv/u/Skycryer)\
**Post date:** [December 12, 2015, 6:31pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/14 "2015-12-12T18:31:59Z")

</div>

Because for plex home it Must Support Login

---

<div class="post-metadata">

**Author:** ![mkools](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mkools](https://forums.plex.tv/u/mkools)\
**Post date:** [December 12, 2015, 7:10pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/15 "2015-12-12T19:10:54Z")

</div>

This works nicely, thanks!

---

<div class="post-metadata">

**Author:** ![mkools](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mkools](https://forums.plex.tv/u/mkools)\
**Post date:** [December 12, 2015, 7:16pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/16 "2015-12-12T19:16:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![damiantje99](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/damiantje99/32/120141_2.png) [@damiantje99](https://forums.plex.tv/u/damiantje99)\
**Post date:** [December 14, 2015, 11:32am UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/17 "2015-12-14T11:32:31Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mkools](https://avatars.discourse-cdn.com/v4/letter/m/3e96dc/32.png) [@mkools](https://forums.plex.tv/u/mkools)\
**Post date:** [December 16, 2015, 10:54am UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/18 "2015-12-16T10:54:18Z")

</div>

> @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 ?

---

<div class="post-metadata">

**Author:** ![damiantje99](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/damiantje99/32/120141_2.png) [@damiantje99](https://forums.plex.tv/u/damiantje99)\
**Post date:** [December 17, 2015, 4:13pm UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/19 "2015-12-17T16:13:27Z")

</div>

> @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](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

---

<div class="post-metadata">

**Author:** ![mr3rown](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/mr3rown/32/92576_2.png) [@mr3rown](https://forums.plex.tv/u/mr3rown)\
**Post date:** [June 7, 2016, 8:39am UTC](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572/20 "2016-06-07T08:39:37Z")

</div>

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.

[Next page](https://forums.plex.tv/t/new-app-telegrambot-plex-api/110572.md?page=2)
