You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Telegram Bot API统计特定邀请链接的新增用户数

统计Telegram私密频道特定邀请链接的用户加入数

问题背景

我通过Telegram Bot API为Telegram私密频道创建了多个邀请链接,需要统计通过特定链接加入频道的用户数量。机器人已拥有频道管理员的全部必要权限,但用户加入时无消息发送至机器人的Webhook。目前我已通过Telegram Bot API实现该统计功能,现寻求使用Telegram API的getChatInviteImporters方法的代码示例。

创建邀请链接的代码

$params = [
    'chat_id' => '-100*********'
];

$ch = curl_init($TgAPI.'bot'.'token'.'/createChatInviteLink');
curl_setopt_array($ch, array(
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $params,
    CURLOPT_TIMEOUT    => 60
));
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

print $output;

此前尝试统计的代码及报错

我曾尝试以下代码实现统计,但触发致命错误:

require_once 'vendor/autoload.php'; // Load telegram-bot/api

$apiToken = 'hash';
$inviteLink = 'link';
$chatId     = '-100*****';

$telegram = new \TelegramBot\Api\Client($apiToken);

$importers = $telegram->messages->getChatInviteImporters($chatId, $inviteLink);

print_r($importers);

报错信息:

Fri Jul 14 07:33:40.260995 2023] [php7:error] [pid 698972] [client 127.0.0.1:45142] PHP Fatal error: Uncaught Error: Call to a member function getChatInviteImporters() on null in /home/leonid/Web/telegram/testMethod.php:36\nStack trace:\n#0 {main}\n thrown in /home/leonid/Web/telegram/testMethod.php on line 36

当前需求

已通过Telegram Bot API完成统计功能,现需要基于Telegram API的getChatInviteImporters方法的完整代码示例。

内容的提问来源于stack exchange,提问作者LeonidMew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 12:53:13