【问题标题】:How to handle contact request in telegram-bot-sdk using Laravel如何使用 Laravel 在电报机器人 SDK 中处理联系请求
【发布时间】:2019-12-18 20:47:24
【问题描述】:

我正在使用https://github.com/irazasyed/telegram-bot-sdk 在我的 Laravel 项目中开发一个机器人。我已使用回复键盘标记成功请求联系。问题是我无法进一步处理联系人。我需要有关如何使用我请求的电话号码进行进一步处理的帮助。

这是我现在使用的代码,

public function requestContact() 
{
    $btn = Keyboard::button([
        'text' => 'Share my phone number',
        'request_contact' => true
    ]);
    $keyboard = Keyboard::make([
        'keyboard' => [[$btn]],
        'resize_keyboard' => true,
        'one_time_keyboard' => true
    ]);
    Telegram::sendMessage([
        'chat_id' => $this->chat_id,
        'text' => 'I need your contact to get your ID. Please click the Share Contact button below.',
        'reply_markup' => $keyboard
    ]);ref
}

【问题讨论】:

    标签: php laravel telegram-bot php-telegram-bot


    【解决方案1】:

    第一: 您不需要“共享联系人”来获取您在此处编写的用户 ID:

    'text' => '我需要你的联系人来获取你的 ID。请点击下方的分享联系人按钮。'

    第二: 我通过我的一个机器人分享了我的联系方式,Telegram 为我发送了这个回复:

     {
       "ok": true,
       "result": [{
         "update_id": 751829617,
         "message": {
           "message_id": 5971,
           "from": {
             "id": 223110107,
             "is_bot": false,
             "first_name": "\u011e\u0105me",
             "last_name": "\u01fever!",
             "username": "GameO7er",
             "language_code": "en"
           },
           "chat": {
             "id": 223110107,
             "first_name": "\u011e\u0105me",
             "last_name": "\u01fever!",
             "username": "GameO7er",
             "type": "private"
           },
           "date": 1568724975,
           "contact": {
             "phone_number": "+1*******88",
             "first_name": ".",
             "user_id": 223110107
           }
         }
       }]
     }
    

    如您在上面的 JSON 格式示例中所见,您可以执行以下操作:

    TelegramResponse->message->contact->phone_number

    上面的代码只是一个示例,它不起作用。但您可以查找phone_number here

    【讨论】:

      猜你喜欢
      • 2021-05-16
      • 2017-07-10
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多