Skip to content

Commit

Permalink
fix(chat): Added metadata definition for chat.postMessage and history (
Browse files Browse the repository at this point in the history
  • Loading branch information
tchapuis authored Nov 10, 2023
1 parent 99ed82c commit 9b923e4
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 165 deletions.
2 changes: 2 additions & 0 deletions generated/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1782,6 +1782,7 @@ public function chatPostEphemeral(array $formParameters = [], array $headerParam
* @var string $icon_emoji Emoji to use as the icon for this message. Overrides `icon_url`. Must be used in conjunction with `as_user` set to `false`, otherwise ignored. See [authorship](#authorship) below.
* @var string $icon_url URL to an image to use as the icon for this message. Must be used in conjunction with `as_user` set to false, otherwise ignored. See [authorship](#authorship) below.
* @var bool $link_names find and link channel names and usernames
* @var string $metadata JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
* @var bool $mrkdwn Disable Slack markup parsing by setting to `false`. Enabled by default.
* @var string $parse Change how messages are treated. Defaults to `none`. See [below](#formatting).
* @var bool $reply_broadcast Used in conjunction with `thread_ts` and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to `false`.
Expand Down Expand Up @@ -1995,6 +1996,7 @@ public function conversationsCreate(array $formParameters = [], array $headerPar
*
* @var string $channel conversation ID to fetch history for
* @var string $cursor Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
* @var bool $include_all_metadata return all metadata associated with this message
* @var bool $inclusive include messages with latest or oldest timestamp in results only when either timestamp is specified
* @var string $latest end of time range of messages to include in results
* @var int $limit The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
Expand Down
4 changes: 3 additions & 1 deletion generated/Endpoint/ChatPostMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ChatPostMessage extends \JoliCode\Slack\Api\Runtime\Client\BaseEndpoint im
* @var string $icon_emoji Emoji to use as the icon for this message. Overrides `icon_url`. Must be used in conjunction with `as_user` set to `false`, otherwise ignored. See [authorship](#authorship) below.
* @var string $icon_url URL to an image to use as the icon for this message. Must be used in conjunction with `as_user` set to false, otherwise ignored. See [authorship](#authorship) below.
* @var bool $link_names find and link channel names and usernames
* @var string $metadata JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.
* @var bool $mrkdwn Disable Slack markup parsing by setting to `false`. Enabled by default.
* @var string $parse Change how messages are treated. Defaults to `none`. See [below](#formatting).
* @var bool $reply_broadcast Used in conjunction with `thread_ts` and indicates whether reply should be made visible to everyone in the channel or conversation. Defaults to `false`.
Expand Down Expand Up @@ -78,7 +79,7 @@ public function getAuthenticationScopes(): array
protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
{
$optionsResolver = parent::getFormOptionsResolver();
$optionsResolver->setDefined(['as_user', 'attachments', 'blocks', 'channel', 'icon_emoji', 'icon_url', 'link_names', 'mrkdwn', 'parse', 'reply_broadcast', 'text', 'thread_ts', 'unfurl_links', 'unfurl_media', 'username']);
$optionsResolver->setDefined(['as_user', 'attachments', 'blocks', 'channel', 'icon_emoji', 'icon_url', 'link_names', 'metadata', 'mrkdwn', 'parse', 'reply_broadcast', 'text', 'thread_ts', 'unfurl_links', 'unfurl_media', 'username']);
$optionsResolver->setRequired(['channel']);
$optionsResolver->setDefaults([]);
$optionsResolver->addAllowedTypes('as_user', ['bool']);
Expand All @@ -88,6 +89,7 @@ protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\
$optionsResolver->addAllowedTypes('icon_emoji', ['string']);
$optionsResolver->addAllowedTypes('icon_url', ['string']);
$optionsResolver->addAllowedTypes('link_names', ['bool']);
$optionsResolver->addAllowedTypes('metadata', ['string']);
$optionsResolver->addAllowedTypes('mrkdwn', ['bool']);
$optionsResolver->addAllowedTypes('parse', ['string']);
$optionsResolver->addAllowedTypes('reply_broadcast', ['bool']);
Expand Down
4 changes: 3 additions & 1 deletion generated/Endpoint/ConversationsHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ConversationsHistory extends \JoliCode\Slack\Api\Runtime\Client\BaseEndpoi
*
* @var string $channel conversation ID to fetch history for
* @var string $cursor Paginate through collections of data by setting the `cursor` parameter to a `next_cursor` attribute returned by a previous request's `response_metadata`. Default value fetches the first "page" of the collection. See [pagination](/docs/pagination) for more detail.
* @var bool $include_all_metadata return all metadata associated with this message
* @var bool $inclusive include messages with latest or oldest timestamp in results only when either timestamp is specified
* @var string $latest end of time range of messages to include in results
* @var int $limit The maximum number of items to return. Fewer than the requested number of items may be returned, even if the end of the users list hasn't been reached.
Expand Down Expand Up @@ -64,11 +65,12 @@ public function getAuthenticationScopes(): array
protected function getQueryOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
{
$optionsResolver = parent::getQueryOptionsResolver();
$optionsResolver->setDefined(['channel', 'cursor', 'inclusive', 'latest', 'limit', 'oldest', 'token']);
$optionsResolver->setDefined(['channel', 'cursor', 'include_all_metadata', 'inclusive', 'latest', 'limit', 'oldest', 'token']);
$optionsResolver->setRequired([]);
$optionsResolver->setDefaults([]);
$optionsResolver->addAllowedTypes('channel', ['string']);
$optionsResolver->addAllowedTypes('cursor', ['string']);
$optionsResolver->addAllowedTypes('include_all_metadata', ['bool']);
$optionsResolver->addAllowedTypes('inclusive', ['bool']);
$optionsResolver->addAllowedTypes('latest', ['string']);
$optionsResolver->addAllowedTypes('limit', ['int']);
Expand Down
17 changes: 17 additions & 0 deletions generated/Model/ObjsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class ObjsMessage
* @var string|null
*/
protected $latestReply;
/**
* @var ObjsMetadata|null
*/
protected $metadata;
/**
* @var string|null
*/
Expand Down Expand Up @@ -421,6 +425,19 @@ public function setLatestReply(?string $latestReply): self
return $this;
}

public function getMetadata(): ?ObjsMetadata
{
return $this->metadata;
}

public function setMetadata(?ObjsMetadata $metadata): self
{
$this->initialized['metadata'] = true;
$this->metadata = $metadata;

return $this;
}

public function getName(): ?string
{
return $this->name;
Expand Down
61 changes: 61 additions & 0 deletions generated/Model/ObjsMetadata.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/*
* This file is part of JoliCode's Slack PHP API project.
*
* (c) JoliCode <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace JoliCode\Slack\Api\Model;

class ObjsMetadata
{
/**
* @var array
*/
protected $initialized = [];
/**
* @var mixed|null
*/
protected $eventPayload;
/**
* @var string|null
*/
protected $eventType;

public function isInitialized($property): bool
{
return \array_key_exists($property, $this->initialized);
}

public function getEventPayload()
{
return $this->eventPayload;
}

public function setEventPayload($eventPayload): self
{
$this->initialized['eventPayload'] = true;
$this->eventPayload = $eventPayload;

return $this;
}

public function getEventType(): ?string
{
return $this->eventType;
}

public function setEventType(?string $eventType): self
{
$this->initialized['eventType'] = true;
$this->eventType = $eventType;

return $this;
}
}
4 changes: 2 additions & 2 deletions generated/Normalizer/JaneObjectNormalizer.php

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions generated/Normalizer/ObjsMessageNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public function denormalize($data, $class, $format = null, array $context = [])
} elseif (\array_key_exists('latest_reply', $data) && null === $data['latest_reply']) {
$object->setLatestReply(null);
}
if (\array_key_exists('metadata', $data) && null !== $data['metadata']) {
$object->setMetadata($this->denormalizer->denormalize($data['metadata'], 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata', 'json', $context));
} elseif (\array_key_exists('metadata', $data) && null === $data['metadata']) {
$object->setMetadata(null);
}
if (\array_key_exists('name', $data) && null !== $data['name']) {
$object->setName($data['name']);
} elseif (\array_key_exists('name', $data) && null === $data['name']) {
Expand Down Expand Up @@ -351,6 +356,9 @@ public function normalize($object, $format = null, array $context = [])
if ($object->isInitialized('latestReply') && null !== $object->getLatestReply()) {
$data['latest_reply'] = $object->getLatestReply();
}
if ($object->isInitialized('metadata') && null !== $object->getMetadata()) {
$data['metadata'] = $this->normalizer->normalize($object->getMetadata(), 'json', $context);
}
if ($object->isInitialized('name') && null !== $object->getName()) {
$data['name'] = $object->getName();
}
Expand Down
85 changes: 85 additions & 0 deletions generated/Normalizer/ObjsMetadataNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

declare(strict_types=1);

/*
* This file is part of JoliCode's Slack PHP API project.
*
* (c) JoliCode <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace JoliCode\Slack\Api\Normalizer;

use Jane\Component\JsonSchemaRuntime\Reference;
use JoliCode\Slack\Api\Runtime\Normalizer\CheckArray;
use JoliCode\Slack\Api\Runtime\Normalizer\ValidatorTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class ObjsMetadataNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
{
use CheckArray;
use DenormalizerAwareTrait;
use NormalizerAwareTrait;
use ValidatorTrait;

public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
{
return 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata' === $type;
}

public function supportsNormalization($data, $format = null, array $context = []): bool
{
return \is_object($data) && 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata' === \get_class($data);
}

public function denormalize($data, $class, $format = null, array $context = [])
{
if (isset($data['$ref'])) {
return new Reference($data['$ref'], $context['document-origin']);
}
if (isset($data['$recursiveRef'])) {
return new Reference($data['$recursiveRef'], $context['document-origin']);
}
$object = new \JoliCode\Slack\Api\Model\ObjsMetadata();
if (null === $data || false === \is_array($data)) {
return $object;
}
if (\array_key_exists('event_payload', $data) && null !== $data['event_payload']) {
$object->setEventPayload($data['event_payload']);
} elseif (\array_key_exists('event_payload', $data) && null === $data['event_payload']) {
$object->setEventPayload(null);
}
if (\array_key_exists('event_type', $data) && null !== $data['event_type']) {
$object->setEventType($data['event_type']);
} elseif (\array_key_exists('event_type', $data) && null === $data['event_type']) {
$object->setEventType(null);
}

return $object;
}

/**
* @return array|string|int|float|bool|\ArrayObject|null
*/
public function normalize($object, $format = null, array $context = [])
{
$data = [];
$data['event_payload'] = $object->getEventPayload();
$data['event_type'] = $object->getEventType();

return $data;
}

public function getSupportedTypes(string $format = null): array
{
return ['JoliCode\\Slack\\Api\\Model\\ObjsMetadata' => false];
}
}
34 changes: 33 additions & 1 deletion resources/slack-openapi-patched.json
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,9 @@
"latest_reply": {
"$ref": "#/definitions/defs_ts"
},
"metadata": {
"$ref": "#/definitions/objs_metadata"
},
"name": {
"type": "string"
},
Expand Down Expand Up @@ -1423,6 +1426,23 @@
"title": "Message object",
"type": "object"
},
"objs_metadata": {
"additionalProperties": false,
"properties": {
"event_payload": {
"type": "object"
},
"event_type": {
"type": "string"
}
},
"required": [
"event_payload",
"event_type"
],
"title": "Metadata object",
"type": "object"
},
"objs_paging": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -11637,6 +11657,12 @@
"name": "link_names",
"type": "boolean"
},
{
"description": "JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you post to Slack is accessible to any app or user who is a member of that workspace.",
"in": "formData",
"name": "metadata",
"type": "string"
},
{
"description": "Disable Slack markup parsing by setting to `false`. Enabled by default.",
"in": "formData",
Expand Down Expand Up @@ -13136,6 +13162,12 @@
"name": "cursor",
"type": "string"
},
{
"description": "Return all metadata associated with this message.",
"in": "query",
"name": "include_all_metadata",
"type": "boolean"
},
{
"description": "Include messages with latest or oldest timestamp in results only when either timestamp is specified.",
"in": "query",
Expand Down Expand Up @@ -26906,4 +26938,4 @@
},
"swagger": "2.0",
"tags": []
}
}
2 changes: 1 addition & 1 deletion resources/slack-openapi-sorted.json
Original file line number Diff line number Diff line change
Expand Up @@ -26892,4 +26892,4 @@
},
"swagger": "2.0",
"tags": []
}
}
Loading

0 comments on commit 9b923e4

Please sign in to comment.