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 Accepts secret chat. Only useful with -E option add_contact Tries to add user to contact list broadcast + Sends text to several users at once chat_add_user [msgs-to-forward] Adds user to chat. Sends him last msgs-to-forward message from this chat. Default 100 chat_del_user Deletes user from chat chat_info Prints info about chat (id, members, admin, etc.) chat_set_photo Sets chat photo. Photo will be cropped to square chat_with_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 + Creates group chat with users create_secret_chat Starts creation of secret chat del_contact Deletes contact from contact list delete_msg Deletes message dialog_list List of last conversations export_card Prints card that can be imported by another user with import_card method fwd Forwards message to peer. Forward to secret chats is forbidden fwd_media Forwards message media to peer. Forward to secret chats is forbidden. Result slightly differs from fwd help Prints this help history [limit] [offset] Prints messages with this peer (most recent message lower). Also marks messages as read import_card Gets user by card and prints it name. You can then send messages to him as usual load_audio Downloads file to downloads dirs. Prints file name after download end load_document Downloads file to downloads dirs. Prints file name after download end load_document_thumb Downloads file to downloads dirs. Prints file name after download end load_file Downloads file to downloads dirs. Prints file name after download end load_file_thumb Downloads file to downloads dirs. Prints file name after download end load_photo Downloads file to downloads dirs. Prints file name after download end load_video Downloads file to downloads dirs. Prints file name after download end load_video_thumb 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 Marks messages with peer as read msg Sends text message to peer quit Quits immediately rename_chat Renames chat rename_contact Renames contact restore_msg 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 Sends audio to peer send_contact Sends contact (not necessary telegram user) send_document Sends document to peer send_file Sends document to peer send_location Sends geo location send_photo [caption] Sends photo to peer send_text Sends contents of text file as plain text message send_typing Sends typing notification send_typing Sends typing notification abort send_video [caption] Sends video to peer set Sets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num set_password Sets password set_profile_name Sets profile name. set_profile_photo Sets profile photo. Photo will be cropped to square set_ttl Sets secret chat ttl. Client itself ignores ttl set_username 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 Prints info about user (id, last online, phone) view_audio Downloads file to downloads dirs. Then tries to open it with system default action view_document Downloads file to downloads dirs. Then tries to open it with system default action view_document_thumb Downloads file to downloads dirs. Then tries to open it with system default action view_file Downloads file to downloads dirs. Then tries to open it with system default action view_file_thumb Downloads file to downloads dirs. Then tries to open it with system default action view_photo Downloads file to downloads dirs. Then tries to open it with system default action view_video Downloads file to downloads dirs. Then tries to open it with system default action view_video_thumb Downloads file to downloads dirs. Then tries to open it with system default action visualize_key Prints visualization of encryption key (first 16 bytes sha1 of it in fact) =====================================