This repository has been archived on 2024-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
discord-questbook/Matterbridge.php

24 lines
670 B
PHP
Raw Permalink Normal View History

2021-09-24 16:59:31 +03:00
<?php
class Matterbridge {
protected $connection;
public function __construct() {
$this->connection = new \GuzzleHttp\Client([
'base_uri' => $_ENV['MATTERBRIDGE_URL'],
]);
2021-09-24 16:59:31 +03:00
}
public function post($text, $username) {
$response = $this->connection->request('POST', '/api/message', [
'json' => [
2021-09-24 16:59:31 +03:00
'gateway' => $_ENV['MATTERBRIDGE_GATEWAY'],
'text' => $text,
'username' => $username
],
'stream' => true,
2021-09-24 16:59:31 +03:00
]);
$body = $response->getBody();
while (!$body->eof()) {
echo $body->read(1024);
}
2021-09-24 16:59:31 +03:00
}
}