From b9b8042993340c0b183bb09050e1c25f703c0a9c Mon Sep 17 00:00:00 2001 From: Alexander Yakovlev Date: Fri, 24 Sep 2021 22:29:21 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B1=D1=83=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=BE=D0=B4=D0=BD=D0=BE=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=BD?= =?UTF-8?q?=D0=BD=D0=B5=D0=B5=20=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=20Matterbridge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Matterbridge.php | 15 +++++++++++---- start.php | 7 ++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Matterbridge.php b/Matterbridge.php index 81af43a..2875fb7 100644 --- a/Matterbridge.php +++ b/Matterbridge.php @@ -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); + } } } diff --git a/start.php b/start.php index 8348dd4..ae9cbde 100644 --- a/start.php +++ b/start.php @@ -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');