adellantado / bot-template-framework

Easy to build bot scenarios and run them on top of Botman
MIT License
17 stars 4 forks source link

Call to a member function get() on null #1

Closed prappo closed 4 years ago

prappo commented 4 years ago

Hi there, Thank you for your awesome project. I tried to use your package on Botman studio . But there is an error. Here is full error message

message": "Call to a member function get() on null", "exception": "Symfony\Component\Debug\Exception\FatalThrowableError", "file": "/Users/prappo/projects/test/studio/vendor/adellantado/bot-template-framework/src/Traits/CacheTrait.php", "line": 21, "trace": [ { "file": "/Users/prappo/projects/test/studio/vendor/adellantado/bot-template-framework/src/TemplateEngine.php", "line": 293, "function": "getCacheVariable", "class": "BotTemplateFramework\TemplateEngine", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/app/Http/Controllers/BotManController.php", "line": 24, "function": "listen", "class": "BotTemplateFramework\TemplateEngine", "type": "->" }, { "function": "handle", "class": "App\Http\Controllers\BotManController", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Controller.php", "line": 54, "function": "call_user_func_array" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php", "line": 45, "function": "callAction", "class": "Illuminate\Routing\Controller", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 212, "function": "dispatch", "class": "Illuminate\Routing\ControllerDispatcher", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 169, "function": "runController", "class": "Illuminate\Routing\Route", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 679, "function": "run", "class": "Illuminate\Routing\Route", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 30, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php", "line": 41, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Routing\Middleware\SubstituteBindings", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php", "line": 75, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\VerifyCsrfToken", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php", "line": 49, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\View\Middleware\ShareErrorsFromSession", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php", "line": 63, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Session\Middleware\StartSession", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php", "line": 37, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php", "line": 66, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Cookie\Middleware\EncryptCookies", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 104, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 681, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 656, "function": "runRouteWithinStack", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 622, "function": "runRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 611, "function": "dispatchToRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 176, "function": "dispatch", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 30, "function": "Illuminate\Foundation\Http\{closure}", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/fideloper/proxy/src/TrustProxies.php", "line": 57, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Fideloper\Proxy\TrustProxies", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 31, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 31, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php", "line": 27, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php", "line": 62, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 151, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php", "line": 53, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 104, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 151, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 116, "function": "sendRequestThroughRouter", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/public/index.php", "line": 55, "function": "handle", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/Users/prappo/projects/test/studio/server.php", "line": 21, "function": "require_once" } ] }

adellantado commented 4 years ago

Hey, you probably have to pass cache instance (e.g. SymfonyCache) to the constructor of TemplateEngine

prappo commented 4 years ago

Example code please

adellantado commented 4 years ago

composer require symfony/cache

use BotMan\BotMan\Cache\SymfonyCache; use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$cache = new SymfonyCache(new FilesystemAdapter('my_cache', 120, storage_path('app'))); $template = file_get_contents(app_path('scenario.json')); $botman = BotManFactory::create(TemplateEngine::getConfig($template), $cache, null, new DBStorage()); $engine = new TemplateEngine($template, $botman, $cache);

prappo commented 4 years ago

Thank you solved the issue.