如何让我的 Telegram 自动转发机器人在不引用的情况下转发?

问题描述 投票:0回答:1

我有一个自动将消息从通道 A 转发到组 B 的机器人,我使用 Node.js 创建了这个机器人。机器人转发消息但显示它在引用,我怎样才能让它看起来好像是共享的而不显示它,总结没有引用?

代码:

const TelegramBot = require('node-telegram-bot-api');

const sourceChannelId = CHANNEL_ID;
const targetChannelId = CHANNEL_ID;

const bot = new TelegramBot('BOT_TOKEN', { polling: true });

bot.on('channel_post', (msg) => {
  if (msg.chat.id === sourceChannelId) {
    bot.forwardMessage(targetChannelId, sourceChannelId, msg.message_id);
  }
});

我不知道该怎么做,我尝试了 ChatGPT 但没用。

javascript node.js telegram telegram-bot
1个回答
0
投票

如果您希望将消息从 Telegram 上的一个聊天转发到另一个聊天,Telethon 库提供了一个无缝的解决方案来处理此任务。

client.send_message(chat, message)
功能可以有效地用于无引号转发消息,允许转发文件、视频等各种内容

下面的示例演示了如何从源频道检索消息实体,然后将它们作为副本转发到另一个聊天(频道、组或用户):

    from telethon.sync import TelegramClient

# Establish a client connection using your credentials
client = TelegramClient('session_name', api_id, api_hash)

Source_id = -1001444411118  # Replace with your source chat's username or ID
Source_entity = client.get_entity(Source_id)
Source_id = Source_entity.id

Destination_id = '@my__channel'  # Replace with your destination chat's username or ID
Destination_entity = client.get_entity(Destination_id)
Destination_id = Destination_entity.id

# Fetch the latest 3 messages from the source
msgs = client.get_messages(Source_id, limit=3)
msgs = msgs[::-1]  # Reverse the order of messages

# Forward each message to the destination
for msg in msgs:
    client.send_message(Destination_id, msg)

在上面的代码中,确保将 api_id 和 api_hash 替换为您的 Telegram API 凭据。此外,请将源 ID 和目标 ID 替换为您各自频道或群组的实际 ID 或用户名。

希望这有帮助!

© www.soinside.com 2019 - 2024. All rights reserved.