메뉴 닫기

텔레그램 CLI (Telegram-CLI) 서버에 설치해보기

idchowto_cover7

 

텔레그램과 서버간에 통신을 위한 Telegram-cli 를 설치해보록 하겠습니다. (CentOS 5 기준)

조건은 스마트폰에 텔레그램 앱이 먼저 설치되어 있어야 합니다.

1. 텔레그램(Telegram) CLI 버전 설치

telegram-cli 설치를 위해 필요한 패키지 및 프로그램을 설치합니다.

1.1 필요 패키지 설치

# yum install libevent-devel openssl-devel readline-devel libconfig-devel lua lua-devel

1.2 libconfig 설치

libconfig 를 사용하려면 CentOS 5 에서는 해당 라이브러리를 제공하지 않으므로, 별도로 설치해줘야 합니다.

– x86_64

# wget http://damsl.cs.indiana.edu/yum/centos/5/x86_64/libconfig-1.4.8-1.x86_64.rpm
# wget http://damsl.cs.indiana.edu/yum/centos/5/x86_64/libconfig-devel-1.4.8-1.x86_64.rpm
# rpm -ivh libconfig-1.4.8-1.x86_64.rpm
# rpm -ivh libconfig-devel-1.4.8-1.x86_64.rpm

– i386

http://hyperrealm.com/libconfig/ 에서 소스를 받아 컴파일 합니다.
설치된 libconfig 라이브러리 경로가 /lib/ 또는 /usr/lib/ 등과 같지 않다면 텔레그램 cli 컴파일시에
LDFLAGS 변수에 -L 옵션으로 경로를 지정해줍니다.

1.3 telegram-cli 소스 다운로드 및 설치

다운로드 사이트 : https://github.com/vysheng/tg
– 오른쪽 중간쯤에 Download ZIP [이미지 배너] 를 클릭하면 소스 파일입니다.

# unzip tg-master.zip
# cd tg-master
# ./configure –disable-libconfig


checking for rl_save_prompt in -lreadline… no
configure: error: no libreadline found

readline-devl 패키지가 설치되어 있음에도
위와 같이 오류가 나는 경우 LDFLAGS 변수를 지정 컴파일 해줍니다.

그 전에 /usr/lib/libncursesw.so 심볼릭 링크가 되어 있는지 확인합니다.
없다면 심볼릭 링크를 걸어줍니다.

# cd /usr/lib
# ln -s libncursesw.so.5 libncursesw.so

LDFLAGS 변수를 지정 컴파일

# cd –
# LDFLAGS=”-lncursesw” ./configure


checking for libconfig… enabled
checking for config_init in -lconfig… no
configure: error: No libconfig found. Try –disable-libconfig

위와 같이 오류나거나 (libconfig 가 설치가 안된 경우) libconfig 를 사용하지 않는 다면
다음 옵션으로 설치합니다.

# LDFLAGS=”-lncursesw” ./configure –disable-libconfig
# make

1.4 configure 진행시 오류 모음

1) libevent-devel 패키지가 없습니다.

# ./configure

checking for event_base_new in -levent… no
configure: error: no libevent found

=> yum install libevent-devel

2) libreadline-devel 패키지가 없습니다.

# ./configure

checking for rl_save_prompt in -lreadline… no
configure: error: no libreadline found

=> yum install readline-devel
https://github.com/vysheng/tg

3) lua, lua-devel 패키지가 없습니다.

# ./configure

checking for lua… no
checking for lua5.2… no
checking for lua52… no
checking for lua5.1… no
checking for lua51… no
checking for lua50… no
checking if : is a Lua interpreter… yes
configure: error: No lua found. Try –disable-liblua

lua 설치

– x86_64

=> wget http://dl.fedoraproject.org/pub/epel/5/x86_64/lua-5.1.4-4.el5.x86_64.rpm
rpm -ivh lua-5.1.4-4.el5.x86_64.rpm

-i386

=> wget http://dl.fedoraproject.org/pub/epel/5/i386/lua-5.1.4-4.el5.i386.rpm
rpm -ivh lua-5.1.4-4.el5.i386.rpm

lua-devl 설치

– x86_64

=> wget http://dl.fedoraproject.org/pub/epel/5/x86_64/lua-devel-5.1.4-4.el5.x86_64.rpm
rpm -ivh lua-devel-5.1.4-4.el5.x86_64.rpm

– i386

=> wget http://dl.fedoraproject.org/pub/epel/5/i386/lua-devel-5.1.4-4.el5.i386.rpm
rpm -ivh lua-devel-5.1.4-4.el5.i386.rpm

2. 텔레그램(Telegram) CLI 실행

# bin/telegram-cli -k server.pub
change_user_group: can’t find the user telegramd to switch to
Telegram-cli version 1.0.6, Copyright (C) 2013-2014 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license’.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show_license’ for details.
I: config dir=[/root/.telegram-cli]
[/root/.telegram-cli] created
[/root/.telegram-cli/downloads] created
Telephone number (with ‘+’ sign): +8201 …. <- 스마트폰 번호 입력해줍니다.
Code from sms (if you did not receive an SMS and want to be called, type “call”): 12345
<– 스마트폰에 설치된 텔레그램 앱 또는 SMS 으로 수신된 인증번호 5자리를 입력합니다.
User 닉네임 updated photo
> <– telegram-cli 접속이 완료된 상태입니다.
> stats
users_allocated 1
chats_allocated 0
secret_chats_allocated 0
peer_num 1
messages_allocated 0

 2.1 주요 명령어

msg <받을사람> <메세지> : 텍스트 문구를 상대방에게 전송합니다.

ex) > msg Sunkyu hello~!
[15:53] Sunkyu <<< hello~!

send_photo <받을사람> <파일명> : 사진 파일을 상대방에게 전송합니다.
send_text <받을사람> <파일명> : 로컬에 있는 텍스트 파일 내용을 상대방에게 전송합니다. (SMS 문자와 같이 화면에 뿌려줌)
contact_list : 대화상대 목록
dialog_list : 열려 있는 대화창 목록
status_online : on 상태로 전환
status_offline : off 상태로 전환

==> 자세한 명령어는 help 명령을 통해 확인할 수 있습니다.

* 텔레그램 앱에서 설정(Settings) > 다른 모든 세션 종료 (Terminate All Other Sessions)를 클릭하면,
CLI 연결은 끊어지고, 새로 인증을 받아야 합니다.

또는, 인증정보가 저장된 ~/.telegram-cli/ 디렉토리를 지우고도 재인증을 받을 수 있습니다.

* telegram-cli 실행시 lua 스크립트를 사용하여 다음과 같은 작업을 할 수 있습니다.

– 상황에 따른 메시지를 지정한 유저, 그룹에게 보낼 수 있습니다.
– telegram-cli 가 메시지를 수신시, 메시지에 따라 결과를 상대방에게 return 해줄 수 있습니다.

* 참고자료

https://github.com/vysheng/tg
https://github.com/vysheng/tg/issues/144
https://github.com/vysheng/tg/blob/master/README-LUA
http://coffeenix.net/board_view.php?bd_code=1759

 

다음 시간에는 lua 스크립트, bash 스크립트 등을 통해
클라이언트와 서버간 통신하는 방법에 대해 살펴보도록 하겠습니다.

 

 telgram-cli_test2 Screenshot_2014-10-21-09-18-26

 

 

 [polldaddy rating=”7739789″]

 

Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Jaehyun Lee
Jaehyun Lee
9 years ago

스마일서브 이용중이라 설치해서 써보려고 시도중인데 컴파일시 오류가 나서 진행이 안되네요… 도움이 필요합니다 ㅠ

이선규
이선규
9 years ago
Reply to  Jaehyun Lee

컴파일시 오류 메세지 구문과 함께 neosky.com 으로 메일주세요.
감사합니다.

2
0
Would love your thoughts, please comment.x
()
x