2016-10-22 11 views
4

그래서 나는 (관리자가 아닌) 특정 채널의 모든 새 메시지를 읽어야합니다. 다른 클라이언트 api (.NET, PHP, nodejs)를 검색했지만 아무도 도움이되지 않았습니다.텔레 그램 채널 메시지 읽기

내가 어떻게 이런 일을 할 수 있는지 알고 있니?

감사합니다.

+0

글쎄. 채널 메시지를 읽는 것은 내가 할 수있는 유일한 일이다. 그래서 나는 이것을 위해 사용할 수있는 C#, VB, PHP, Java 또는 Nodejs에서 전신 클라이언트를 원했다. – Digot

답변

0

첫 번째 단계는 채널 메시지를 읽을 수 없다면 전보 봇을 채널 관리자로 추가하는 것입니다 !!! 여기

4

내가 그것을 어떻게 있습니다 :

https://github.com/luckydonald/pytg

from pytg import Telegram 
from pytg.utils import coroutine 
tg  = Telegram( telegram="./tg/bin/telegram-cli", pubkey_file="./tg/tg-server.pub") 
receiver = tg.receiver 
QUIT = False 
@coroutine 
def main_loop(): 
    try: 
    while not QUIT: 
     msg = (yield) # it waits until it got a message, stored now in msg. 
     if msg.text is None: 
     continue 
     print(msg.event) 
     print(msg.text) 
    except GeneratorExit: 
    pass 
    except KeyboardInterrupt: 
    pass 
    else: 
    pass 

receiver.start() 
receiver.message(main_loop()) 

NodeJS 버전 wraper CLI를 설치

전보 https://github.com/vysheng/tg를 설치 : 문제의

const path = require('path'); 
const TelegramAPI = require('tg-cli-node'); 
const config = { 
    telegram_cli_path: path.join(__dirname, 'tg/bin/telegram-cli'), //path to tg-cli (see https://github.com/vysheng/tg) 
    telegram_cli_socket_path: path.join(__dirname, 'socket'), // path for socket file 
    server_publickey_path: path.join(__dirname, 'tg/tg-server.pub'), // path to server key (traditionally, in %tg_cli_path%/tg-server.pub) 
} 

const Client = new TelegramAPI(config) 

Client.connect(connection => { 
    connection.on('message', message => { 
     console.log('message : ', message) 
     console.log('message event : ', message.event) 
     console.log('message text : ', message.text)   
     console.log('message from :', message.from) 
    }) 
    connection.on('error', e => { 
     console.log('Error from Telegram API:', e) 
    }) 
    connection.on('disconnect',() => { 
     console.log('Disconnected from Telegram API') 
    }) 
}) 
+0

은 pytg를 사용하여 특정 채널에서 소식을받는 방법입니다. –

+0

@ycode 여기서 메시지를 수신하는 채널은 무엇입니까? 또는 직접 메시지를 수신하고 있습니까? –

관련 문제