【发布时间】:2016-07-29 22:13:28
【问题描述】:
我有一个电话号码列表。
我需要他们在 Telegram 中匹配的 username 和 first_name(如果他们订阅了 Telegram)。
我想通过 Telegram BOT API 获取这些信息(用户名和名字)。
有可能吗?我怎样才能做到这一点? (使用 PHP)
这是我的示例代码:
<?php
//telegram sdk and configuration
$client = new Zelenin\Telegram\Bot\Api('someRandomToken');
$update = json_decode(file_get_contents('php://input'));
//your app
try {
if($update->message->text != '/next_event_datetime')
exit;
$dom = Sunra\PhpSimple\HtmlDomParser::file_get_html('http://laratalks.com/');
$element = $dom->find('#location header.section-header h3', 0);
$dateTime = $element->plaintext;
$response = $client->sendMessage([
'chat_id' => $update->message->chat->id,
'text' => $dateTime
]);
} catch (\Zelenin\Telegram\Bot\NotOkException $e) {
//echo error message ot log it
//echo $e->getMessage();
}
【问题讨论】:
-
最好不要提及您的示例代码,因为它与您的问题部分无关
-
想一想...您是否希望只有您的电话号码的人能够获得您的姓名和用户名?这将是对隐私的侵犯,并且对于想要对您进行网络钓鱼攻击的人来说是一个严重的潜在开始。
标签: php api telegram telegram-bot