NoAd
NoAd

Reputation: 181

Call to undefined method Symfony\Component\HttpFoundation\Response::create() when adding webhook in facebook

Description:

Hi, im geting this error in laravel 9, how to handle it easiest way?

method create not exist, so should i make new class that extends Request with method create ?

I already tried to change all references from use Symfony\Component\HttpFoundation\Response; to Illuminate\Http\Response (and Request) but this also not work.

curl -X GET "https://somedomain.org/botman?hub.verify_token=MySecretTokenFromDotENV&hub.challenge=CHALLENGE_ACCEPTED&hub.mode=subscribe"

Reponse:

Error: Call to undefined method Symfony\Component\HttpFoundation\Response::create() in file /var/www/nams/botman/driver-facebook/src/FacebookDriver.php on line 120

#0 /var/www/nams/botman/botman/src/Drivers/DriverManager.php(157): BotMan\Drivers\Facebook\FacebookDriver->verifyRequest()
#1 /var/www/nams/botman/botman/src/BotMan.php(542): BotMan\BotMan\Drivers\DriverManager::verifyServices()
#2 /var/www/nams/botman/botman/src/BotMan.php(421): BotMan\BotMan\BotMan->verifyServices()
#3 /var/www/nams/app/Http/Controllers/BotManController.php(40): BotMan\BotMan\BotMan->listen()
#4 /var/www/nams/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\BotManController->handle()...

Steps To Reproduce:

Install botman on laravel 9 from local repository (path) change in composer/json dependencies to fit laravel 9 Try to connect to facebook like:

        $config = [
            'user_cache_time' => 720,

            'config' => [
                'conversation_cache_time' => 720 ,
            ],
            // Your driver-specific configuration
            'facebook' => [
                'token' => env('FACEBOOK_TOKEN'),
                'app_secret' => env('FACEBOOK_APP_SECRET'),
                'verification' => env('FACEBOOK_VERIFICATION'),
            ]
        ];
        $botman = app('botman');
        DriverManager::loadDriver(\BotMan\Drivers\Facebook\FacebookDriver::class);
        BotManFactory::create($config, new LaravelCache());
        $botman->listen();

try to get response for facebook by: curl -X GET "https://somedomain.org/botman?hub.verify_token=MySecretTokenFromDotENV&hub.challenge=CHALLENGE_ACCEPTED&hub.mode=subscribe"

Function that generates error is below, probably updating it to newest laravel/symfony will work, but I'm not yet so confident to know how to repair this

 /**
 * @param  Request  $request
 * @return null|Response
 */
public function verifyRequest(Request $request)
{
    if ($request->get('hub_mode') === 'subscribe' && $request->get('hub_verify_token') === $this->config->get('verification')) {
        return Response::create($request->get('hub_challenge'))->send();
    }
}

Upvotes: 0

Views: 1654

Answers (1)

nathant
nathant

Reputation: 11

You can replace

use Symfony\Component\HttpFoundation\Response;

by

use Response; (\Illuminate\Support\Facades\Response)

And in the function do :

 /**
 * @param  Request  $request
 * @return null|Response
 */
public function verifyRequest(Request $request)
{
    if ($request->get('hub_mode') === 'subscribe' && $request->get('hub_verify_token') === $this->config->get('verification')) {
        return Response::make($request->get('hub_challenge'))->send();
    }
}

At least it worked for me on TwilioDriver

Upvotes: 1

Related Questions