zmnkh icon

connect telegram on ubuntu 16.04

zmnkh | PRO | 11/02/17 06:12:45 AM UTC | 0 ⭐ | 845 👁️ | Never ⏰ | []
text |

7.85 KB

|

None

|

0 👍

/

0 👎

 hoon@kcxweb:~/tg$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
   텔레그램으로 연동하기 (for linux, ubuntu 16.04)
 #telegram install
 hoon@kcxweb:~/tg$ git clone --recursive https://github.com/vysheng/tg.git
hoon@kcxweb:cd tg
 hoon@kcxweb:sudo apt-get install libreadline-dev libconfig-dev libssl-dev lua5.2 liblua5.2-dev libevent-dev libjansson-dev libpython-dev make
  hoon@kcxweb:./configure
hoon@kcxweb:make
  #telegram 연결 (특정 전화번호의 텔레그램 프로그램 연결 인증)
hoon@kcxweb:./bin/telegram-cli -k tg-server.pub
 phone number: 8210xxxxxxxxxx //전화번호 입력
code ('CALL' for phone code): 24329 // 인증번호 입력
 아래와 같이 telegram의 CLI 모드 진입됨
>> msg 하x hello
 [14:25]  하x <<< hello
User 하x online (was online [2017/11/02 14:30:52])
User 하x marked read 1 outbox and 0 inbox messages //언제 읽었는지 확인 가능
 // 상대방은 010xxxxxxxxx 사용자가 보낸것으로 보임 
  #상대방 아이디에 공백이 있는 경우에는 _(underscore) 를 넣어주면 된다.
 #수신인을 그룹으로 지정하면, 1번의 메세지를 보낸것으로 다수의 사용자에게 보낼 수 있다.
  #종료
> quit
  한번 인증 한 후에는 아래와 같이 스크립트로도 보낼 수 있다.
============
#!/bin/bash
 export user=$1;
export subject=$2;
export body=$3;
 ./bin/telegram-cli -W -e "msg $user $subject" > /dev/null
exit
=============
 ex)
 # sh send_telegram.sh 하x "이건보이시나요?"
 ==================
 #python으로 DB 정보 조회해서 전달하기
------------------------------
 # apt-get install python-dev libmysqlclient-dev python-pip
# pip install mysql-python
------------------------------
 #!/usr/bin/python
# -*- coding: utf-8 -*- //한글 사용시 오류나는 것을 방지
 import MySQLdb
import subprocess
 def get_server_verion():
    db = MySQLdb.connect("localhost","user","password")
    cursor = db.cursor()
    cursor.execute("SELECT VERSION()")
    data = cursor.fetchone()
    version = "Database version : %s " % data
    print version
    db.close()
     subprocess.call(["./send_telegram.sh", "하x", version, ""])
 get_server_verion()
  =======================================================
 #crontab에 등록하여 계속 보내기
 20 */3 * * * /usr/bin/python /root/send_server_version.py
 =============
 #telegram 명령어
https://github.com/vysheng/tg/wiki/Telegram-CLI-Commands
  accept_secret_chat <secret chat> Accepts secret chat. Only useful with -E option
 add_contact <phone> <first name> <last name> Tries to add user to contact list
 broadcast <user>+ <text> Sends text to several users at once
 chat_add_user <chat> <user> [msgs-to-forward] Adds user to chat. Sends him last msgs-to-forward message from this chat. Default 100
 chat_del_user <chat> <user> Deletes user from chat
 chat_info <chat> Prints info about chat (id, members, admin, etc.)
 chat_set_photo <chat> <filename> Sets chat photo. Photo will be cropped to square
 chat_with_peer <peer> Interface option. All input will be treated as messages to this peer. Type /quit to end this mode
 clear Clears all data and exits. For debug.
 contact_list Prints contact list
 contact_search username [limit] Searches contacts by username
 create_group_chat <name> <user>+ Creates group chat with users
 create_secret_chat <user> Starts creation of secret chat
 del_contact <user> Deletes contact from contact list
 delete_msg <msg-id> Deletes message
 dialog_list List of last conversations
 export_card Prints card that can be imported by another user with import_card method
 fwd <peer> <msg-id> Forwards message to peer. Forward to secret chats is forbidden
 fwd_media <peer> <msg-id> Forwards message media to peer. Forward to secret chats is forbidden. Result slightly differs from fwd
help Prints this help
 history <peer> [limit] [offset] Prints messages with this peer (most recent message lower). Also marks messages as read
 import_card <card> Gets user by card and prints it name. You can then send messages to him as usual
 load_audio <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_document <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_document_thumb <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_file <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_file_thumb <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_photo <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_video <msg-id> Downloads file to downloads dirs. Prints file name after download end
 load_video_thumb <msg-id> Downloads file to downloads dirs. Prints file name after download end
 main_session Sends updates to this connection (or terminal). Useful only with listening socket
 mark_read <peer> Marks messages with peer as read
 msg <peer> <text> Sends text message to peer
 quit Quits immediately
 rename_chat <chat> <new name> Renames chat
 rename_contact <user> <first name> <last name> Renames contact
 restore_msg <msg-id> Restores message. Only available shortly (one hour?) after deletion
 safe_quit Waits for all queries to end, then quits
 search [peer] [limit] [from] [to] [offset] pattern Search for pattern in messages from date from to date to (unixtime) in 
messages with peer (if peer not present, in all messages) generate new key for active secret chat
 send_audio <peer> <file> Sends audio to peer
 send_contact <peer> <phone> <first-name> <last-name> Sends contact (not necessary telegram user)
 send_document <peer> <file> Sends document to peer
 send_file <peer> <file> Sends document to peer
 send_location <peer> <latitude> <longitude> Sends geo location
 send_photo <peer> <file> [caption] Sends photo to peer
 send_text <peer> <file> Sends contents of text file as plain text message
 send_typing <peer> Sends typing notification
 send_typing <peer> Sends typing notification abort
 send_video <peer> <file> [caption] Sends video to peer
 set <param> <value> Sets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num
 set_password <hint> Sets password
 set_profile_name <first-name> <last-name> Sets profile name.
 set_profile_photo <filename> Sets profile photo. Photo will be cropped to square
 set_ttl <secret chat> Sets secret chat ttl. Client itself ignores ttl
 set_username <name> Sets username.
 show_license Prints contents of GPL license
 stats For debug purpose
 status_online Sets status as online
 status_offline Sets status as offline
 user_info <user> Prints info about user (id, last online, phone)
 view_audio <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_document <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_document_thumb <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_file <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_file_thumb <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_photo <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_video <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 view_video_thumb <msg-id> Downloads file to downloads dirs. Then tries to open it with system default action
 visualize_key <secret chat> Prints visualization of encryption key (first 16 bytes sha1 of it in fact)
 =====================================

Comments