-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.php
41 lines (32 loc) · 924 Bytes
/
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
<?php
include (__DIR__ . '/vendor/autoload.php');
$access_token = 'your_access_token_here';
$verify_token = 'TOKEN';
$appId = 'your_app_id_here';
$appSecret = 'your_app_secret_here';
if(isset($_REQUEST['hub_challenge'])) {
$challenge = $_REQUEST['hub_challenge'];
if ($_REQUEST['hub_verify_token'] === $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\Facebook([
'app_id' => $appId,
'app_secret' => $appSecret,
]);
$data = [
'messaging_type' => 'RESPONSE',
'recipient' => [
'id' => $sender,
],
'message' => [
'text' => 'You wrote: ' . $message,
]
];
$response = $fb->post('/me/messages', $data, $access_token);