• XSS.stack #1 – первый литературный журнал от юзеров форума

Telegram Bot

Adventurer

HDD-drive
Пользователь
Регистрация
14.02.2020
Сообщения
36
Реакции
10
Я пишу бота для телеги и застрял в некоторых вопросах:
1) Как можно получить доступ к комментам под постами. получить и сам коммент и отправителя
2) Как получить статус юзера если он скрыл
Буду благодарен за помощь
 
 
1) Как можно получить доступ к комментам под постами. получить и сам коммент и отправителя

Easy! The comments are actually hosted in a separate 'discussion' channel. The bot should be added to the discussion group associated with the channel (where the replies are hosted). Once that's been done, your bot will have access to the replies too. I've written a quick script that access messages and associates them with replies in the discussion channel, to show you how this is done:

Python:
import telegram
bot = telegram.Bot(token='YOUR TOKEN FROM BOTFATHER')
messages = {}
for update in bot.get_updates():
    m = update.message
    if m is not None and m.text is not None:
        sender = m.from_user.first_name
        reply = m.reply_to_message
        if reply and reply.message_id in messages:
            messages[reply.message_id]['replies'].append({
                'sender' : sender,
                'text' : m.text
            })
        else:
            messages[m.message_id] = {
                'sender' : sender,
                'text' : m.text,
                'replies' : []
            }
for id, msg in messages.items():
    print()
    print(f"{msg['sender']}: {msg['text']}")
  
    for reply in msg['replies']:
        print(f"|____ {reply['sender']}: {reply['text']}")
print()

And here's what the output looks like using a test channel I created for this purpose:

Код:
hehe@macos:~/Apps$ python3 view_telegram_replies.py

User 1: I am an original post
|____ User 2: And I am a reply :)
|____ User 2: Another reply

User 1: A second original post has appeared!
|____ User 2: And would you look at that...more replies!

User 2: This top level post has no replies

The telegram Python library I'm using here is this one: https://github.com/python-telegram-bot/python-telegram-bot

I hope this helps! If not, let me know where you get stuck so we can help you move forward :)

2) Как получить статус юзера если он скрыл

Do you mean you want to see whether a user is online or not, even though they've hidden their online status? In theory, this should not be possible via normal means. Maybe someone else here knows something clever that can be done, though. Good luck!
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх