Mobile instant messaging from the Pi

Sending Messages

Now you can cut right to the chase and start annoying your friends. To send a single message to one of your contacts, type the following:

> msg <username> <message>

If you're not sure about your friends' usernames, you can list them with:

> contact_list

Note that Telegram has tab completion, which means you don't have to type out a command in full. For example, to get contact_list, you type con+Tab, which gives you contact; then, typing _+Tab completes the entire command.

In the contact list, you want to look at the names in green. Spaces, periods, and other symbols in contact names are substituted with underscores ( _ ). So, if you wanted to say hello to your friend Simon Pegg, you'd type:

> msg Simon_Pegg Hello!

To start a chat, you would use:

> chat_with_user Simon_Pegg

Messaging and chatting are different. After a message, you are immediately dumped back into the command line, and the program treats the next input as a command. While chatting, on the other hand, everything you type is treated like a message and is posted to your friend. To exit chat mode, type /exit or /quit.

You can send files (plain text, images, and videos) using send_text, send_photo, and send_video:

> send_<type> <username> </path/to/imagefile>

with <type> being text, photo, or video. So, to send a pic to Simon, you'd type

> send_photo Simon_Pegg /home/pi/Pictures/nick_frost.jpg

and off it would go.

Receiving Messages

Although receiving pure text messages is simple (they just pop up on the next line of the terminal), attachments are a little trickier.

To be able to download and view pictures and movies that are sent to you over the Telegram CLI client, you have to start the program with the -N option,

$ ./telegram -N

which shows an ID assigned to each message you receive.

This step is necessary because, when you are sent a message with an attachment, be it text, picture, or video, you use the message ID to save it or view it in your default viewer. An exchange could look something like this:

[23:01]  User Simon Pegg is now online
379 [23:05]  Simon Pegg >>> [photo]
[1 unread]view_photo 379

The last line opens your default viewer and shows the photo Simon sent in the message with ID 379. To download the photo without opening it, use the load_photo command. To download a video, you would use load_video, and to view the video, view_video.

Use the help command to bring up more information about the commands you can use. Table 1 shows some of the most useful commands. To close the Telegram CLI client, type quit at the prompt.

Table 1

Most Useful Telegram Commands

Command

Action

add_contact <phone-number> <username>

Tries to add a contact to the contact list by phone number.

chat_with_peer <user>

Starts chat with this user. Type /exit or /quit to end chat session.

chat_info <chat>

Prints information about chat.

contact_list

Prints info about users in your contact list.

create_secret_chat <user>

Creates secret chat with the named user.

dialog_list

Prints info about your dialogs.

fwd <user> <msgID>

Forward message to user. Start telegram with -N to see message IDs.

global_search pattern

Searches for the pattern in all messages.

help

Prints help.

history <user> [limit]

Prints history (and marks it as read). Default limit = 40.

load_photo <msgID>

Downloads photo to download directory. Start telegram with -N to see message IDs.

load_video <msgID>

Downloads video to download directory. Start telegram with -N to see message IDs.

mark_read <user>

Mark as read all received messages from user.

msg <user> Text

Sends message to user.

rename_contact <user> <username>

Tries to rename contact. Can cause conflicts with your other devices.

search <user> pattern

Searches for the pattern in messages from user.

send_photo <user> <filename>

Sends photo to user.

send_text <user> <filename>

Sends text file as plain message.

send_video <user> <filename>

Sends video to user.

suggested_contacts

Print info about potential contacts with whom you share friends.

user_info <user>

Prints info about user.

view_photo <msgID>

Downloads photo to download directory and starts system's default viewer. Start telegram with -N to see message IDs.

view_video <msgID>

Downloads video to download directory and starts system's default viewer. Start telegram with -N to see message IDs.

visualize_key <secret_chat>

Prints encryption key. You should compare it with your partner's.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Host a secret chat using Mesh

    With Mesh, an unlimited number of Scratch projects can interact by using variables and broadcasts over a local network. We show how to communicate across Mesh by building a multiuser chat program.

  • Waking the Raspberry Pi with a wireless command

    If you want to power your Pi solely with batteries, then it makes sense for the Pi to only be turned on when you need it. The Pi can boot when called remotely via radio signal sent over the European 868 MHz band.

  • Tracking airplanes in real time with ADS-B

    Airplanes continuously broadcast signals that identify the aircraft and its current flight path. With a moderately priced receiver and a Raspberry Pi, users can receive ADS-B transponder data in real time.

  • Working with the Raspberry Pi camera module

    The amazing Raspberry Pi camera module opens into a whole new world of useful projects. We'll show you how to use the Pi camera for time-lapse photography, and we'll even help you set up a motion-detecting surveillance camera.

  • DIY body cam with a Raspberry Pi

    Make your own body cam with a Raspberry Pi, a cannibalized webcam, a WiFi module, and some Python.