telegram logo

All weekend I’ve been itching to write about telegram-cli, a command-line interface to—faux gasp of surprise—the Telegram messaging service.

Naturally, because I have something I’m keen to write about, the Wi-Fi in the coffee shop is acting up. As I’m relying on a ropey 3G tether (complete with 750MB data cap) I haven’t actually been able to try this app out.

As I’ve already bought a large latte and a bus ticket today, I need to get a return on my ‘investment’. So, apologies up front, I’m going to try and write about it anyway…

Back home I’ve tried the app out and it works just dandy!

telegram logo

整个周末我一直渴望写出来一篇关于 telegram-cli 的文章。telegram-cli  是一个完美到让人惊讶的命令行程序接口,进行 telegram 信息传送服务。

自然地,由于我正要写点东西,咖啡店的 Wi-Fi 就出毛病了(作者幽默调侃)。因为我在外面使用体验糟糕的 3G 服务(流量数据限制在750 MB以内),所以这时候我没有实际上体验过这个应用程序。

鉴于我已经买了一大杯拿铁,也付款了公交车费,我需要赚回我的“投资”(花销)。所以为了表达歉意,我无论如何也要尝试使用 telegram-cli并写点什么了……



Telegram Isn’t For Everyone

Telegram is a sort of open, secure messaging service that runs in the cloud. It provides a robust open API, puts a lot of emphasis on privacy, and offers a slate of mobile, web and desktop clients. These points alone have seen the service become incredibly popular with open-source, privacy and Linux enthusiasts.

Telegram lets you send regular text messages, photos, videos and other files to other Telegram users, as well as initiate  so-called ‘secret chats’ which are encrypted.

For the avoidance of doubt please note that I am not writing this post to persuade anyone that Telegram is ‘the best’ messaging service around. Nor am I going to say that it is the most secure, or that using it through a Terminal app makes any sense when various mobile and desktop GUI apps are freely available.

Telegram 的受众面并不是所有人

Telegram 是一个架构在云服务上面,开放的、安全的即时通讯服务。它提供强有力的开放 API (应用程序接口),把重点放在了客户隐私上面,并且跨平台地提供手机移动端、web页面、和桌面客户端。单单凭借这些方面,Telegram 服务就极其受开源社区、隐私重视者和 Linux 热衷者们的欢迎。

你可以在 Telegram 给别人发送常规的文字消息、照片、视频和其他类型的文件,此外,加入 ‘secret chats(加密聊天)’ 后,可以互相发送编码后加密的信息。

为了避免怀疑请注意:即使 Telegram 的各种移动端和桌面 GUI(Graphical User Interface 图形用户界面) 应用程序是免费的 ,我也不是写这篇文章来说服所有人Telegram 是“最好的”消息传递服务,也不会说它是最安全的,或者说使用了这个终端应用程序就有任何作用。


Nope, I’m just here to highlight an alternative way to use something that you may already use. If you find it helpful, fantastic. If you don’t, no worries.

Telegram-CLI Features

Like the fully-fledged clients, Telegram-cli lets you send, receive and read messages from your contacts, channels and groups. It offers the following features:

  • Colored terminal messages
  • Message management, including message history
  • Create/join/manage group chats
  • Start secure encrypted one-on-one conversations
  • Add/edit/remove contacts
  • Send/load photos and videos

Telegram-CLI rather helpfully supports tab completion. If you’re the sort of person who regularly forget commands, or simple like to speed up your workflow, you only need to remember the first few characters of any command, and the tab key will do the rest.

都不是,我只是想强调一下你可能已经使用的聊天软件的替代方法。如果你觉得 Telegram 好用,那太棒了。如果反之,我无所谓,没关系。

Telegram-CLI 的功能

就像其他已经做的很成熟的客户端一样, Telegram-cli 也可以收发联系人、频道、群组里面的消息。它提供以下功能:

  • 终端信息显示彩色
  • 消息管理,包括历史消息
  • 创建/加入/管理 群聊
  • 开启安全加密一对一的对话
  • 添加/编辑/删除 联系人
  • 发送/加载 照片和视频

Telegram-CLI 甚至更人性化地提供了 tab 键自动补全功能。如果你是那种经常忘记命令的人,或者单纯想提升工作效率,你只需要记住任何命令的前几个字符,然后按一下 Tab 键帮你补全命令。


Features that aren’t supported in telegram-cli include stickers, emoji, custom backgrounds, and other visual fluff.

How To Install Telegram CLI on Ubuntu


If you’re running Ubuntu 16.04 LTS or Ubuntu 16.10 you can install telegram-cli through the Snap store by searching for ‘telegram-cli’ in the Ubuntu Software app or running:

sudo snap install telegram-cli

Logging In

Like WhatsApp, Telegram is a service centred around your mobile number as your identity. You’ll need to have already signed up to Telegram from a mobile app before you can “log in” and use the service through the Terminal.

但是 telegram-cli 不支持 表情包,表情符号(emoji),自定义背景图,和其他视觉上的小花样。

如何在 Ubuntu 系统下载 Telegram CLI


如果你是 Ubuntu 16.04 LTS 或者 Ubuntu 16.10 系统的话,可以在 Ubuntu 软件中心通过搜索 ‘telegram-cli’ 经由 Snap store 下载。 或者执行命令:

sudo snap install telegram-cli

就像 WhatsApp 一样,Telegram 是基于手机号码来认证身份的服务。你需要先在移动端注册好号码,这样才能在终端通过命令行登录。


Assuming you have, just run the app using the following command:


This will prompt you for your phone number. Type it in to the terminal, then double-check that it’s correct. Press Enter.

A code will be sent to your mobile device. You simply need to enter this code into the Terminal when prompted to do so to authenticate.

After that, you’re good to go!

Using Telegram-CLI


Telegram works on the basis of “peers” rather than phone numbers. To see a list of people in your contacts list who you can message, type:


To view a list of all current chats, groups and unread messages type:






开始使用 Telegram-CLI


Telegram 的信息传送不是依赖电话号码,而是基于 “peer(对等网络)” 。如果要查看联系人的列表,您可以键入:




To message a contact or group, type msg followed by their name (remember that you can use tab to autocomplete) and then your message:

msg <name> <message>

To view a conversation or chat history type history followed by the name of the contact or group and the number of lines you wish to see:

history <peer> <number of lines>

E.g.: history Liam 10 will print the 10 most recent messages in my conversation with Liam:


You’ll find a comprehensive list of all the commands supported by telegram-cli on the project’s GitHub wiki:

View a List of Telegram-CLI Commands

Or, while using the client, by running help.


如果想私聊或者群聊,键入 msg 之后紧随他们的名字(请记住你可以使用 tab 自动补全),之后键入你要发的消息文本内容,就像这样:

 msg <name> <message>

若你要查看会话或聊天历史记录,请输入 history 之后紧随他们的名字或者群名,之后键入你希望看到的行数,就像这样:

history <peer> <number of lines>

例如:键入 history Liam 10,就会显示最近10条我和 Liam 谈话的信息。


你会在 telegram-cli 项目的 GitHub 维基里面找到一个详尽的列表:

View a List of Telegram-CLI Commands (源地址 https://github.com/vysheng/tg/wiki/Telegram-CLI-Commands)

或者在使用时,键入 help 获取帮助。