The title may be confusing a little, but I really mean: Control a camera using a messenger.
For those among you who don't know Telegram, it is like WhatsApp. The advantages and differences of those two messengers won't be described here, but if you want, read more about here.
One thing before we start: The content of the following lines isn't that useful. To take pictures with a camera using a messenger is not that wise, but if you want to know how to use Telegram bots or how to interact with a dslr on your Rasberry Pi you're welcome.
Get Telegram
First you need Telegram. Besides the smartphone app I recommend the PC/Mac version. It very neat to create the bot on you PC instead on your phone.
Then you have to enter the name BotFather in the search field. The BotFather is the manager of all bots on Telegram. You're going to ask him for a name.


If that's done, you'll get an unique ID, the so called token. That token is very important in the program code later.
Get Components
Your bot is now ready, but to bring it to life it needs a body. In that case the raspberry Pi 2 Model B (with an active internet connection).

Pre-Code
Before you run the program, which is on GitHub, you need some add-ons.
Telepot
Telepot is needed so you can use Telegram bots in python. It's plain simple: Get Telepot, done. Just enter the following lines in your Raspberrys terminal:
sudo apt-get install python-pip
sudo pip install telepot
sudo pip install telepot --upgrade
gPhoto2
gPhoto2 enables the communication between the Pi and a connected camera. Here a wide range of cameras is supported, a list is here). Get it with the command:
wget https://raw.githubusercontent.com/gonzalo/gphoto2-updater/master/gphoto2-updater.sh && chmod +x gphoto2-updater.sh && sudo ./gphoto2-updater.sh
For testing please connect the camera via USB to the Raspberry.
Then open the terminal an enter the follwoing command:
sudo --gphoto2 --auto-detect

If that worked, go on.
The Code
As already said the code's on GitHub and is done with Python 2.7.
Token & User ID
Now we're going to need the token which you got from the BotFather. At the beginning of the Python code you'll find the line ...
Bot_Name = "CameraBot"
Bot_Token = "INSERT TOKEN HERE"
The botname is the name which will be shown in the messages. You have to change it with the BotFather (/setname). The token is now the unique ID for that bot.
When everything is set you can run the program. Start the terminal and go to the directory of the Python code. Then start it using the line ...
python DSLR_Telegram.py
The Admin-ID
At the moment there is now admin user. In the code the admin ID is set as a string of zeros. To find out your ID and to be able to insert it you have to start the bot with your phone or your PC.
You can do that when you enter the bots name in the search field. Be careful that you write it with an @ infront of the name. The bots name is not the one you created with /rename, but that one you've choosen at the beginning.
If the bot runs you'll get the message "Access denied". Additionally in the terminal on the Pi you'll who tried to access it. There you will also find the ID of your telegram account. Temrinate the Python script and enter your ID:
Admin_Users = [00000000] # INSERT USER ID !
Restart the script.
Add User
If you want to add a user, just let him send the keyword /start to your bot. Then you will get a message to your phone/PC with the ID. The message addressed only to the admin user - you.
Now send the following message to you bot: /addUser ID Forename Name
Be careful of the space between the words and don't leave anything blank. I haven't done a failsafe, so your Python script would crush if you do a mistake here. If you want to add a group to your bot just use (group) as name.
Yes I was lazy here.
Get Camera List
The camera list will be sent to you if you send the bot the /getCam command.

Get/Set Settings
You can change three settings. ISO, aperture, shutter speed. The syntax for use will be sent to you if you send the /info command to your bot.
The get command for the ISO-value is /getISO.

And with /setISO Value you can set the value. Attention to the space!

It's the same for the other two values:
- /getAV und /setAV Zahl für die Blende
- /getTV und /setTV Zahl für die Belichtungsdauer
Trigger Camera
Now you want to take a picture. Therefore use /pic.

I had to decrease the picture quality on the camera, due to my slow internet connection. Otherwise I would have waited 10 minutes for the picture.
Summary
I wanted to do two tasks at once with my Raspberry (that's my first project with it).
Telegram bots are a nice idea. You can make useful things like a remidner for groups or just for yourself. So you'll never forget about an appointment.
And then there's the opportunity to interact with your camera. I think that's really cool and useful. I think I will use it again in some of my camera related projects, maybe for time lapses or something like that.
If you don't know Python or if you have a general question -> deloarts.wordpress.com