-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws.php
83 lines (71 loc) · 2.45 KB
/
ws.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
use Aerys\{Host, Request, Response, Router};
use function Aerys\root;
/** @var Router $router */
$router = (new Router())
->route("POST", "/", function(Request $request, Response $response) {
$body = yield $request->getBody();
$requestBody = json_decode($body, true);
$token = '';
if ($token == '') {
$query = http_build_query(
[
'grant_type' => 'client_credentials',
'client_id' => '014e516a-4287-4ba0-818b-0ed97a6a61e0',
'client_secret' => 'fOFffbhtcmWLxzuCurcTaTw',
'scope' => 'https://api.botframework.com/.default',
]
);
$curl = curl_init();
curl_setopt_array(
$curl,
[
CURLOPT_URL => 'https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $query,
CURLOPT_RETURNTRANSFER => true,
]
);
$result = curl_exec($curl);
curl_close($curl);
unset($curl);
$token = json_decode($result, true)['access_token'];
}
$serviceUrl = $requestBody['serviceUrl'];
$conversationId = $requestBody['conversation']['id'];
$url = $serviceUrl . '/v3/conversations/' . $conversationId . '/activities';
$data = json_encode(
[
'type' => 'message',
'text' => 'Hello World!',
'from' => [
'name' => 'Bot',
]
]
);
$curl = curl_init();
curl_setopt_array(
$curl,
[
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => [
'Accept: application/json, text/json',
'Content-Type: application/json',
'Authorization: Bearer ' . $token,
],
CURLOPT_RETURNTRANSFER => true,
]
);
curl_exec($curl);
curl_close($curl);
unset($curl);
$response->setStatus(200);
$response->end(json_encode(['id' => 'sdfdfsddsdfwe']));
});
$root = root(__DIR__ . "/web");
(new Host)
->expose("*", getenv('PORT'))
->use($router)
->use($root);