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