Пробуем одностороннее общение с Matterbridge
This commit is contained in:
parent
051d79ac17
commit
b9b8042993
|
@ -2,15 +2,22 @@
|
|||
class Matterbridge {
|
||||
protected $connection;
|
||||
public function __construct() {
|
||||
$this->connection = new \GuzzleHttp\Client();
|
||||
$this->connection = new \GuzzleHttp\Client([
|
||||
'base_uri' => $_ENV['MATTERBRIDGE_URL'],
|
||||
]);
|
||||
}
|
||||
public function post($text, $username) {
|
||||
$this->connection->post($_ENV['MATTERBRIDGE_URL'].'/api/message', [
|
||||
'body' => json_encode([
|
||||
$response = $this->connection->request('POST', '/api/message', [
|
||||
'json' => [
|
||||
'gateway' => $_ENV['MATTERBRIDGE_GATEWAY'],
|
||||
'text' => $text,
|
||||
'username' => $username
|
||||
]),
|
||||
],
|
||||
'stream' => true,
|
||||
]);
|
||||
$body = $response->getBody();
|
||||
while (!$body->eof()) {
|
||||
echo $body->read(1024);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ $dotenv->load();
|
|||
// TODO post missing messages
|
||||
//
|
||||
|
||||
/*
|
||||
$chat = new Questbook();
|
||||
$bridge = new Matterbridge();
|
||||
$timestamp = '';
|
||||
|
@ -23,10 +24,14 @@ while(true) {
|
|||
try {
|
||||
$bridge->post($msg[2], $msg[1]);
|
||||
} catch (\Exception $e) {
|
||||
echo 'Error posting';
|
||||
echo $e->getMessage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
$timestamp = ((int) date('U')) * 1000;
|
||||
sleep(2000);
|
||||
}
|
||||
*/
|
||||
|
||||
$bridge = new Matterbridge();
|
||||
$bridge->post('hi', 'testuser');
|
||||
|
|
Reference in New Issue