因此,我需要閱讀我所在的一個特定頻道的所有新消息(而不是管理員)。我搜索了不同的客戶端API(.NET,PHP,nodejs),但沒有一個幫助。閱讀電報頻道信息
你有什麼想法我可以做到這一點?
謝謝!
因此,我需要閱讀我所在的一個特定頻道的所有新消息(而不是管理員)。我搜索了不同的客戶端API(.NET,PHP,nodejs),但沒有一個幫助。閱讀電報頻道信息
你有什麼想法我可以做到這一點?
謝謝!
第一步是將電報機器人添加爲頻道管理員,如果不是,則無法讀取頻道信息!
這是我如何做的:
安裝電報https://github.com/vysheng/tg
安裝Cli時wraper 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:
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')
})
})
有沒有辦法使用pytg從特定頻道接收帖子。 –
@ycode其中是您收到消息的渠道?或者你只收到直接的消息? –
嗯,這就是問題所在。閱讀頻道消息實際上是我唯一想做的事情,因此我希望在C#,VB,PHP,Java或Nodejs中使用這種電報客戶端。 – Digot