 ringcentral    /
                    glip-botman
                      ringcentral    /
                    glip-botman
                
                            | 1 | <?php | ||
| 2 | |||
| 3 | require('vendor/autoload.php'); | ||
| 4 | require('GlipBotman.php'); | ||
| 5 | |||
| 6 | use Mpociot\BotMan\BotManFactory; | ||
| 7 | use Mpociot\BotMan\BotMan; | ||
| 8 | use Mpociot\BotMan\DriverManager; | ||
| 9 | use Symfony\Component\HttpFoundation\Request; | ||
| 10 | use Symfony\Component\HttpFoundation\Response; | ||
| 11 | use GlipDriver\GlipBotman; | ||
| 12 | |||
| 13 | // Parse the .env file | ||
| 14 | $dotenv = new Dotenv\Dotenv(getcwd()); | ||
| 15 | $dotenv->load(); | ||
| 16 | |||
| 17 | |||
| 18 | // Load the values from .env | ||
| 19 | $config = [ | ||
| 20 | 'GLIP_SERVER' => $_ENV['GLIP_SERVER'], | ||
| 21 | 'GLIP_APPKEY' => $_ENV['GLIP_APPKEY'], | ||
| 22 | 'GLIP_APPSECRET' => $_ENV['GLIP_APPSECRET'], | ||
| 23 | 'GLIP_USERNAME' => $_ENV['GLIP_USERNAME'], | ||
| 24 | 'GLIP_PASSWORD' => $_ENV['GLIP_PASSWORD'], | ||
| 25 | 'GLIP_EXTENSION' => $_ENV['GLIP_EXTENSION'], | ||
| 26 | ]; | ||
| 27 | |||
| 28 | |||
| 29 | // Create the Subscription using Webhooks Method | ||
| 30 | $cacheDir = __DIR__ . DIRECTORY_SEPARATOR . '_subscribe'; | ||
| 31 | if (!file_exists($cacheDir)) { | ||
| 32 | |||
| 33 | mkdir($cacheDir); | ||
| 34 | $request = Request::createFromGlobals(); | ||
| 35 | // GlipWebhook verification | ||
| 36 |     if ($request->headers->has('Validation-Token')) | ||
| 37 |     { | ||
| 38 | |||
| 39 |         return Response::create('',200,array('Validation-Token' => getallheaders()['Validation-Token']))->send(); | ||
| 0 ignored issues–
                            show             Bug
    
    
    
        introduced 
                            by  
  Loading history... | |||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | // Load the Driver into Botman | ||
| 44 | DriverManager::loadDriver(GlipBotman::class); | ||
| 45 | |||
| 46 | print "The vaialble drivers are : ". print_r(DriverManager::getAvailableDrivers()); | ||
| 47 | |||
| 48 | // Create a Botman Instance | ||
| 49 | $botman = BotManFactory::create($config); | ||
| 50 | |||
| 51 | |||
| 52 | // Give the bot something to listen for. | ||
| 53 | $botman->hears('hello', function (BotMan $bot) { | ||
| 54 |     $bot->reply('Hello yourself.'); | ||
| 55 | })->driver(GlipBotman::class); | ||
| 56 | |||
| 57 | $botman->hears('what is your name', function (BotMan $bot) { | ||
| 58 |     $bot->reply('My name is Minion Bot.'); | ||
| 59 | })->driver(GlipBotman::class); | ||
| 60 | |||
| 61 | |||
| 62 | $botman->hears('What can you do', function (BotMan $bot) { | ||
| 63 |     $bot->reply('I am still under construction'); | ||
| 64 | })->driver(GlipBotman::class); | ||
| 65 | |||
| 66 | |||
| 67 | // Start listening | ||
| 68 | $botman->listen(); | 
