forked from paysera/app-chat-bot-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
47 lines (35 loc) · 1.08 KB
/
index.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
<?php
use Facebook\Facebook;
use Service\ConfigProvider;
include(__DIR__ . '/vendor/autoload.php');
$configProvider = new ConfigProvider(__DIR__ . '/config.json');
if (isset($_REQUEST['hub_challenge'])) {
$challenge = $_REQUEST['hub_challenge'];
if ($_REQUEST['hub_verify_token'] === $configProvider->getParameter('verify_token')) {
echo $challenge;
die();
}
}
$input = json_decode(file_get_contents('php://input'), true);
if ($input === null) {
exit;
}
$message = $input['entry'][0]['messaging'][0]['message']['text'];
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$fb = new Facebook([
'app_id' => $configProvider->getParameter('app_id'),
'app_secret' => $configProvider->getParameter('app_secret'),
]);
if($message=="Labas")
{
$data = [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => $sender,
],
'message' => [
'text' => 'Sveiki, kuo galiu padeti?' ,
]
];
}
$response = $fb->post('/me/messages', $data, $configProvider->getParameter('access_token'));