PHP code example of tudor2004 / google-bot-laravel

1. Go to this page and download the library: Download tudor2004/google-bot-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tudor2004 / google-bot-laravel example snippets


'providers' => [
  Tudorica\GoogleBot\GoogleBotServiceProvider::class,
],

'aliases' => [
  ...
  'GoogleBot' => Tudorica\GoogleBot\Facades\GoogleBotFacade::class,
],

// Handle commands for a custom 'audio' bot. We pass all the request data that the Google Chat event sends us.
namespace App\Http\Controllers;

class WebhookController extends Controller
{
    public function webhook(Request $request)
    {
        try {        
            
            return GoogleBot::run(AudioBot::class, $request->all());
            
        } catch(BotException $ex) {
            return [
                'text' => 'Something wrong happend';
            ];
        }             
    }
}

namespace App\Bots;
 
use Tudorica\GoogleBot\Contracts\BotContract;
 
class AudioBot extends BotContract
{
     public function name(): string
     {
         return 'Radio';
     }
 
     public function commands(): array
     {
         return [             
             AudioVolume::class             
         ];
     }
}

namespace App\Commands;
 
use Tudorica\GoogleBot\Contracts\CommandContract;
 
class AudioVolume implements CommandContract
{
    /**
     * You can here define a list of users that can perform this command. Use [*] to allow everyone.
     */ 
    public function allowedUsers(): array
    {
        return ['*'];
    }

    /**
     * Define here the command name. You can also use here regular expressions.
     */
    public function name(): string
    {
        return '!audio volume (.+)';
    }

    /**
     * This description message will be used for the help.
     */
    public function description(): string
    {
        return 'Set volume.';
    }

    /**
     * The handler the executes the command. This has to respond with a string, that will be in the end be returned in the chat room.
     */
    public function handle(string $command): string
    {
        // Some logic for turning the volume of your speakers up or down...

        return 'Ok, volume is now ' . $volume . '.';
    }
}