php - Telegram API,获取发件人的电话号码?

标签 php chat bots telegram telegram-bot

我意识到无法使用a Bot 来接收发件人的电话号码。
但是,我确实需要实现一个类似机器人的客户端,它可以响应任何向它发送消息的人。我在 apache 上使用 PHP。

它不是机器人,因为它不接受命令,而是响应任何拥有该电话号码的人发送的文本。因此,您将用户添加为联系人(使用电话号码),然后向其发送文本。

我的目标是在收到时识别发件人的电话号码,我在 Telegram API 上看到有一个 peer ID,但我找不到如何获得电话号码的方法……

最佳答案

试试这个来自 github 的库 https://github.com/irazasyed/telegram-bot-sdk

以及在私有(private)聊天中创建“名片”按钮的代码:

$keyboard = array(
                   array(
                        array( 
                              'text'=>"Send your visit card",
                              'request_contact'=>true
                              )
                        )
                 ); //user button under keyboard.

$reply_markup = $telegram->replyKeyboardMarkup([ 'keyboard' => $auth_keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => false ]);
$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);

以及在用户按下按钮后从“访问卡”获取 unic 用户电话的代码

$user_phone = $result["message"]["contact"]["phone_number"];
if ($user_phone) {
        $reply = $user_phone;
        $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);
   }

关于php - Telegram API,获取发件人的电话号码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38308568/

相关文章:

php, mysqli-stmt.bind-param] : Number of elements in type definition string doesn't match number of bind variables

php - Facebook XMPP 中发生错误

python - 显示 json python discord bot

Javascript:反垃圾邮件自动主持人 (Discord.js)

php从mysql数据库检索数据

php - Paypal 自适应支付 - 描述字段

Facebook 聊天在打开时 Conceal Flash 应用程序

javascript - Microsoft Bot Framework - 读取机器人文件时出错,但所有环境变量都正确?

CLI 中的 PHP SIGTERM

android - 如何使用文本和图像消息创建聊天 Activity