Advertisement
zmnkh

connect telegram on ubuntu 16.04

Nov 2nd, 2017
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.85 KB | None | 0 0
  1.  
  2. hoon@kcxweb:~/tg$ lsb_release -a
  3. No LSB modules are available.
  4. Distributor ID: Ubuntu
  5. Description: Ubuntu 16.04.3 LTS
  6. Release: 16.04
  7. Codename: xenial
  8.  
  9.  
  10.  
  11. 텔레그램으로 연동하기 (for linux, ubuntu 16.04)
  12.  
  13. #telegram install
  14.  
  15. hoon@kcxweb:~/tg$ git clone --recursive https://github.com/vysheng/tg.git
  16. hoon@kcxweb:cd tg
  17.  
  18. hoon@kcxweb:sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make
  19.  
  20.  
  21. hoon@kcxweb:./configure
  22. hoon@kcxweb:make
  23.  
  24.  
  25. #telegram 연결 (특정 전화번호의 텔레그램 프로그램 연결 인증)
  26. hoon@kcxweb:./bin/telegram-cli -k tg-server.pub
  27.  
  28. phone number: 8210xxxxxxxxxx //전화번호 입력
  29. code ('CALL' for phone code): 24329 // 인증번호 입력
  30.  
  31. 아래와 같이 telegram의 CLI 모드 진입됨
  32. >> msg 하x hello
  33. [14:25] 하x <<< hello
  34. User 하x online (was online [2017/11/02 14:30:52])
  35. User 하x marked read 1 outbox and 0 inbox messages //언제 읽었는지 확인 가능
  36.  
  37. // 상대방은 010xxxxxxxxx 사용자가 보낸것으로 보임
  38.  
  39.  
  40. #상대방 아이디에 공백이 있는 경우에는 _(underscore) 를 넣어주면 된다.
  41.  
  42. #수신인을 그룹으로 지정하면, 1번의 메세지를 보낸것으로 다수의 사용자에게 보낼 수 있다.
  43.  
  44.  
  45. #종료
  46. > quit
  47.  
  48.  
  49. 한번 인증 한 후에는 아래와 같이 스크립트로도 보낼 수 있다.
  50. ============
  51. #!/bin/bash
  52.  
  53. export user=$1;
  54. export subject=$2;
  55. export body=$3;
  56.  
  57. ./bin/telegram-cli -W -e "msg $user $subject" > /dev/null
  58. exit
  59. =============
  60.  
  61. ex)
  62.  
  63. # sh send_telegram.sh 하x "이건보이시나요?"
  64.  
  65. ==================
  66.  
  67. #python으로 DB 정보 조회해서 전달하기
  68. ------------------------------
  69.  
  70. # apt-get install python-dev libmysqlclient-dev python-pip
  71. # pip install mysql-python
  72. ------------------------------
  73.  
  74. #!/usr/bin/python
  75. # -*- coding: utf-8 -*- //한글 사용시 오류나는 것을 방지
  76.  
  77. import MySQLdb
  78. import subprocess
  79.  
  80. def get_server_verion():
  81. db = MySQLdb.connect("localhost","user","password")
  82. cursor = db.cursor()
  83. cursor.execute("SELECT VERSION()")
  84. data = cursor.fetchone()
  85. version = "Database version : %s " % data
  86. print version
  87. db.close()
  88.  
  89. subprocess.call(["./send_telegram.sh", "하x", version, ""])
  90.  
  91. get_server_verion()
  92.  
  93.  
  94. =======================================================
  95.  
  96. #crontab에 등록하여 계속 보내기
  97.  
  98. 20 */3 * * * /usr/bin/python /root/send_server_version.py
  99.  
  100. =============
  101.  
  102. #telegram 명령어
  103. https://github.com/vysheng/tg/wiki/Telegram-CLI-Commands
  104.  
  105.  
  106. accept_secret_chat <secret chat> Accepts secret chat. Only useful with -E option
  107.  
  108. add_contact <phone> <first name> <last name> Tries to add user to contact list
  109.  
  110. broadcast <user>+ <text> Sends text to several users at once
  111.  
  112. chat_add_user <chat> <user> [msgs-to-forward] Adds user to chat. Sends him last msgs-to-forward message from this chat. Default 100
  113.  
  114. chat_del_user <chat> <user> Deletes user from chat
  115.  
  116. chat_info <chat> Prints info about chat (id, members, admin, etc.)
  117.  
  118. chat_set_photo <chat> <filename> Sets chat photo. Photo will be cropped to square
  119.  
  120. chat_with_peer <peer> Interface option. All input will be treated as messages to this peer. Type /quit to end this mode
  121.  
  122. clear Clears all data and exits. For debug.
  123.  
  124. contact_list Prints contact list
  125.  
  126. contact_search username [limit] Searches contacts by username
  127.  
  128. create_group_chat <name> <user>+ Creates group chat with users
  129.  
  130. create_secret_chat <user> Starts creation of secret chat
  131.  
  132. del_contact <user> Deletes contact from contact list
  133.  
  134. delete_msg <msg-id> Deletes message
  135.  
  136. dialog_list List of last conversations
  137.  
  138. export_card Prints card that can be imported by another user with import_card method
  139.  
  140. fwd <peer> <msg-id> Forwards message to peer. Forward to secret chats is forbidden
  141.  
  142. fwd_media <peer> <msg-id> Forwards message media to peer. Forward to secret chats is forbidden. Result slightly differs from fwd
  143. help Prints this help
  144.  
  145. history <peer> [limit] [offset] Prints messages with this peer (most recent message lower). Also marks messages as read
  146.  
  147. import_card <card> Gets user by card and prints it name. You can then send messages to him as usual
  148.  
  149. load_audio <msg-id> Downloads file to downloads dirs. Prints file name after download end
  150.  
  151. load_document <msg-id> Downloads file to downloads dirs. Prints file name after download end
  152.  
  153. load_document_thumb <msg-id> Downloads file to downloads dirs. Prints file name after download end
  154.  
  155. load_file <msg-id> Downloads file to downloads dirs. Prints file name after download end
  156.  
  157. load_file_thumb <msg-id> Downloads file to downloads dirs. Prints file name after download end
  158.  
  159. load_photo <msg-id> Downloads file to downloads dirs. Prints file name after download end
  160.  
  161. load_video <msg-id> Downloads file to downloads dirs. Prints file name after download end
  162.  
  163. load_video_thumb <msg-id> Downloads file to downloads dirs. Prints file name after download end
  164.  
  165. main_session Sends updates to this connection (or terminal). Useful only with listening socket
  166.  
  167. mark_read <peer> Marks messages with peer as read
  168.  
  169. msg <peer> <text> Sends text message to peer
  170.  
  171. quit Quits immediately
  172.  
  173. rename_chat <chat> <new name> Renames chat
  174.  
  175. rename_contact <user> <first name> <last name> Renames contact
  176.  
  177. restore_msg <msg-id> Restores message. Only available shortly (one hour?) after deletion
  178.  
  179. safe_quit Waits for all queries to end, then quits
  180.  
  181. search [peer] [limit] [from] [to] [offset] pattern Search for pattern in messages from date from to date to (unixtime) in
  182. messages with peer (if peer not present, in all messages) generate new key for active secret chat
  183.  
  184. send_audio <peer> <file> Sends audio to peer
  185.  
  186. send_contact <peer> <phone> <first-name> <last-name> Sends contact (not necessary telegram user)
  187.  
  188. send_document <peer> <file> Sends document to peer
  189.  
  190. send_file <peer> <file> Sends document to peer
  191.  
  192. send_location <peer> <latitude> <longitude> Sends geo location
  193.  
  194. send_photo <peer> <file> [caption] Sends photo to peer
  195.  
  196. send_text <peer> <file> Sends contents of text file as plain text message
  197.  
  198. send_typing <peer> Sends typing notification
  199.  
  200. send_typing <peer> Sends typing notification abort
  201.  
  202. send_video <peer> <file> [caption] Sends video to peer
  203.  
  204. set <param> <value> Sets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num
  205.  
  206. set_password <hint> Sets password
  207.  
  208. set_profile_name <first-name> <last-name> Sets profile name.
  209.  
  210. set_profile_photo <filename> Sets profile photo. Photo will be cropped to square
  211.  
  212. set_ttl <secret chat> Sets secret chat ttl. Client itself ignores ttl
  213.  
  214. set_username <name> Sets username.
  215.  
  216. show_license Prints contents of GPL license
  217.  
  218. stats For debug purpose
  219.  
  220. status_online Sets status as online
  221.  
  222. status_offline Sets status as offline
  223.  
  224. user_info <user> Prints info about user (id, last online, phone)
  225.  
  226. view_audio <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  227.  
  228. view_document <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  229.  
  230. view_document_thumb <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  231.  
  232. view_file <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  233.  
  234. view_file_thumb <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  235.  
  236. view_photo <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  237.  
  238. view_video <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  239.  
  240. view_video_thumb <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
  241.  
  242. visualize_key <secret chat> Prints visualization of encryption key (first 16 bytes sha1 of it in fact)
  243.  
  244. =====================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement