여리군의 홈페이지~♡

 

 

며칠전 웹서핑을 하다가 재미있는 글을 봐서 직접 시도해보고, 그 결과를 정리해보았습니다.

I just found an interesting article on the internet, and I tried. 

 

그 내용은, MyBookLive에 세팅된 트랜스미션Transmission에서 토렌트가 다운로드 완료되면 완료메시지를 텔레그램으로 받는 방법입니다.

It is about receiving alarm via telegram when trasmission completes downloading a torrent on your MyBookLive.

 

 

할 일은 크게 2가지 입니다.

1. 텔레그램 봇 설정

2. MyBookLive에서 알람 설정

It is seperated on 2 parts.

1. set up telegram bot

2. set up alarm on MyBookLive

 

 

 

먼저, 텔레그램 봇 설정 방법입니다.

This is how-to set up telegram bot.

 

1. https://telegram.me/botfather 주소를 눌러서 봇파더 BotFather 에게 말을 겁니다.

   PC에서 잘 안되면 텔레그램이 설치된 핸드폰에서 위 주소를 누르면 botfather와의 대화창이 열립니다.

2. /newbot   이라고 입력합니다.

3. 봇의 이름을 적당히 입력합니다. 한글도 가능하고 나중에 바꿀수도 있습니다.

4. 봇의 username을 영어로 입력합니다. 마지막은 반드시 bot으로 끝나야 합니다.

1. press https://telegram.me/botfather . Use cellphone if your computer doesn't work.

2. type /newbot

3. Name your bot

4. choose a username for your bot

위 2~4번의 내용을 대화형태로 표현하면 이렇습니다. "나" 부분의 빨간 글씨가  사용자가 입력해야 하는 부분입니다.

Here's the chat between me and @BotFather. You need to type red characters next to "나". 

 

나: /newbot

BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.

 

나: 토렌트알리미 TorrentAlarm

BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.

 

나: torrent_transmission_alarm_bot

BotFather: Done! Congratulations on your new bot. You will find it at telegram.me/torrent_transmission_alarm_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.

Use this token to access the HTTP API:

123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

 

 

 파란색으로 칠해진 token 부분을 써먹게 되니 잘 알아두시기 바랍니다. (임의의 문자열로 대체했습니다.)

 Keep the token(in blue color) somewhere like notepad.

 

5. telegram.me/torrent_transmission_alarm_bot 부분을 클릭하면 자신이 만든 봇과의 대화창이 열립니다. (username에 따라 주소가 다릅니다)

6. 적당히 대화를 한두개 보냅니다. 반응이 없는 것이 정상입니다.

7. 이제, 아래 주소를 자신의 token으로 바꾸어서 인터넷 브라우저 주소창에 입력합니다.

   https://api.telegram.org/bot123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE/getUpdates

8. 그러면 getUpdates.json 파일을 하나 다운받게 되는데, 이 getUpdates.json 파일을 메모장으로 열어봅니다.

5. click telegram.me/torrent_transmission_alarm_bot (depends on your bot username)

6. send your bot some message like "hello"

7. type following text on your browser after replacing blue text with your token from 4

    https://api.telegram.org/bot123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE/getUpdates

8. your browser will download a file named getUpdates.json. open it with notepad

다음은 getUpdates.json 파일의 내용입니다.

This is the getUpdates.json file. 

 

{"ok":true,"result":[{"update_id":987654321,
"message":{"message_id":1,"from":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME"},"chat":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME","type":"private"},"date":1452737400,"text":"\/start"}},{"update_id":987654321,
"message":{"message_id":2,"from":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME"},"chat":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME","type":"private"},"date":1452737404,"text":"hello"}}]}

 

 

여기서 id 뒤의 숫자가 중요하니 이것도 잘 알아두시기 바랍니다.

Keep the id number(in blue color) along with your token.

 

9. 텔레그램 봇의 기본적인 설정은 끝입니다.

BotFather에게 /setuserpic 등의 명령어를 주어서 꾸미세요. ^^

9. Now you're done with setting up telegram bot. Tell @BotFather /setuserpic to change the picture.

 

 

 

이제 MyBookLive의 Transmission에서 다운로드 완료시 텔레그램으로 메시지를 보내도록 설정하는 방법입니다.

Transmission 설치방법은 우성군의 NAS 홈페이지 http://www.wsgvet.com/bbs/board.php?bo_table=iomega&wr_id=35 를 참고하시기 바랍니다.

This is how-to set up MyBookLive to send message to telegram bot when transmission finishes downloading a torrent.

The link above is about how-to install transmission on MyBookLive, written in Korean.

If you need to install transmission on your MBL, please google it. sorry. :) 

 

1. putty 등으로 ssh를 통해 MyBookLive에 접속합니다.

2. cd /opt/bin  라고 입력합니다. 커서 앞쪽이 MyBookLive:/opt/bin#로 바뀌는게 보입니다.

3. nano nas_notify.sh  라고 입력합니다. 파일이름은 마음대로 바꾸어도 됩니다.

4. 새 창이 뜨면 아래내용을 복사해서 붙여넣습니다. (putty에서는 마우스 오른쪽 버튼을 누르면 붙여넣기가 됩니다.)

1. connect to MyBookLive with putty, etc.

2. type cd /opt/bin

3. type nano nas_notify.sh

4. copy and paste following text. right click on your mouse for paste on your putty

 

#!/bin/sh

 

# telegram configuration
TOKEN='123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE'
URL='https://api.telegram.org/bot'$TOKEN
MSG_URL=$URL'/sendMessage?chat_id='
CHAT_ID="12345678"

 

# function setting
function send_message {
res=$(/usr/bin/curl --data-urlencode "text=$TR_TORRENT_NAME download completed" "$MSG_URL"$CHAT_ID"&")
}

 

# telegram notify gogo
send_message

 

 

이때, TOKEN과 CHAT_ID는 위 텔레그램 봇 설정에서 나온 문자열로 바꿔줍니다.

 

그리고 CTRL+O, 엔터, CTRL+X를 차례로 한번씩 누르면 파일이 저장되고 다시 밖으로 나옵니다.

replace TOKEN and CHAT_ID with your token and chat_id, press Ctrl+O, enter, Ctrl+X to save & exit.

 

4. chmod a+x nas_notify.sh  라고 입력합니다. 파일이 실행가능으로 변경됩니다.

5. chmod 777 nas_notify.sh  라고 입력합니다. 트랜스미션에도 실행권한을 줍니다.

6. /opt/etc/init.d/S90transmission stop  라고 입력합니다. 실행중인 트랜스미션을 정지시킵니다.

7. nano /root/.config/transmission-daemon/settings.json  라고 입력합니다. 트랜스미션 설정파일을 수정합니다.

4. type chmod a+x nas_notify.sh  to change the sh file executable

5. type chmod 777 nas_notify.sh  to give permission to be executed

6. type /opt/etc/init.d/S90transmission stop  to stop transmission

7. type nano /root/.config/transmission-daemon/settings.json to alter setting file of transmission

아래 문자열을 찾습니다. 

    "script-torrent-done-enabled": false,
    "script-torrent-done-filename": "",
 

이렇게 수정합니다.

    "script-torrent-done-enabled": true,
    "script-torrent-done-filename": "/opt/bin/nas_notify.sh",

 

 

 

바뀐 부분은 제일 뒷부분만 이지만, 두줄 전체를 바꾸어버려도 됩니다. 

 

그리고 CTRL+O, 엔터, CTRL+X를 차례로 한번씩 누르면 파일이 저장되고 다시 밖으로 나옵니다.

 

find blue text, and replace them to red text.

press Ctrl+O, enter, Ctrl+X to save & exit.

 

8. /opt/etc/init.d/S90transmission start   라고 입력합니다. 트랜스미션을 다시 시작합니다.

8. type /opt/etc/init.d/S90transmission start  to start transmission again.

 

9. 트랜스미션의 설정이 완료되었습니다.

9. now you're done with everything!

 

 

 

 

참고 : 포고플러그에서 트랜스미션 다운로드 완료시 스마트폰으로 알람받기 http://www.clien.net/cs2/bbs/board.php?bo_table=lecture&wr_id=233890

참고 : 트랜스미션, Flexget 다운로드 완료시 텔레그램으로 알람받기 http://www.clien.net/cs2/bbs/board.php?bo_table=lecture&wr_id=303717

참고 : 텔레그램 봇 설정 http://domoticz.com/wiki/Telegram_Bot

참고 : 텔레그램 봇 설정 https://core.telegram.org/bots

참고 : putty 프로그램 다운로드 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html