Added channel posting

This commit is contained in:
aymm 2021-04-18 15:13:59 +02:00
parent 51a798ea3e
commit f9fbbbd225
Signed by: phlaym
GPG Key ID: A06651BAB6777237
3 changed files with 45 additions and 9 deletions

View File

@ -313,6 +313,13 @@ class APnutI
return $this->makeRequest($method, $end_point, $parameters, $content_type); 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( public function get(
string $end_point, string $end_point,
array $parameters = [], array $parameters = [],

View File

@ -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 public function __toString(): string
{ {
$str = ''; $str = '';

View File

@ -192,15 +192,6 @@ class Poll
public static function makePollNoticeRaw(int $poll_id, string $poll_token) 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 [ return [
'io.pnut.core.poll-notice' => [ 'io.pnut.core.poll-notice' => [
[ [