botman / driver-telegram

BotMan Telegram Driver
MIT License
88 stars 75 forks source link

Undefined index: vcard in TelegramContactDriver #82

Closed vdomah closed 4 years ago

vdomah commented 4 years ago

Required Information

Expected behaviour

Receiving contact array after user sends his contact details.

Actual behaviour

TelegramContactDriver is not checking iv vcard field is present. That causes error:

Undefined index: vcard {"exception":"[object] (ErrorException(code: 0): Undefined index: vcard at /var/www/html/vendor/botman/driver-telegram/src/TelegramContactDriver.php:55)

Steps to reproduce

Using this code example: https://gist.github.com/yarkm13/4d9359f2c96149a012f563ea41849c02

Extra details

Solved it by extending TelegramContactDriver and overriding loadMessages method:

public function loadMessages()
    {
        $message = new IncomingMessage(Contact::PATTERN, $this->event->get('from')['id'], $this->event->get('chat')['id'], $this->event);
        $message->setContact(new Contact(
            $this->event->get('contact')['phone_number'],
            $this->event->get('contact')['first_name'],
            $this->event->get('contact')['last_name'],
            $this->event->get('contact')['user_id'],
            $this->event->get('contact')['vcard'] ?? null
        ));

        $this->messages = [$message];
    }

then in routes/botman.php:

DriverManager::unloadDriver(TelegramContactDriverBase::class);
DriverManager::loadDriver(TelegramContactDriver::class);
// required to do before the 'resolve'
$botman = resolve('botman');
pedroufv commented 4 years ago

same problem here...the bot keep stop when don't have vcard

EduardMalik commented 4 years ago

Same problem too.

curl 'http://chatbot.loc:8080/botman' POST -d '{"update_id":513976669, "message":{"message_id":200,"from":{"id":1218871752,"is_bot":false,"first_name":"Eduard","last_name":"Malik","username":"eduard_malik","language_code":"ru"},"chat":{"id":1218871752,"first_name":"Eduard","last_name":"Malik","username":"eduard_malik","type":"private"},"date":1600069362,"contact":{"phone_number":"79789999999","first_name":"Eduard","last_name":"Malik","user_id":1218871752}}}'

ErrorException: Undefined index: vcard in file /home/hotadd/www/chatbot/vendor/botman/driver-telegram/src/TelegramContactDriver.php on line 55 Stack trace:

  1. ErrorException->() /home/hotadd/www/chatbot/vendor/botman/driver-telegram/src/TelegramContactDriver.php:55
  2. Illuminate\Foundation\Bootstrap\HandleExceptions->handleError() /home/hotadd/www/chatbot/vendor/botman/driver-telegram/src/TelegramContactDriver.php:55
  3. BotMan\Drivers\Telegram\TelegramContactDriver->loadMessages() /home/hotadd/www/chatbot/vendor/botman/driver-telegram/src/TelegramContactDriver.php:38
  4. BotMan\Drivers\Telegram\TelegramContactDriver->getMessages() /home/hotadd/www/chatbot/vendor/botman/botman/src/BotMan.php:192
  5. BotMan\BotMan\BotMan->getMessages() /home/hotadd/www/chatbot/vendor/botman/botman/src/Traits/HandlesConversations.php:170
  6. BotMan\BotMan\BotMan->loadActiveConversation() /home/hotadd/www/chatbot/vendor/botman/botman/src/BotMan.php:422
  7. BotMan\BotMan\BotMan->listen() /home/hotadd/www/chatbot/routes/botman.php:26
  8. Illuminate\Routing\RouteFileRegistrar->{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Route.php:205
  9. Illuminate\Routing\Route->runCallable() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Route.php:179
    1. Illuminate\Routing\Route->run() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Router.php:681
    2. Illuminate\Routing\Router->Illuminate\Routing{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130
    3. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41
    4. Illuminate\Routing\Middleware\SubstituteBindings->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    5. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:77
    6. Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    7. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49
    8. Illuminate\View\Middleware\ShareErrorsFromSession->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    9. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:56
    10. Illuminate\Session\Middleware\StartSession->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    11. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
    12. Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    13. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67
    14. Illuminate\Cookie\Middleware\EncryptCookies->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    15. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105
    16. Illuminate\Pipeline\Pipeline->then() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Router.php:683
    17. Illuminate\Routing\Router->runRouteWithinStack() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Router.php:658
    18. Illuminate\Routing\Router->runRoute() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Router.php:624
    19. Illuminate\Routing\Router->dispatchToRoute() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Routing/Router.php:613
    20. Illuminate\Routing\Router->dispatch() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:170
    21. Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:130
    22. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/fideloper/proxy/src/TrustProxies.php:57
    23. Fideloper\Proxy\TrustProxies->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    24. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
    25. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    26. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21
    27. Illuminate\Foundation\Http\Middleware\TransformsRequest->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    28. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
    29. Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    30. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:63
    31. Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:171
    32. Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:105
    33. Illuminate\Pipeline\Pipeline->then() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:145
    34. Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter() /home/hotadd/www/chatbot/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:110
    35. Illuminate\Foundation\Http\Kernel->handle() /home/hotadd/www/chatbot/public/index.php:55
crynobone commented 4 years ago

Fixed via botman/driver-telegram#88 and will be released as 1.6.2 later today.