Running a CCTV Telegram Bot on your Pi

            

Telepot is a python based telegram bot framework which is lightweight, easy to use and supports all of the up-to-date telegram features. For example, I was able to write a small telegram bot running on Pi2 which takes and sends a photo with only few lines using it. Here is how.

1) Although Telepot supports python 2.7 without async feature, I wanted to use Python 3.x. However, the latest Telepot supports async requires Python 3.5 so I had to download and build Python 3.5 on my Pi2. I followed the instruction introduced here https://sowingseasons.com/blog/software/2016/01/building-python-3-4-on-raspberry-pi-2/19864079 except using python source https://www.python.org/ftp/python/3.5.2/Python-3.5.2.tgz

2) Telepot also provides basic samples. You can also find out other API usages through test code. ‘couter/countera’ example is simple but a good start points if you only require receiving telegram message and sending a reply back.

3) Of course you’ll need a Telegram Bot account. There’s a bot named ‘@BotFather’ which does making a bot for you and makes you setting basic info of it. Just initiate a talk to the account and detailed instruction described here: https://core.telegram.org/bots

4) I used the https://github.com/nickoala/telepot/blob/master/examples/chat/countera.py as the starting point. From the source, MessageCounter.on_chat_message will be called responds to the user’s message. If you want to make the CCTV like telegram bot, then just take a picture and send it back within the method.

5) Takes a picture using the picamera module and replies with it. Remove the temporary saved picture after sending it.

6) here is the result: https://gist.github.com/heejune/afd77aeec49e836fa549fc025962ddd8

5 thoughts on “Running a CCTV Telegram Bot on your Pi

  1. why there are two py files, i tried running picam.py, it dose not give any errors, it just comes back on command prompt.
    Also what command you are using to receive pics ?

    • Hi, of course, you can merge two .py files into one. I just wanted to keep files clean as dividing modules as bot and picamera each.

      First I suggest you make sure the picamera successfully generate images using picam.py. If you read the coutera.py source code, you’ll realize that it just read images which stored in the sub-directory and send them.

      So, if you succeeded generating images on the sub-directory, then make sure telegram bot code keeps running and responses from bot commands. Thanks.

  2. Good day sir,
    May I ask for your guidance. Is it possible to adjust the script that you have shown so that when it is launched. it will automatically send the pictures to user telegram? If it is possible. Can you show me how.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s