Skip to content

Commit 9b923e4

Browse files
authored
fix(chat): Added metadata definition for chat.postMessage and history (#156)
1 parent 99ed82c commit 9b923e4

12 files changed

+479
-165
lines changed

generated/Client.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,7 @@ public function chatPostEphemeral(array $formParameters = [], array $headerParam
17821782
* @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.
17831783
* @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.
17841784
* @var bool $link_names find and link channel names and usernames
1785+
* @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.
17851786
* @var bool $mrkdwn Disable Slack markup parsing by setting to `false`. Enabled by default.
17861787
* @var string $parse Change how messages are treated. Defaults to `none`. See [below](#formatting).
17871788
* @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`.
@@ -1995,6 +1996,7 @@ public function conversationsCreate(array $formParameters = [], array $headerPar
19951996
*
19961997
* @var string $channel conversation ID to fetch history for
19971998
* @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.
1999+
* @var bool $include_all_metadata return all metadata associated with this message
19982000
* @var bool $inclusive include messages with latest or oldest timestamp in results only when either timestamp is specified
19992001
* @var string $latest end of time range of messages to include in results
20002002
* @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.

generated/Endpoint/ChatPostMessage.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ChatPostMessage extends \JoliCode\Slack\Api\Runtime\Client\BaseEndpoint im
2929
* @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.
3030
* @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.
3131
* @var bool $link_names find and link channel names and usernames
32+
* @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.
3233
* @var bool $mrkdwn Disable Slack markup parsing by setting to `false`. Enabled by default.
3334
* @var string $parse Change how messages are treated. Defaults to `none`. See [below](#formatting).
3435
* @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`.
@@ -78,7 +79,7 @@ public function getAuthenticationScopes(): array
7879
protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
7980
{
8081
$optionsResolver = parent::getFormOptionsResolver();
81-
$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']);
82+
$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']);
8283
$optionsResolver->setRequired(['channel']);
8384
$optionsResolver->setDefaults([]);
8485
$optionsResolver->addAllowedTypes('as_user', ['bool']);
@@ -88,6 +89,7 @@ protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\
8889
$optionsResolver->addAllowedTypes('icon_emoji', ['string']);
8990
$optionsResolver->addAllowedTypes('icon_url', ['string']);
9091
$optionsResolver->addAllowedTypes('link_names', ['bool']);
92+
$optionsResolver->addAllowedTypes('metadata', ['string']);
9193
$optionsResolver->addAllowedTypes('mrkdwn', ['bool']);
9294
$optionsResolver->addAllowedTypes('parse', ['string']);
9395
$optionsResolver->addAllowedTypes('reply_broadcast', ['bool']);

generated/Endpoint/ConversationsHistory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ConversationsHistory extends \JoliCode\Slack\Api\Runtime\Client\BaseEndpoi
2424
*
2525
* @var string $channel conversation ID to fetch history for
2626
* @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.
27+
* @var bool $include_all_metadata return all metadata associated with this message
2728
* @var bool $inclusive include messages with latest or oldest timestamp in results only when either timestamp is specified
2829
* @var string $latest end of time range of messages to include in results
2930
* @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.
@@ -64,11 +65,12 @@ public function getAuthenticationScopes(): array
6465
protected function getQueryOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
6566
{
6667
$optionsResolver = parent::getQueryOptionsResolver();
67-
$optionsResolver->setDefined(['channel', 'cursor', 'inclusive', 'latest', 'limit', 'oldest', 'token']);
68+
$optionsResolver->setDefined(['channel', 'cursor', 'include_all_metadata', 'inclusive', 'latest', 'limit', 'oldest', 'token']);
6869
$optionsResolver->setRequired([]);
6970
$optionsResolver->setDefaults([]);
7071
$optionsResolver->addAllowedTypes('channel', ['string']);
7172
$optionsResolver->addAllowedTypes('cursor', ['string']);
73+
$optionsResolver->addAllowedTypes('include_all_metadata', ['bool']);
7274
$optionsResolver->addAllowedTypes('inclusive', ['bool']);
7375
$optionsResolver->addAllowedTypes('latest', ['string']);
7476
$optionsResolver->addAllowedTypes('limit', ['int']);

generated/Model/ObjsMessage.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class ObjsMessage
8585
* @var string|null
8686
*/
8787
protected $latestReply;
88+
/**
89+
* @var ObjsMetadata|null
90+
*/
91+
protected $metadata;
8892
/**
8993
* @var string|null
9094
*/
@@ -421,6 +425,19 @@ public function setLatestReply(?string $latestReply): self
421425
return $this;
422426
}
423427

428+
public function getMetadata(): ?ObjsMetadata
429+
{
430+
return $this->metadata;
431+
}
432+
433+
public function setMetadata(?ObjsMetadata $metadata): self
434+
{
435+
$this->initialized['metadata'] = true;
436+
$this->metadata = $metadata;
437+
438+
return $this;
439+
}
440+
424441
public function getName(): ?string
425442
{
426443
return $this->name;

generated/Model/ObjsMetadata.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of JoliCode's Slack PHP API project.
7+
*
8+
* (c) JoliCode <coucou@jolicode.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace JoliCode\Slack\Api\Model;
15+
16+
class ObjsMetadata
17+
{
18+
/**
19+
* @var array
20+
*/
21+
protected $initialized = [];
22+
/**
23+
* @var mixed|null
24+
*/
25+
protected $eventPayload;
26+
/**
27+
* @var string|null
28+
*/
29+
protected $eventType;
30+
31+
public function isInitialized($property): bool
32+
{
33+
return \array_key_exists($property, $this->initialized);
34+
}
35+
36+
public function getEventPayload()
37+
{
38+
return $this->eventPayload;
39+
}
40+
41+
public function setEventPayload($eventPayload): self
42+
{
43+
$this->initialized['eventPayload'] = true;
44+
$this->eventPayload = $eventPayload;
45+
46+
return $this;
47+
}
48+
49+
public function getEventType(): ?string
50+
{
51+
return $this->eventType;
52+
}
53+
54+
public function setEventType(?string $eventType): self
55+
{
56+
$this->initialized['eventType'] = true;
57+
$this->eventType = $eventType;
58+
59+
return $this;
60+
}
61+
}

generated/Normalizer/JaneObjectNormalizer.php

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

generated/Normalizer/ObjsMessageNormalizer.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ public function denormalize($data, $class, $format = null, array $context = [])
144144
} elseif (\array_key_exists('latest_reply', $data) && null === $data['latest_reply']) {
145145
$object->setLatestReply(null);
146146
}
147+
if (\array_key_exists('metadata', $data) && null !== $data['metadata']) {
148+
$object->setMetadata($this->denormalizer->denormalize($data['metadata'], 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata', 'json', $context));
149+
} elseif (\array_key_exists('metadata', $data) && null === $data['metadata']) {
150+
$object->setMetadata(null);
151+
}
147152
if (\array_key_exists('name', $data) && null !== $data['name']) {
148153
$object->setName($data['name']);
149154
} elseif (\array_key_exists('name', $data) && null === $data['name']) {
@@ -351,6 +356,9 @@ public function normalize($object, $format = null, array $context = [])
351356
if ($object->isInitialized('latestReply') && null !== $object->getLatestReply()) {
352357
$data['latest_reply'] = $object->getLatestReply();
353358
}
359+
if ($object->isInitialized('metadata') && null !== $object->getMetadata()) {
360+
$data['metadata'] = $this->normalizer->normalize($object->getMetadata(), 'json', $context);
361+
}
354362
if ($object->isInitialized('name') && null !== $object->getName()) {
355363
$data['name'] = $object->getName();
356364
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of JoliCode's Slack PHP API project.
7+
*
8+
* (c) JoliCode <coucou@jolicode.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace JoliCode\Slack\Api\Normalizer;
15+
16+
use Jane\Component\JsonSchemaRuntime\Reference;
17+
use JoliCode\Slack\Api\Runtime\Normalizer\CheckArray;
18+
use JoliCode\Slack\Api\Runtime\Normalizer\ValidatorTrait;
19+
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
20+
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
21+
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
22+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
23+
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
24+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
25+
26+
class ObjsMetadataNormalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
27+
{
28+
use CheckArray;
29+
use DenormalizerAwareTrait;
30+
use NormalizerAwareTrait;
31+
use ValidatorTrait;
32+
33+
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
34+
{
35+
return 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata' === $type;
36+
}
37+
38+
public function supportsNormalization($data, $format = null, array $context = []): bool
39+
{
40+
return \is_object($data) && 'JoliCode\\Slack\\Api\\Model\\ObjsMetadata' === \get_class($data);
41+
}
42+
43+
public function denormalize($data, $class, $format = null, array $context = [])
44+
{
45+
if (isset($data['$ref'])) {
46+
return new Reference($data['$ref'], $context['document-origin']);
47+
}
48+
if (isset($data['$recursiveRef'])) {
49+
return new Reference($data['$recursiveRef'], $context['document-origin']);
50+
}
51+
$object = new \JoliCode\Slack\Api\Model\ObjsMetadata();
52+
if (null === $data || false === \is_array($data)) {
53+
return $object;
54+
}
55+
if (\array_key_exists('event_payload', $data) && null !== $data['event_payload']) {
56+
$object->setEventPayload($data['event_payload']);
57+
} elseif (\array_key_exists('event_payload', $data) && null === $data['event_payload']) {
58+
$object->setEventPayload(null);
59+
}
60+
if (\array_key_exists('event_type', $data) && null !== $data['event_type']) {
61+
$object->setEventType($data['event_type']);
62+
} elseif (\array_key_exists('event_type', $data) && null === $data['event_type']) {
63+
$object->setEventType(null);
64+
}
65+
66+
return $object;
67+
}
68+
69+
/**
70+
* @return array|string|int|float|bool|\ArrayObject|null
71+
*/
72+
public function normalize($object, $format = null, array $context = [])
73+
{
74+
$data = [];
75+
$data['event_payload'] = $object->getEventPayload();
76+
$data['event_type'] = $object->getEventType();
77+
78+
return $data;
79+
}
80+
81+
public function getSupportedTypes(string $format = null): array
82+
{
83+
return ['JoliCode\\Slack\\Api\\Model\\ObjsMetadata' => false];
84+
}
85+
}

resources/slack-openapi-patched.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,9 @@
13271327
"latest_reply": {
13281328
"$ref": "#/definitions/defs_ts"
13291329
},
1330+
"metadata": {
1331+
"$ref": "#/definitions/objs_metadata"
1332+
},
13301333
"name": {
13311334
"type": "string"
13321335
},
@@ -1423,6 +1426,23 @@
14231426
"title": "Message object",
14241427
"type": "object"
14251428
},
1429+
"objs_metadata": {
1430+
"additionalProperties": false,
1431+
"properties": {
1432+
"event_payload": {
1433+
"type": "object"
1434+
},
1435+
"event_type": {
1436+
"type": "string"
1437+
}
1438+
},
1439+
"required": [
1440+
"event_payload",
1441+
"event_type"
1442+
],
1443+
"title": "Metadata object",
1444+
"type": "object"
1445+
},
14261446
"objs_paging": {
14271447
"additionalProperties": false,
14281448
"properties": {
@@ -11637,6 +11657,12 @@
1163711657
"name": "link_names",
1163811658
"type": "boolean"
1163911659
},
11660+
{
11661+
"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.",
11662+
"in": "formData",
11663+
"name": "metadata",
11664+
"type": "string"
11665+
},
1164011666
{
1164111667
"description": "Disable Slack markup parsing by setting to `false`. Enabled by default.",
1164211668
"in": "formData",
@@ -13136,6 +13162,12 @@
1313613162
"name": "cursor",
1313713163
"type": "string"
1313813164
},
13165+
{
13166+
"description": "Return all metadata associated with this message.",
13167+
"in": "query",
13168+
"name": "include_all_metadata",
13169+
"type": "boolean"
13170+
},
1313913171
{
1314013172
"description": "Include messages with latest or oldest timestamp in results only when either timestamp is specified.",
1314113173
"in": "query",
@@ -26906,4 +26938,4 @@
2690626938
},
2690726939
"swagger": "2.0",
2690826940
"tags": []
26909-
}
26941+
}

resources/slack-openapi-sorted.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26892,4 +26892,4 @@
2689226892
},
2689326893
"swagger": "2.0",
2689426894
"tags": []
26895-
}
26895+
}

0 commit comments

Comments
 (0)