Telegram BOT 강좌 2부
Telegram CLI 의 기초적인 사용방법과 BOT 의 기초 작업에 대한 강좌.
1. Telegram CLI 기초 사용방법.
Telegram CLI 를 설치를 하였다면 이제 활용을 해야 한다.
그 전에 Telegram CLI 의 기초적인 사용방법을 알아 보자.
cd /home/pi/tg
명령을 이용해서 Telegram이 있는 디렉토리로 이동한다.
bin/telegram-cli -k server.pub
위 명령을 이용하면 Telegram CLI 가 실행이 되고 다음과 같은 화면을 볼 수 있다.
[pi@/home/pi/tg]$ bin/telegram-cli -k server.pub Telegram-cli version 1.3.3, Copyright (C) 2013-2015 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. Telegram-cli uses libtgl version 2.0.3 Telegram-cli includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit. (http://www.openssl.org/) Telegram-cli uses libpython version 2.7.3 I: config dir=[/home/pi/.telegram-cli] > |
이 상태에서 다음 명령어를 입력하자.
help
help 명령을 치고 엔터를 누르면 다음과 같은 도움말을 볼 수 있다.
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 block_user <user> Blocks user 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 Searches user 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 [limit=100] [offset=0] List of last conversations export_card Prints card that can be imported by another user with import_card method export_chat_link Prints chat link that can be used to join to chat 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 get_message <msg-id> Get message by id get_self Get our user info 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 import_chat_link <hash> Joins to chat by link load_audio <msg-id> Downloads file to downloads dirs. Prints file name after download end load_chat_photo <chat> 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_user_photo <user> 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 msg <peer> <kbd> <text> Sends text message to peer with custom kbd quit Quits immediately rename_chat <chat> <new name> Renames chat rename_contact <user> <first name> <last name> Renames contact reply <msg-id> <text> Sends text reply to message reply_audio <msg-id> <file> Sends audio to peer reply_contact <msg-id> <phone> <first-name> <last-name> Sends contact (not necessary telegram user) reply_document <msg-id> <file> Sends document to peer reply_file <msg-id> <file> Sends document to peer reply_location <msg-id> <latitude> <longitude> Sends geo location reply_photo <msg-id> <file> [caption] Sends photo to peer reply_video <msg-id> <file> Sends video to peer resolve_username username Searches user by username 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) 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> [status] Sends typing notification. You can supply a custom status (range 0-10): none, typing, cancel, record video, upload video, record audio, upload audio, upload photo, upload document, geo, choose contact. send_typing_abort <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 start_bot <bot> <chat> <data> Adds bot to chat stats For debug purpose status_online Sets status as online status_offline Sets status as offline unblock_user <user> Unblocks user 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_chat_photo <chat> 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_user_photo <user> 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 view <msg-id> Tries to view message contents visualize_key <secret chat> Prints visualization of encryption key (first 16 bytes sha1 of it in fact} |
이 수많은 명령어들 중에 자주사용하는 명령어는 다음과 같다.
contact_list
|
내 텔레그램 계정에 등록된 주소록을 보여주는 기능
|
msg |
msg <peer> <text> Sends text message to peer
다른 사용자에게 메시지를 보내는 기능
peer 와 text 를 인자로 받게 되어 있다.
사용 방법은 다음과 같다.
msg first_name_second_name "전달한 메시지"
contact_list 에서 다음과 같은 이름 목록이 나왔을 경우의 예제이다. (띄어쓰기 주의)
contact_list
홍 길동
john doe
김영희
위와 같은 목록의 주소록을 가지고 있는 경우 <peer> 항목에 이름을 써주어야 하는데
First Name 과 Second Name 사이에 밑줄(UnderBar) 를 이용해서 이어주면 된다.
First Name 만 있는 경우에는 First Name 만 써주면 된다.
ex)
msg 홍_길동 처음으로 보내보는 메시지 예제
msg john_doe Hello, World
msg 김영희 샘플 메시지입니다.
|
send_text |
send_text <peer> <file> Sends contents of text file as plain text message
Text 파일을 보내기 위한 기능
msg 기능으로도 텍스트를 보낼수 있지만 msg 기능은 줄바꿈이 들어간 메시지를 보낼 수가 없다.
여러줄로 구성된 메시지를 보내기 위해서는 보내려는 메시지를 Text 파일에 작성 후 send_text 를 이용해 보낸다.
send_text 홍_길동 /home/pi/tgmsg.txt
|
quit |
Telegram CLI를 종료한다.
|
safe_quit |
Telegram CLI를 안전하게 종료한다. 이미 수행된 명령을 기다렸다가 종료하는 명령이다.
|
주로 써야 되는 기능에 대한 기초적인 사용방법이며 다른 Command 들도 command <peer> <option> 형태의 구조로 되어 있기 떄문에
무리 없이 사용할 수 있을것이다.
※ contact_list 를 했는데 아무도 없다면 Telegram Web 버전이나 PC버전, 모바일앱을 이용해서 자신이 쓸 계정을 친구 추가해두면
편리하게 이용할 수 있다.
CLI 에서 add_contact +8212340000 홍 길동
이런식으로 친구를 추가 할 수도 있다.
글이 길어져서 3부에 Telegram CLI BOT의 기초작업을 다루어보자.