【问题标题】:Read telegram channel messages阅读电报频道消息
【发布时间】:2017-03-04 17:46:25
【问题描述】:

所以我需要阅读我所在的一个特定频道的所有新消息(而不是作为管理员)。我搜索了不同的客户端 API(.NET、PHP、nodejs),但都没有帮助。

你知道我该怎么做吗?

谢谢!

【问题讨论】:

  • 这就是问题所在。阅读频道消息确实是我唯一想做的事情,所以我希望有一个可以用于此目的的 C#、VB、PHP、Java 或 Nodejs 电报客户端。

标签: telegram


【解决方案1】:

我是这样做的:

安装电报https://github.com/vysheng/tg

安装 Cli 包装器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 您从哪里接收消息?还是您只接收直接消息?
  • 什么是socket文件?
【解决方案2】:

第一步是将电报机器人添加为频道管理员,否则您无法阅读频道消息!!!

【讨论】:

  • 如果你可以使用python,那么你可能希望使用telethon
猜你喜欢
  • 1970-01-01
  • 2021-10-12
  • 2017-07-29
  • 2017-09-24
  • 1970-01-01
  • 1970-01-01
  • 2016-09-08
  • 1970-01-01
  • 2017-09-11
相关资源
最近更新 更多