From f9fbbbd22520fc20e8b8bf60dc5d7618d4e2eabc Mon Sep 17 00:00:00 2001 From: aymm Date: Sun, 18 Apr 2021 15:13:59 +0200 Subject: [PATCH] Added channel posting --- src/APnutI.php | 7 +++++++ src/Entities/Channel.php | 38 ++++++++++++++++++++++++++++++++++++++ src/Entities/Poll.php | 9 --------- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/APnutI.php b/src/APnutI.php index ea80e5a..53fe9f1 100644 --- a/src/APnutI.php +++ b/src/APnutI.php @@ -313,6 +313,13 @@ class APnutI return $this->makeRequest($method, $end_point, $parameters, $content_type); } + public function postJson( + string $end_point, + array $parameters, + ): array { + return $this->post($end_point, $parameters, 'application/json'); + } + public function get( string $end_point, array $parameters = [], diff --git a/src/Entities/Channel.php b/src/Entities/Channel.php index e86c91d..11f24d8 100644 --- a/src/Entities/Channel.php +++ b/src/Entities/Channel.php @@ -80,6 +80,44 @@ class Channel } } + #TODO_ return message object instead of response + public function postMessage(string $text, array $raw = [], array $parameters = []) + { + $this->api->logger->debug('Creating channel message'); + $params = [ + 'text' => $text, + 'raw' => $raw + ]; + $params = array_merge($params, $parameters); + $this->api->logger->debug(json_encode($params)); + $resp = $this->api->postJson('/channels/'.$this->id.'/messages', $params); + $this->api->logger->debug(json_encode($resp)); + return $resp; + } + + public static function makeChannelInviteRaw(int $channel_id) + { + return [ + 'io.pnut.core.channel.invite' => [ + [ + 'channel_id' => $channel_id + ] + ] + ]; + } + + public static function makeBroadcastNoticeRaw(int $post_id) + { + return [ + 'net.patter-app.broadcast' => [ + [ + 'id' => $post_id, + 'url' => 'https://posts.pnut.io/'.$post_id + ] + ] + ]; + } + public function __toString(): string { $str = ''; diff --git a/src/Entities/Poll.php b/src/Entities/Poll.php index ccd6fd7..e3a1802 100644 --- a/src/Entities/Poll.php +++ b/src/Entities/Poll.php @@ -192,15 +192,6 @@ class Poll public static function makePollNoticeRaw(int $poll_id, string $poll_token) { - /*return [ - 'type' => 'io.pnut.core.poll-notice', - 'value' => [ - '+io.pnut.core.poll' => [ - 'poll_id' => $poll_id, - 'poll_token' => $poll_token - ] - ] - ];*/ return [ 'io.pnut.core.poll-notice' => [ [