标签: telegram

通过电报机器人发送带有描述的文档

我正在尝试使用 Telegram 机器人用户将 pdf 文档和有关它的小描述从我的服务器发送到 Telegram 组。我可以使用 /sendDocument 方法自行发送文档。然而,这并不完全是我想要的。我想知道这可能吗?

curl -F chat_id="-xxxxxxxxxx" -F document=@"/home/telegram/someFile.pdf" -F text="Text Message with attachment" https://api.telegram.org/bot<token>/sendMessage
Run Code Online (Sandbox Code Playgroud)

telegram telegram-bot

0
推荐指数
1
解决办法
1万
查看次数

Telegram 登录响应“NOT_AUTHORIZED”

我正在尝试使用 Telegram 登录小部件。

我已在登录页面中插入以下脚本:

<script async="" src="https://telegram.org/js/telegram-widget.js?4" data-telegram-login="<name of bot>" data-size="large" data-auth-url="http://local.<domain>/tg" data-radius="0" data-request-access="write"></script>
Run Code Online (Sandbox Code Playgroud)

只要显示登录小部件,此操作就有效。

当我单击“使用 Telegram 登录”按钮时,如果我想登录该网站,它会正确地要求我接受/拒绝。但随后就没有再发生任何事情。

通过调查网络请求,我发现电报服务器响应如下:

{"error":"NOT_AUTHORIZED","html":"<button class=\"btn tgme_widget_login_button\" onclick=\"return TWidgetLogin.auth();\"><i class=\"tgme_widget_login_button_icon\"><\/i>Log in with Telegram<\/button>","origin":"http:\/\/local.<domain>"}
Run Code Online (Sandbox Code Playgroud)

有什么是我应该做的而错过的吗?

我确实与 @BotFather 进行了交谈,将域名设置为http://local.<domain>.

登录时,我还在客户端中收到来自 Telegram 的消息,告诉我:

您已通过@成功登录local.furry.cafe。该网站收到您的姓名、用户名和个人资料图片。

可能有问题的事情:

  • local.<domain>是我的 /etc/hosts 的一部分,但这应该不是问题,对吧?
  • 我的开发机器上没有使用 HTTPS?但这并没有在任何地方写成要求。

telegram

0
推荐指数
1
解决办法
2392
查看次数

从 Telegram 聊天中抓取活跃用户而不是所有用户

我希望使用 Telethon API 抓取 Telegram 组用户列表。因此它会抓取组中的所有用户,我只想抓取过去 24 小时/最近的 ACTIVE 用户。然而我无法这样做/不明白。如果有人可以帮助我并告诉我放置预期代码的位置会非常好

谢谢你的问候!

from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty
import csv

api_id = 
api_hash = ''
phone = '+'
client = TelegramClient(phone, api_id, api_hash)

client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('Enter the code: '))


chats = []
last_date = None
chunk_size = 200
groups=[]

result = client(GetDialogsRequest(
             offset_date=last_date,
             offset_id=0,
             offset_peer=InputPeerEmpty(),
             limit=chunk_size,
             hash = 0
         ))
chats.extend(result.chats)

for chat in chats:
    try:
        if chat.megagroup== True:
            groups.append(chat)
    except:
        continue

print('Choose a group …
Run Code Online (Sandbox Code Playgroud)

python python-3.x telegram telethon

0
推荐指数
1
解决办法
3141
查看次数

使用 Telethon 从 event.message 对象获取发件人的用户名

当消息到达组时,我无法获取 event.message 对象的发件人的用户名。

我尝试了 get_entity、get_input_entity 方法。但这显示错误。AttributeError: 'coroutine' 对象没有属性 'chat' 我什至不知道如何处理 coroutine 对象

@client.on(events.NewMessage(chats=input_groups_entity))
    async def handler(event):
        print(event)
        sender = event.message.chat_id
        perticipants = client.get_participants(event.message.to_id)
        np = client.get_input_entity(event.message.from_id)
        await client.send_message(event.message.to_id, message=event.message.message)
Run Code Online (Sandbox Code Playgroud)

我只想从消息对象中提取用户名

telegram telegram-bot telethon

0
推荐指数
1
解决办法
3052
查看次数

有没有办法用电报机器人发送链接并且在点击/点击时不显示警报?

我正在开发一个电报机器人,我需要将外部网站的链接发送到频道中。我注意到,当我在聊天中手动粘贴链接时,用户只需单击该链接即可导航到该网站,另一方面,单击从机器人发送的链接,会显示确认导航的警报

我正在使用带有自定义库的 Java 来与 Telegram Bot API 进行交互。我正在使用 SendMessage 操作向频道发送消息。

解析模式是 HTML,我正在发送带有链接的 html 锚标记的小文本。

telegram telegram-bot

0
推荐指数
1
解决办法
2316
查看次数

在 Telethon.events 中使用“聊天”参数

我正在运行这个:

from telethon import TelegramClient, events
from telethon.tl.types import PeerChat, PeerChannel

@client.on(events.ChatAction(chats=[PeerChannel(-1001244988104)]))
async def handle_chat_action(event):
    print(event)
    print(event.user_left)

@client.on(events.NewMessage(chats=[PeerChat(-100123456789)]))
async def my_event_handler(event):
    print(event.raw_text)

client.start()
client.run_until_disconnected()
Run Code Online (Sandbox Code Playgroud)

但是,没有得到更新,为什么?这里有什么问题?

起初,我尝试过chats=[-100123456](没有 PeerChat),但没有得到更新......

python python-3.x telegram telethon

0
推荐指数
1
解决办法
1430
查看次数

类型错误:send_message() 收到意外的关键字参数“parse_mode”

下面是我用于电报机器人的代码,该机器人从我喜欢的 Reddit 子版块发布新的更新。这不是我的代码(我在堆栈溢出上在线找到它),但我不断收到此错误。我到处搜索但没有找到任何解决方案。无论如何,即使是关于我应该走哪个方向的轻微信息也将不胜感激。

import telebot
import praw
import config
bot_token = 'x'
bot_chatID = '@monsterKing_bot'
bot = telebot.TeleBot(bot_token)

reddit = praw.Reddit(client_id='x', \
                     client_secret='x', \
                     user_agent='x', \
                     username='x ', \
                     password='x')

def reddit_scraper(submission):
    news_data = []
    subreddit = reddit.subreddit('coronavirus')
    new_subreddit = subreddit.new(limit=500)
    for submission in subreddit.new(limit=5):
        data = {}
        data['title'] = submission.title
        data['link'] = submission.url
        news_data.append(data)
    return news_data

def get_msg(news_data):
    msg = '\n\n\n'
    for news_item in news_data:
        title = news_item['title']
        link = news_item['link']
        msg += title+'\n[<a href="'+link+'">Read the full article --></a>]' …
Run Code Online (Sandbox Code Playgroud)

reddit praw telegram telegram-bot

0
推荐指数
1
解决办法
8204
查看次数

使用bot定期发送电报消息

给出下面的代码:

def start(update, context):
    context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")
Run Code Online (Sandbox Code Playgroud)

是否可以定期调用此函数并使我的机器人自动将消息发送给用户,而不是用户键入“/start”

python-3.x telegram python-telegram-bot telegram-bot

0
推荐指数
1
解决办法
293
查看次数

"async with" 如果事件循环正在运行但没有事件循环

尝试运行Telethon 文档提供的基本代码时,我收到以下错误。我很困惑,因为我还没有建立一个循环。

RuntimeError:如果事件循环正在运行,则必须使用“async with”(即您在“async def”中)

我在 spyder 4.0.1 中使用 python 3.7.7

from telethon.sync import TelegramClient
from telethon import functions, types

def channel_info(username, api_id, api_hash):
    with TelegramClient(username, api_id, api_hash,channel) as client:
        result = client(functions.channels.GetFullChannelRequest(
            channel=channel
        ))
        return(result)

out = channel_info(username, api_id, api_hash)
Run Code Online (Sandbox Code Playgroud)

python telegram telethon

0
推荐指数
1
解决办法
1591
查看次数

如何使用 Telegram Bot 删除所有聊天记录?

是否可以删除我与机器人聊天的所有聊天记录(消息)。

所以控制台版本是这样的:

import os
os.sys("clear") - if Linux
os.sys("cls") - if Windows
Run Code Online (Sandbox Code Playgroud)

我想要的只是使用 bot 删除聊天中的所有消息。

def deleteChat(message):
    #delete chat code
Run Code Online (Sandbox Code Playgroud)

python python-3.x telegram python-telegram-bot telegram-bot

0
推荐指数
1
解决办法
8442
查看次数