• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

debian/H06-Jan-2020-255210

gentoo/net-im/telegram-cli/H06-Jan-2020-4234

parts/plugins/H06-Jan-2020-6649

rpm/H06-Jan-2020-10687

tgl/H03-Feb-2019-40,72433,719

.gitignoreH A D06-Jan-2020320 2726

.gitmodulesH A D06-Jan-202079 43

.travis.ymlH A D06-Jan-2020343 2823

CHANGELOGH A D06-Jan-20201.1 KiB4543

LICENSEH A D06-Jan-202017.7 KiB340281

LICENSE.hH A D06-Jan-202019 KiB340339

Makefile.inH A D06-Jan-20202.3 KiB7252

Makefile.tglH A D06-Jan-20203.1 KiB5733

Makefile.tl-parserH A D06-Jan-2020316 85

README-Cygwin.mdH A D06-Jan-20202.5 KiB7744

README-LUAH A D06-Jan-20203.1 KiB8759

README-PY.mdH A D06-Jan-202012.4 KiB178162

README.esH A D06-Jan-20205.9 KiB14687

README.mdH A D06-Jan-202011.1 KiB266169

ax_lua.m4H A D06-Jan-202024.2 KiB615561

ax_python.m4H A D06-Jan-20203.9 KiB113105

bootstrapH A D06-Jan-202071 74

compile_osx.shH A D06-Jan-2020226 64

config.h.inH A D06-Jan-20204.9 KiB197133

config.sampleH A D06-Jan-2020950 6250

configureH A D03-May-2022229.2 KiB8,0956,671

configure.acH A D06-Jan-20205.9 KiB196168

event-old.hH A D06-Jan-20201.7 KiB4940

interface.cH A D06-Jan-2020146.3 KiB4,5323,984

interface.hH A D06-Jan-20203 KiB9359

json-tg.cH A D06-Jan-202019.8 KiB519472

json-tg.hH A D06-Jan-2020402 1514

loop.cH A D06-Jan-202023.1 KiB882743

loop.hH A D06-Jan-20201 KiB3010

lua-tg.cH A D06-Jan-202065.5 KiB2,2271,886

lua-tg.hH A D06-Jan-20201.2 KiB3615

m4-ax_gcc_builtin.m4H A D06-Jan-20205.7 KiB169163

m4_ax_check_openssl.m4H A D06-Jan-20204.1 KiB125113

m4_ax_check_zlib.m4H A D06-Jan-20205.3 KiB143138

main.cH A D06-Jan-202026.4 KiB1,040867

mime.typesH A D03-Feb-201951.8 KiB1,5901,589

python-tg.cH A D06-Jan-202044.4 KiB1,4081,151

python-tg.hH A D06-Jan-20204.1 KiB9163

python-types.cH A D06-Jan-202042.4 KiB1,5891,270

python-types.hH A D06-Jan-2020352 2215

server.pubH A D06-Jan-2020426 98

snapcraft.yamlH A D06-Jan-2020626 3430

start-telegram-daemonH A D06-Jan-20205.2 KiB207154

telegram-cli-cygwin.patchH A D06-Jan-20201.9 KiB3935

telegram-daemonH A D06-Jan-20208.2 KiB333252

telegram.1H A D06-Jan-20206.9 KiB237219

telegram.hH A D06-Jan-2020840 254

test.luaH A D06-Jan-20202.5 KiB127100

tg-server.pubH A D06-Jan-2020427 108

tg-test.pyH A D06-Jan-20201.6 KiB7653

README-Cygwin.md

1### Installation on Windows
2To use telegram-cli in Windows, you should compile with Cygwin which has POSIX API functionality.
3
4Install [Cygwin](https://www.cygwin.com/).
5
6In Cygwin Terminal, install cygwin's package manager, apt-cyg, as per apt-cyg's [project page](https://github.com/transcode-open/apt-cyg):
7
8     lynx -source rawgit.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
9     install apt-cyg /bin
10
11Then install compiler and tools: if you're on the **32-bit** version of cygwin,
12
13     apt-cyg install gcc-core gcc-g++ gcc-core gcc-g++ make wget patch diffutils grep tar gzip autoconf automake libtool git zlib-devel
14
15Whereas on the **64-bit** version,
16
17     apt-cyg install cygwin32-gcc-core cygwin32-gcc-g++ gcc-core gcc-g++ make wget patch diffutils grep tar gzip zlib-devel
18
19You need libraries *readline*, *openssl*, *libconfig*, *liblua*, *python* and *libjansson* to use telegram-cli's full functionality.
20
21Clone this project's GitHub Repository in Cygwin Terminal
22
23     git clone --recursive https://github.com/vysheng/tg.git
24
25Then type:
26
27     apt-cyg install libevent-devel openssl-devel libreadline-devel lua-devel python3
28
29(Install package 'python' to use Python 2.7, or install package 'python3' to use Python 3)
30
31libconfig and libjansson are not included in the cygwin package, so you should compile them yourself.
32
33Compile libconfig:
34
35     wget https://github.com/hyperrealm/libconfig/archive/v1.7.2.tar.gz
36     mv v1.7.2.tar.gz libconfig-1.7.2.tar.gz
37     tar xvf libconfig-1.7.2.tar.gz && cd libconfig-1.7.2
38     autoreconf
39     ./configure
40     make && make install && cd ..
41
42Compile libjansson:
43
44     wget http://www.digip.org/jansson/releases/jansson-2.7.tar.gz
45     tar xvf jansson-2.7.tar.gz && cd jansson-2.7
46     ./configure
47     make && make install && cd ..
48
49Then, change to the tg directory and generate the Makefile.
50
51     cd tg
52     ./configure
53
54In case `configure` fails, it might be because of the CRLF line endings, so:
55
56     dos2unix -f configure
57
58And again,
59
60     ./configure
61
62We need to patch the Makefile and loop.c to compile properly in cygwin. The patch is included, so just type:
63
64     patch -p1 < telegram-cli-cygwin.patch
65
66Then,
67
68     make
69
70Once the compilation is complete, **telegram-cli.exe** will be found in the **bin** subdirectory.
71
72To run `telegram-cli`, type
73
74     bin/telegram-cli -k tg-server.pub
75
76**Caution**: A binary compiled with Cygwin should be run in Cygwin Terminal.
77

README-LUA

1To use lua with client you should write lua script. You can specify it from config ("lua_script" option) or from command_line [-s].
2
3It should have several functions:
4  on_binlog_replay_end() - it is called when replay of old events end. Any updates prior this call were already received by this client
5                           some time ago.
6
7  on_get_difference_end() - it is called after first get_difference call. So we received all updates after last client execute.
8
9  on_our_id(our_id) - Informs about id of currently logged in user.
10
11  on_msg_receive(msg) - it is called when we receive new msg (!! may be called before on_binlog_replay_end, than it is old msg).
12  on_msg_history(msg) - it is called when a msg from history is printed.
13
14  on_user_update(user,what_changed) - updated info about user. what_changed is array of strings.
15  on_chat_update(user,what_changed) - updated info about user. what_changed is array of strings.
16  on_secret_chat_update(user,what_changed) - updated info about user. what_changed is array of strings.
17
18
19
20Also, you can call several functions. Each this function last two arguments, are cb_function and cb_extra.
21These functions may return false immidiately if something is bad with args, or return true and call cb_function in future.
22cb_function would have two or three arguments: first cb_extra, second success (1 or 0), third result (if applicable).
23
24If you want to pass msg to function, you should pass it's id.
25If you want to pass peer to function, you should pass it's print_name.
26Or, you can pass string user#id<id> chat#id<id> and secret_chat#id<id> as peer. It is in some cases better. For example if you want to postpone and you are afraid, that print_name would be changed in the meantime.
27
28Function_list (arguments are listed aside from cb_function and cb_extra, :
29  get_contact_list ()
30  get_dialog_list ()
31
32  rename_chat (chat, new_name)
33  chat_set_photo (chat, file)
34
35  send_typing (peer)
36  send_typing_abort (peer)
37
38  send_msg (peer, text)
39  fwd_msg (peer, msg)
40
41  send_photo (peer, file)
42  send_video (peer, file)
43  send_audio (peer, file)
44  send_document (peer, file)
45  send_text (peer, file)
46
47  load_photo(msg)
48  load_video(msg)
49  load_video_thumb(msg)
50  load_audio(msg)
51  load_document(msg)
52  load_document_thumb(msg)
53
54  chat_info (chat)
55  channel_info (channel)
56  user_info (user)
57
58  get_history (peer, limit)
59
60  chat_add_user (chat, user)
61  chat_del_user (chat, user)
62
63  add_contact (phone, first_name, last_name)
64  rename_contact (phone, first_name, last_name)
65
66  msg_search (peer, text)
67  msg_global_search (text)
68
69  mark_read (peer)
70
71  set_profile_photo (file)
72
73  create_secret_chat (user)
74  create_group_chat (user, name)
75
76  delete_msg (msg)
77  restore_msg (number)
78
79  status_online ()
80  status_offline ()
81
82  send_location (peer, latitude, longitude)
83
84Also, you have function
85  postpone (cb_function, cb_extra, timeout). It will call your cb_function in specified number of seconds (number of seconds may be double).
86  register_interface_function (name, cb_function, cb_arg, description, arg1_type, arg2_type, ...) adds function to CLI interface
87

README-PY.md

1Python Bindings
2====================
3All of the functions and methods are executed in the network loop of tg, ***NOT IMMEDIATELY***. What this means is all calls should be considered async, and so there is an optional callback parameter for every function/method as the last parameter. For many uses, you won't care about the return value, so you can leave out the callback. Note there are a few cases where the callback is considered mandatory when the function is considered an information query and has no functionality without returned data. These will explicitly have the callback in the parameter list and will be noted in the description.
4
5You can specify the python script from config ("python_script" option) or from command_line [-Z].
6
7Version Notes
8=====================
9The python integration is written with Python 2/3 in mind, however, there is a bias to Python 3. Because of this, there are a few caveats:
10- I am only testing against Python 2.7, and have no intention to support/test < 2.7 but am more than happy to accept PRs for fixes as long as it does not break 2.7/3
11- repr/print of native types is dumbed down for < 2.7.9, I highly recommend using this version or newer. (This is due to a [bug](http://bugs.python.org/issue22023) in python)
12
13TGL Callbacks
14=============
15Assign python fuctions to the following tgl attributes to set callbacks from TG.
16
17| Callback | Description          |
18|--------- | ---------------------|
19|`tgl.on_binlog_replay_end()` | This is called when replay of old events end. Any updates prior this call were already received by this client some time ago.|
20|`tgl.on_get_difference_end()`| This is called after first get_difference call. So we received all updates after last client execute.|
21|`tgl.on_our_id(our_id)`|Informs about id of currently logged in user.|
22|`tgl.on_msg_receive(msg)`| This is called when we receive new `tgl.Msg` object (*may be called before on_binlog_replay_end, than it is old msg*).|
23|`tgl.on_msg_history(msg)`| This is called when we receive a `tgl.Msg` object from a history printing.|
24|`tgl.on_user_update(peer, what_changed)`|updated info about user. peer is a `tgl.Peer` object representing the user, and what_changed is array of strings.|
25|`tgl.on_chat_update(peer, what_changed)`|updated info about chat. peer is a `tgl.Peer` object representing the chat, and what_changed is array of strings.|
26|`tgl.on_secret_chat_update(peer, what_changed)`|updated info about secret chat. peer is a `tgl.Peer` object representing the secret chat, and  what_changed is array of strings.|
27|`tgl.on_loop()` | This is called every now and then.|
28
29Python Callback Signatures
30=========================
31As mentioned, all methods and functions have callbacks. The following are the different signatures that may be required (*The description of the method will mention which is used*)
32
33| Type | Signature          | Description |
34|----- | ------------------ | ------------|
35|empty_cb|`(success)`|This just indicated the success of the call. All other callback types have this as well.|
36|contact_list_cb|`(success, peer_list)`|`peer_list` is a list of `tgl.Peer` objects|
37|dialog_list_cb|`(success, dialog_list)`|`dialog_list` is a list of dicts, with keys: 'peer': `tgl.Peer`, 'unread': `bool( Determine whether has unread message)`|
38|msg_cb|`(success, msg)`|`msg` is a `tgl.Msg`|
39|msg_list_cb|`(success, msg_list)`|`msg_list` is a list of `tgl.Msg` objects|
40|file_cb|`(success, file_path)`|`file_path` is a string with an absolute path|
41|chat_cb|`(success, peer)`|`peer` is a `tgl.Peer` that will have the type of `tgl.PEER_CHAT`|
42|peer_cb|`(success, peer)`|`peer` is a `tgl.Peer`|
43|secret_chat_cb|`(success, peer)`|`peer` is a `tgl.Peer` that will have the type of `tgl.PEER_ENCR_CHAT`|
44|user_cb|`(success, peer)`|`peer` is a `tgl.Peer` that will have the type of `tgl.PEER_USER`|
45|str_cb|`(success, string)`|`string` is a simple string|
46
47TGL Module Level Fuctions
48=========================
49All of these functions are accessed by importing the `tgl` module.
50
51| Function | Description          | Callback Type |
52|--------- | ---------------------| ------------- |
53|`tgl.get_contact_list (callback)`|Retrieve peers stored in the contact list. *requires callback*|`contact_list_cb`|
54|`tgl.get_dialog_list (callback)`|Get a list of current conversations with the `tgl.Peer` and the most recent `tgl.Msg`. *requires callback*|`dialog_list_cb`|
55|`tgl.add_contact (phone, first_name, last_name)`|Adds contact to contact list, last name is optional|`contact_list_cb`|
56|`tgl.del_contact (peer)`|Removes contact from contact list|`empty_cb`|
57|`tgl.rename_contact (phone, first_name, last_name) `|Renaming a contact means sending the first/last name with the same phone number of an existing contact|`contact_list_cb`|
58|`tgl.msg_global_search (text, callback)`|Get all messages that match the search text. *requires callback*|`msg_list_cb`|
59|`tgl.set_profile_photo (file_path)`|Sets avatar to image found at `file_path`, no checking on the file.|`empty_cb`|
60|`tgl.create_secret_chat (user)`|Creates secret chat with user, callback recommended to get new peer for the secret chat.|`secret_chat_cb`|
61|`tgl.create_group_chat (peer_list, name)`|`peer_list` contains users to create group with, must be more than 1 peer.|`empty_cb`|
62|`tgl.delete_msg (msg_id)`|Deletes the message from the local history.|`empty_cb`|
63|`tgl.restore_msg (msg_id)`|Restore a deleted message by message id.|`empty_cb`|
64|`tgl.status_online ()`|Sets status as online|`empty_cb`|
65|`tgl.status_offline ()`|Sets status as offline|`empty_cb`|
66|`tgl.import_chat_link (link)`|Join channel using the `link`.|`empty_cb`|
67|`tgl.safe_exit (exit_status)`|Exception to the rule about callbacks, no callback parameter is accepted. Causes the bot to quit after cleaning up. `exit_status` is an optional parameter with the exit status (On glibc, this must be 0-255)|NONE|
68
69Peer
70====
71## Attributes
72| Attribute | Type |  Description          |
73|---------- | ---- | ----------------------|
74|`id`|`int`|Telegram peer id|
75|`type`|`int`|Peer type, you can compare this with `tgl.PEER_CHAT`, `tgl.PEER_USER`, or `tgl.PEER_ENCR_CHAT`|
76|`type_name`|`string`|Text representation of the type of the peer, `'chat'`, `'user'`, or `'secret_chat'`|
77|`name`|`string`|Returns the tg print version of the name. Usually `FirstName_LastName` for user, and the chatname with spaces replaced with `_`|
78|`user_id`|`int`|Used in secret chats, since a secret chat has it's own id, this is the id of the user at the endpoint.|
79|`user_list`|`peer_list`|Only used in `tgl.PEER_CHAT` peers, contains list of users. This currently does not work, it is not populating properly.|
80|`user_status`|`dict`|Only used in `tgl.PEER_USER` peers. Dictionary with the current status, keys: 'online': `bool`, 'when': `datetime`|
81|`phone`|`string`|Only used in `tgl.PEER_USER` peers. Phone number, only available if user is on contact list.|
82|`username`|`string`|Only used in `tgl.PEER_USER` peers. Will be `None` if username is not set.|
83|`first_name`|`string`|Only used in `tgl.PEER_USER` peers.|
84|`last_name`|`string`|Only used in `tgl.PEER_USER` peers.|
85
86## Methods
87| Method | Description          | Callback Type |
88|------- | ---------------------| ------------- |
89|`peer.rename_chat (new_name)`||`empty_cb`|
90|`peer.chat_set_photo (file)`|Sets avatar for the group to image found at `file_path`, no checking on the file. The calling peer must be of type `tgl.PEER_CHAT`.|`msg_cb`|
91|`peer.send_typing ()`|Tell peer that you are typing.|`empty_cb`|
92|`peer.send_typing_abort ()`|Tell peer you are done typing.|`empty_cb`|
93|`peer.send_msg (text, reply=msg_id, preview=bool)`|Sends message to peer. Optional keyword arguments: reply is the message id we are replying to, preview is a boolean that forces URL preview on or off.|`msg_cb`|
94|`peer.fwd_msg (msg_id)`|Forwards msg with message id to peer.|`msg_cb`|
95|`peer.fwd_media (msg_id)`|Forwards media with message id to peer.|`msg_cb`|
96|`peer.send_photo (file)`|Send media to peer using `file`. No checking is done on the contents of the file.|`msg_cb`|
97|`peer.send_video (file)`|Send media to peer using `file`. No checking is done on the contents of the file.|`msg_cb`|
98|`peer.send_audio (file)`|Send media to peer using `file`. No checking is done on the contents of the file.|`msg_cb`|
99|`peer.send_document (file)`|Send media to peer using `file`. No checking is done on the contents of the file.|`msg_cb`|
100|`peer.send_text (file)`|Send media to peer using `file`. No checking is done on the contents of the file.|`msg_cb`|
101|`peer.send_location (latitude, longitude)`|Sends location media message to peer, `longitude` and `latitude` should be specified as double.|`msg_cb`|
102|`peer.chat_add_user (user)`|Adds `user`(`tgl.Peer`) to the group. The calling peer must be of type `tgl.PEER_CHAT`|`empty_cb`|
103|`peer.chat_del_user (user)`|Removes `user`(`tgl.Peer`) from the group. The calling peer must be of type `tgl.PEER_CHAT`|`empty_cb`|
104|`peer.mark_read ()`|Marks the dialog with the peer as read. This cannot be done on message level.|`empty_cb`|
105|`peer.msg_search (text, callback)`|Get all messages that match the search text with the peer. *requires callback*|`msg_list_cb`|
106|`peer.history (offset, limit, callback)`|Get all messages with the peer. `offset` specifies what message to start at, and `limit` specifies how many messages to retrieve. See example below for one method to get the entire history. *requires callback*|`msg_list_cb`|
107|`peer.info ()`|Gets peer info.|`peer_cb`|
108
109Example usage for `peer.history`:
110```
111from functools import partial
112history = []
113# Get all the history, 100 msgs at a time
114peer.history(0, 100, partial(history_callback, 100, peer))
115
116def history_callback(msg_count, peer, success, msgs):
117    history.extend(msgs)
118    if len(msgs) == msg_count:
119        peer.history(len(history), msg_count, partial(history_callback, msg_count, peer))
120```
121
122Msg
123====
124## Attributes
125| Attribute | Type |  Description          |
126|---------- | ---- | ----------------------|
127|`id`|`int`|Message id|
128|`flags`|`int`|tgl flags, see source code for tgl for various possible flags. This is a bitfield in an int.|
129|`mention`|`bool`|`True` if you are @mentioned.|
130|`out`|`bool`|`True` if you sent this message.|
131|`unread`|`bool`|`True` if you have not marked this as read.|
132|`service`|`bool`|`True` if the message is a service messages, see tgl.Msg.action for the type.|
133|`src`|`tgl.Peer`|Peer who sent the message|
134|`dest`|`tgl.Peer`|Peer who the message was sent too. In a group, this will be the chat peer. Otherwise it will be you.|
135|`text`|`string`|Text contents of the message. This may be `None` if it's media without caption.|
136|`media`|`dict`|Dictionary that varies based on the media type.|
137|`date`|`datetime`|When the message was sent.|
138|`fwd_src`|`tgl.Peer`|The user that sent the forwarded message.|
139|`fwd_date`|`datetime`|When the forwarded message was originally sent.|
140|`reply`|`tgl.Msg`|Message that this message is replying to.|
141|`reply_id`|`int`|Message id that this message is replying to.|
142|`action`|`int`|Action enum for the message if `msg.service == True`. See all the possible values below|
143
144## Action Type Constants
145- tgl.ACTION_NONE
146- tgl.ACTION_GEO_CHAT_CREATE
147- tgl.ACTION_GEO_CHAT_CHECKIN
148- tgl.ACTION_CHAT_CREATE
149- tgl.ACTION_CHAT_EDIT_TITLE
150- tgl.ACTION_CHAT_EDIT_PHOTO
151- tgl.ACTION_CHAT_DELETE_PHOTO
152- tgl.ACTION_CHAT_ADD_USER
153- tgl.ACTION_CHAT_ADD_USER_BY_LINK
154- tgl.ACTION_CHAT_DELETE_USER
155- tgl.ACTION_SET_MESSAGE_TTL
156- tgl.ACTION_READ_MESSAGES
157- tgl.ACTION_DELETE_MESSAGES
158- tgl.ACTION_SCREENSHOT_MESSAGES
159- tgl.ACTION_FLUSH_HISTORY
160- tgl.ACTION_RESEND
161- tgl.ACTION_NOTIFY_LAYER
162- tgl.ACTION_TYPING
163- tgl.ACTION_NOOP
164- tgl.ACTION_COMMIT_KEY
165- tgl.ACTION_ABORT_KEY
166- tgl.ACTION_REQUEST_KEY
167- tgl.ACTION_ACCEPT_KEY
168
169## Methods
170| Method | Description          | Callback Type |
171|------- | ---------------------| ------------- |
172|`msg.load_photo(callback)`|Saves the media and returns the path to the file in the callback. *requires callback*|`file_cb`|
173|`msg.load_video(callback)`|Saves the media and returns the path to the file in the callback. *requires callback*|`file_cb`|
174|`msg.load_video_thumb(callback)`|Saves the media and returns the path to the file in the callback. *requires callback*|`file_cb`|
175|`msg.load_audio(callback)`|Saves the media and returns the path to the file in the callback. *requires callback*|`file_cb`|
176|`msg.load_document(callback)`|Saves the media and returns the path to the file in the callback. *requires callback*|`file_cb`|
177|`msg.load_document_thumb(callback)`|Saves the media and returns the path to the file in the callback. *requires callback*|`file_cb`|
178

README.es

1## Telegram messenger CLI [![Build Status](https://travis-ci.org/kenorb-contrig/tg.png)](https://travis-ci.org/kenorb-contrig/tg)
2
3!!!! May be outdated. Please refer to english README as more actual.
4
5
6Interfaz de línea de comandos para: [Telegram](http://telegram.org). Usa interfaz readline.
7
8### Documentación del API y el protocolo
9
10La documentación del APi de Telegram está disponible aquí: http://core.telegram.org/api
11
12La documentación del protocolo MTproto está disponible aquí: http://core.telegram.org/mtproto
13
14### Instalación
15
16Clona el Repositorio GitHub
17
18    $ git clone --recursive https://github.com/kenorb-contrig/tg.git && cd tg
19
20o descarga y descomprime el zip
21
22    $ wget https://github.com/kenorb-contrig/tg/archive/master.zip -O tg-master.zip
23    $ unzip tg-master.zip && cd tg-master
24
25#### Linux
26
27Librerías requeridas: readline openssl y (si desea usar config) libconfig y liblua.
28Si no deseas usarlo, pasa las siguientes opciones --disable-libconfig y --disable-liblua respectivamente.
29
30En Ubuntu usa:
31
32    $ sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev
33
34En gentoo:
35
36    $ sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua
37
38En Fedora:
39
40    $ sudo yum install lua-devel openssl-devel libconfig-devel readline-devel
41
42Por defecto Makefile utiliza liblua5.2 de ubuntu. Si utilizas una versión diferente de liblua o linux, tienes que ejecutar el script ./configure o recibirás un error de compilación extraño.
43
44Entonces
45
46    $ ./configure
47    $ make
48
49
50#### Mac OS X
51
52El cliente depende de [librería readline](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) y [libconfig](http://www.hyperrealm.com/libconfig/), las cuales no están incluídas en OS X por defecto. Debes instalar estas librerías de forma manual, usando por ejemplo [Homebrew](http://brew.sh/).
53
54    $ brew install libconfig
55    $ brew install readline
56    $ brew install lua
57    $ export CFLAGS="-I/usr/local/include -I/usr/local/Cellar/readline/6.2.4/include"
58    $ export LDFLAGS="-L/usr/local/lib -L/usr/local/Cellar/readline/6.2.4/lib"
59    $ ./configure && make
60
61Gracias a [@jfontan](https://github.com/vysheng/tg/issues/3#issuecomment-28293731) por esta solución.
62
63#### FreeBSD
64
65Instalar estos puertos:
66
67* devel/libconfig
68* devel/libexecinfo
69
70Entonces construir:
71
72    $ env CC=clang CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ./configure
73    $ make
74
75#### Otros UNIX
76
77Si logras ejecutarlo en otros UNIX, por favor házmelo saber.
78
79
80### Uso
81
82    ./telegram -k <clave-servidor-público>
83
84
85Por defecto la clave pública se almacena en la misma carpeta con el nombre tg-server.pub o en /etc/telegram/server.pub, si no lo es, indica dónde encontrarlo:
86
87    ./telegram -k tg-server.pub
88
89El Cliente soporta completamiento con TAB e historial de comandos.
90
91Peer se refiere al nombre del contacto o de diálogo y se puede acceder por completamiento con Tab.
92Para los contactos de usuario el peer es el Nombre <guión bajo> Apellido con todos los espacios cambiados a guiones bajos.
93Para los chats es su título con todos los espacios cambiados a guiones bajos.
94Para los chats encriptados es <marca de exclamación> <guión bajo> Nombre <guión bajo> Apellido con todos los espacios cambiados a guiones bajos.
95
96Si dos o más peers tienen el mismo nombre, una almohadilla y un número es añadido al nombre. (por ejemplo A_B,A_B#1,A_B#2 y así sucesivamente).
97
98### Comandos soportados
99
100#### Mensajería
101
102
103* **msg** \<peer\> texto - envía el mensaje a este usuario.
104* **fwd** \<usuario\> \<numero-mensaje\> - reenviar un mensaje al usuario. Puedes ver los número de mensajes iniciando el Cliente con -N.
105* **chat_with_peer** \<peer\> - inicia un chat con este usuario. /exit o /quit para salir de este modo.
106* **add_contact** \<numero-teléfono\> \<nombre\> \<apellido\> - intenta añadir este contacto a la lista de contactos.
107* **rename_contact** \<usuario\> \<nombre\> \<apellido\> - intenta renombrar el contacto. Si tienes otro dispositivo será una pelea.
108* **mark_read** \<peer\> - marca todos los mensajes como recibidos de ese usuario.
109
110#### Multimedia
111
112* **send_photo** \<peer\> \<nombre-archivo-foto\> - manda una foto al usuario.
113* **send_video** \<peer\> \<nombre-archivo-video\> - envia un video al usuario.
114* **send_text** \<peer\> \<nombre-archivo-texto> - envia un archivo de texto como un mensaje en plano.
115* **load_photo**/load_video/load_video_thumb \<numero-mensaje\> - carga foto/video indicado del directorio de descarga.
116* **view_photo**/view_video/view_video_thumb \<numero-mensaje\> - carga foto/video indicado del directorio de descarga y lo abre con el visor por defecto del sistema.
117
118
119#### Opciones de chat de grupo
120
121* **chat_info** \<chat\> - imprime información del chat.
122* **chat_add_user** \<chat\> \<usuario\> - agrega un usuario al chat.
123* **chat_del_user** \<chat\> \<usuario\> - elimina un usuario del chat.
124* **rename_chat** \<chat\> \<nuevo-nombre\> - cambia el nombre al chat.
125
126#### Search
127
128* **search** \<peer\> patrón - busca el patrón indicado en los mensajes con ese usuario.
129* **global_search** patrón - busca el patrón indicado en todos los mensajes.
130
131#### Chat secreto
132
133* **create_secret_chat** \<user\> - crea un chat secreto con el usuario indicado.
134* **visualize_key** \<secret_chat\> - Muestra la clave de cifrado. Debes compararla con la del otro usuario.
135
136#### Estadísticas e información varia.
137
138* **user_info** \<user\> - muestra información sobre el usuario.
139* **history** \<peer\> [limit] - muestra el historial (y la marca como leído). Limite por defecto = 40.
140* **dialog_list** - muestra información acerca del dialogo
141* **contact_list** - muestra información acerca de tu lista de contactos.
142* **suggested_contacts** - muestra información sobre sus contactos, tiene un máximo de amigos comunes.
143* **stats** - solo para depuración.
144* **show_license** - muestra la licencia GPLv2.
145* **help** - imprime esta ayuda.
146

README.md

1## Telegram messenger CLI
2
3Command-line interface for [Telegram](http://telegram.org). Uses readline interface. It is client implementation of TGL library.
4
5> Note: This is a fork of [`telegram-cli`](https://github.com/vysheng/tg).
6
7Build status:
8
9| Repository                                             | Status|
10| ------------------------------------------------------ | ----- |
11| [vysheng](https://github.com/vysheng/tg) (main)        |[![Build Status](https://travis-ci.org/vysheng/tg.png)](https://travis-ci.org/vysheng/tg)|
12| [kenorb-contrib](https://github.com/kenorb-contrib/tg) |[![Build Status](https://travis-ci.org/kenorb-contrib/tg.png)](https://travis-ci.org/kenorb-contrib/tg)|
13
14### API, Protocol documentation
15
16Documentation for Telegram API is available here: <http://core.telegram.org/api>
17
18Documentation for MTproto protocol is available here: <http://core.telegram.org/mtproto>
19
20### Upgrading to version 1.0
21
22First of all, the binary is now in ./bin folder and is named telegram-cli. So be careful, not to use old binary.
23
24Second, config folder is now ${HOME}/.telegram-cli
25
26Third, database is not compatible with older versions, so you'll have to login again.
27
28Fourth, in `peer_name` '#' are substitued to '@'. (Not applied to appending of '#%d' in case of two peers having same name).
29
30### Installation
31
32Clone this GitHub repository with `--recursive` parameter to clone submodules.
33
34     git clone --recursive https://github.com/CHANGETHIS/tg.git && cd tg
35
36### Python Support
37
38Python support is currently limited to Python 2.7 or Python 3.1+. Other versions may work but are not tested.
39
40#### Linux and BSDs
41
42Install libs: readline, openssl and (if you want to use config) libconfig, liblua, python and libjansson.
43If you do not want to use them pass options --disable-libconfig, --disable-liblua, --disable-python and --disable-json respectively.
44
45On Ubuntu/Debian use:
46
47     sudo apt-get install libreadline-dev libconfig-dev libssl1.0-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev libpython3-dev libgcrypt-dev zlib1g-dev lua-lgi make
48
49To build and install the packaege, run:
50     dpkg-buildpackage -b
51     sudo dpkg -i ../telegram-cli_x.x.x-x_amd64.deb
52
53On Gentoo:
54
55     sudo emerge -av sys-libs/readline dev-libs/libconfig dev-libs/openssl dev-lang/lua dev-libs/libevent dev-libs/jansson dev-lang/python
56
57On Fedora:
58
59     sudo dnf install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel jansson-devel python-devel libgcrypt-devel
60
61On CentOS:
62
63     sudo yum install lua-devel openssl-devel libconfig-devel readline-devel libevent-devel jansson-devel python-devel
64
65On Archlinux:
66
67     yaourt -S telegram-cli-git
68
69On Milislinux:
70
71     mps kur telegram-cli
72
73On FreeBSD:
74
75     pkg install libconfig libexecinfo lua52 python jansson
76
77On OpenBSD:
78
79     pkg_add libconfig libexecinfo lua python
80
81On openSUSE:
82
83     sudo zypper in lua-devel libconfig-devel readline-devel libevent-devel libjansson-devel python-devel libopenssl-devel
84
85Then,
86
87     ./configure
88     make
89
90If you are going to build tg on OpenBSD or FreeBSD, please use `gmake` instead of `make`.
91
92#### Other methods to install on linux
93
94On Gentoo: use ebuild provided.
95
96On Arch: https://aur.archlinux.org/packages/telegram-cli-git
97
98#### Mac OS X
99
100The client depends on [readline library](http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html) and [libconfig](http://www.hyperrealm.com/libconfig/), which are not included in OS X by default. You have to install these libraries manually.
101
102If using [Homebrew](http://brew.sh/):
103
104     brew tap ivoputzer/tg
105     brew install tg
106
107or manually:
108
109     brew install libconfig readline lua python libevent jansson
110     export READLINEPATH=$(brew --prefix readline)
111     export OPENSSLPATH=$(brew --prefix openssl)
112     export CPPFLAGS="-I/usr/local/opt/openssl/include -I$READLINEPATH/include -W"
113     export CFLAGS="-I/usr/local/include -I$READLINEPATH/include -I$OPENSSLPATH/include"
114     export LDFLAGS="-L/usr/local/lib -L$READLINEPATH/lib -L$OPENSSLPATH/lib"
115
116     ./configure
117
118You might have to manually pass the location of OpenSSL to `configure`:
119
120    $ brew info openssl
121    openssl: stable 1.0.2e (bottled) [keg-only]
122    Poured from bottle /usr/local/Cellar/openssl/1.0.2e_1 (465 files, 11.9M)
123
124so in this case the configure should be run as:
125
126     ./configure --with-openssl=/usr/local/Cellar/openssl/1.0.2e_1
127
128in other cases OpenSSL could be found in `/usr/local/opt`, e.g.:
129
130     ./configure --with-openssl=/usr/local/opt/openssl
131
132If you get a LUA error on Sierra, you can configure without LUA using
133
134     ./configure --disable-liblua
135
136After configuration run build:
137
138    make
139
140Thanks to [@jfontan](https://github.com/vysheng/tg/issues/3#issuecomment-28293731) for this solution.
141
142If using [MacPorts](https://www.macports.org):
143
144     sudo port install libconfig-hr
145     sudo port install readline
146     sudo port install lua51
147     sudo port install python34
148     sudo port install libevent
149     export CFLAGS="-I/usr/local/include -I/opt/local/include -I/opt/local/include/lua-5.1"
150     export LDFLAGS="-L/usr/local/lib -L/opt/local/lib -L/opt/local/lib/lua-5.1"
151     ./configure && make
152
153#### Docker
154
155The set for dockerizing the app: https://github.com/semenyukdmitry/telegram_cli_docker.
156
157#### Other UNIX
158
159If you manage to launch it on other UNIX, please let me know.
160
161### Contacts
162If you would like to ask a question, you can write to my telegram or to the github (or both). To contact me via telegram, you should use import_card method with argument 000653bf:0738ca5d:5521fbac:29246815:a27d0cda
163
164
165### Usage
166
167    bin/telegram-cli -k <public-server-key>
168
169By default, the public key is stored in tg-server.pub in the same folder or in /etc/telegram-cli/server.pub. If not, specify where to find it:
170
171    bin/telegram-cli -k tg-server.pub
172
173Client support TAB completion and command history.
174
175Peer refers to the name of the contact or dialog and can be accessed by TAB completion.
176For user contacts peer name is Name <underscore> Lastname with all spaces changed to underscores.
177For chats it is it's title with all spaces changed to underscores
178For encrypted chats it is <Exсlamation mark> <underscore> Name <underscore> Lastname with all spaces changed to underscores.
179
180If two or more peers have same name, <sharp>number is appended to the name. (for example A_B, A_B#1, A_B#2 and so on)
181
182### Supported commands
183
184#### Messaging
185
186* **msg** \<peer\> Text - sends message to this peer
187* **fwd** \<user\> \<msg-seqno\> - forward message to user. You can see message numbers starting client with -N
188* **chat_with_peer** \<peer\> starts one on one chat session with this peer. /exit or /quit to end this mode.
189* **add_contact** \<phone-number\> \<first-name\> \<last-name\> - tries to add contact to contact-list by phone
190* **rename_contact** \<user\> \<first-name\> \<last-name\> - tries to rename contact. If you have another device it will be a fight
191* **mark_read** \<peer\> - mark read all received messages with peer
192* **delete_msg** \<msg-seqno\> - deletes message (not completly, though)
193* **restore_msg** \<msg-seqno\> - restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion
194
195#### Multimedia
196
197* **send_photo** \<peer\> \<photo-file-name\> - sends photo to peer
198* **send_video** \<peer\> \<video-file-name\> - sends video to peer
199* **send_text** \<peer\> \<text-file-name> - sends text file as plain messages
200* **send_document** \<peer\> \<document-file-name\> - sends document to peer
201* **load_photo**/load_video/load_video_thumb/load_audio/load_document/load_document_thumb \<msg-seqno\> - loads photo/video/audio/document to download dir
202* **view_photo**/view_video/view_video_thumb/view_audio/view_document/view_document_thumb \<msg-seqno\> - loads photo/video to download dir and starts system default viewer
203* **fwd_media** \<msg-seqno\> send media in your message. Use this to prevent sharing info about author of media (though, it is possible to determine user_id from media itself, it is not possible get access_hash of this user)
204* **set_profile_photo** \<photo-file-name\> - sets userpic. Photo should be square, or server will cut biggest central square part
205
206
207#### Group chat options
208
209* **chat_info** \<chat\> - prints info about chat
210* **chat_add_user** \<chat\> \<user\> - add user to chat
211* **chat_del_user** \<chat\> \<user\> - remove user from chat
212* **rename_chat** \<chat\> \<new-name\>
213* **create_group_chat** \<chat topic\> \<user1\> \<user2\> \<user3\> ... - creates a groupchat with users, use chat_add_user to add more users
214* **chat_set_photo** \<chat\> \<photo-file-name\> - sets group chat photo. Same limits as for profile photos.
215
216### Channels
217
218* **channel_get_admins** \<channel\> [limit=100] [offset=0]	- Gets channel admins
219* **channel_get_members** \<channel\> [limit=100] [offset=0]	- Gets channel members
220* **channel_info** \<channel\>	- Prints info about channel (id, members, admin, etc.)
221* **channel_invite** \<channel\> \<user\>	- Invites user to channel
222* **channel_join** \<channel\>	- Joins to channel
223* **channel_kick** \<channel\> \<user\>	- Kicks user from channel
224* **channel_leave** \<channel\>	- Leaves from channel
225* **channel_list** [limit=100] [offset=0]	- List of last channels
226* **channel_set_about** \<channel\> \<about\>	- Sets channel about info.
227* **channel_set_admin** \<channel\> \<admin\> \<type\>	- Sets channel admin. 0 - not admin, 1 - moderator, 2 - editor
228* **channel_set_photo** \<channel\> \<filename\>	- Sets channel photo. Photo will be cropped to square
229* **channel_set_username** \<channel\> \<username\>	 -Sets channel username info.
230
231#### Search
232
233* **search** \<peer\> pattern - searches pattern in messages with peer
234* **global_search** pattern - searches pattern in all messages
235
236#### Secret chat
237
238* **create_secret_chat** \<user\> - creates secret chat with this user
239* **visualize_key** \<secret_chat\> - prints visualization of encryption key. You should compare it to your partner's one
240* **set_ttl** \<secret_chat\> \<ttl\> - sets ttl to secret chat. Though client does ignore it, client on other end can make use of it
241* **accept_secret_chat** \<secret_chat\> - manually accept secret chat (only useful when starting with -E key)
242
243#### Stats and various info
244
245* **user_info** \<user\> - prints info about user
246* **history** \<peer\> [limit] - prints history (and marks it as read). Default limit = 40
247* **dialog_list** - prints info about your dialogs
248* **contact_list** - prints info about users in your contact list
249* **suggested_contacts** - print info about contacts, you have max common friends
250* **stats** - just for debugging
251* **show_license** - prints contents of GPLv2
252* **help** - prints this help
253* **get_self** - get our user info
254
255#### Card
256* **export_card** - print your 'card' that anyone can later use to import your contact
257* **import_card** \<card\> - gets user by card. You can write messages to him after that.
258
259#### Other
260* **quit** - quit
261* **safe_quit** - wait for all queries to end then quit
262* run `telegram-cli -q` to logout from account
263
264#### Troubleshooting
265* if you got error: `get error FAIL: 38: can not parse arg #1` it maybe be unresolved username. You should use `resolve_username channel/group/user_name` before running action with it. [See this issue for more info](https://github.com/vysheng/tg/issues/823)
266