Пробуем одностороннее общение с Matterbridge

This commit is contained in:
Alexander Yakovlev 2021-09-24 22:29:21 +07:00
parent 051d79ac17
commit b9b8042993
Signed by: oreolek
GPG Key ID: 8D24103F5EE2A6C0
2 changed files with 17 additions and 5 deletions

View File

@ -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);
}
}
}

View File

@ -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');