1 | <?php
|
---|
2 | /*
|
---|
3 | * Copyright 2014 Google Inc.
|
---|
4 | *
|
---|
5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
---|
6 | * use this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at
|
---|
8 | *
|
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
10 | *
|
---|
11 | * Unless required by applicable law or agreed to in writing, software
|
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
---|
13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
---|
14 | * License for the specific language governing permissions and limitations under
|
---|
15 | * the License.
|
---|
16 | */
|
---|
17 |
|
---|
18 | namespace Google\Service\HangoutsChat\Resource;
|
---|
19 |
|
---|
20 | use Google\Service\HangoutsChat\ChatEmpty;
|
---|
21 | use Google\Service\HangoutsChat\ListMessagesResponse;
|
---|
22 | use Google\Service\HangoutsChat\Message;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * The "messages" collection of methods.
|
---|
26 | * Typical usage is:
|
---|
27 | * <code>
|
---|
28 | * $chatService = new Google\Service\HangoutsChat(...);
|
---|
29 | * $messages = $chatService->spaces_messages;
|
---|
30 | * </code>
|
---|
31 | */
|
---|
32 | class SpacesMessages extends \Google\Service\Resource
|
---|
33 | {
|
---|
34 | /**
|
---|
35 | * Creates a message in a Google Chat space. For an example, see [Send a
|
---|
36 | * message](https://developers.google.com/workspace/chat/create-messages). The
|
---|
37 | * `create()` method requires either [user
|
---|
38 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
39 | * authorize-chat-user) or [app
|
---|
40 | * authentication](https://developers.google.com/workspace/chat/authorize-
|
---|
41 | * import). Chat attributes the message sender differently depending on the type
|
---|
42 | * of authentication that you use in your request. The following image shows how
|
---|
43 | * Chat attributes a message when you use app authentication. Chat displays the
|
---|
44 | * Chat app as the message sender. The content of the message can contain text
|
---|
45 | * (`text`), cards (`cardsV2`), and accessory widgets (`accessoryWidgets`).
|
---|
46 | * ![Message sent with app
|
---|
47 | * authentication](https://developers.google.com/workspace/chat/images/message-
|
---|
48 | * app-auth.svg) The following image shows how Chat attributes a message when
|
---|
49 | * you use user authentication. Chat displays the user as the message sender and
|
---|
50 | * attributes the Chat app to the message by displaying its name. The content of
|
---|
51 | * message can only contain text (`text`). ![Message sent with user
|
---|
52 | * authentication](https://developers.google.com/workspace/chat/images/message-
|
---|
53 | * user-auth.svg) The maximum message size, including the message contents, is
|
---|
54 | * 32,000 bytes. For
|
---|
55 | * [webhook](https://developers.google.com/workspace/chat/quickstart/webhooks)
|
---|
56 | * requests, the response doesn't contain the full message. The response only
|
---|
57 | * populates the `name` and `thread.name` fields in addition to the information
|
---|
58 | * that was in the request. (messages.create)
|
---|
59 | *
|
---|
60 | * @param string $parent Required. The resource name of the space in which to
|
---|
61 | * create a message. Format: `spaces/{space}`
|
---|
62 | * @param Message $postBody
|
---|
63 | * @param array $optParams Optional parameters.
|
---|
64 | *
|
---|
65 | * @opt_param string messageId Optional. A custom ID for a message. Lets Chat
|
---|
66 | * apps get, update, or delete a message without needing to store the system-
|
---|
67 | * assigned ID in the message's resource name (represented in the message `name`
|
---|
68 | * field). The value for this field must meet the following requirements: *
|
---|
69 | * Begins with `client-`. For example, `client-custom-name` is a valid custom
|
---|
70 | * ID, but `custom-name` is not. * Contains up to 63 characters and only
|
---|
71 | * lowercase letters, numbers, and hyphens. * Is unique within a space. A Chat
|
---|
72 | * app can't use the same custom ID for different messages. For details, see
|
---|
73 | * [Name a message](https://developers.google.com/workspace/chat/create-
|
---|
74 | * messages#name_a_created_message).
|
---|
75 | * @opt_param string messageReplyOption Optional. Specifies whether a message
|
---|
76 | * starts a thread or replies to one. Only supported in named spaces. When
|
---|
77 | * [responding to user
|
---|
78 | * interactions](https://developers.google.com/workspace/chat/receive-respond-
|
---|
79 | * interactions), this field is ignored. For interactions within a thread, the
|
---|
80 | * reply is created in the same thread. Otherwise, the reply is created as a new
|
---|
81 | * thread.
|
---|
82 | * @opt_param string requestId Optional. A unique request ID for this message.
|
---|
83 | * Specifying an existing request ID returns the message created with that ID
|
---|
84 | * instead of creating a new message.
|
---|
85 | * @opt_param string threadKey Optional. Deprecated: Use thread.thread_key
|
---|
86 | * instead. ID for the thread. Supports up to 4000 characters. To start or add
|
---|
87 | * to a thread, create a message and specify a `threadKey` or the thread.name.
|
---|
88 | * For example usage, see [Start or reply to a message
|
---|
89 | * thread](https://developers.google.com/workspace/chat/create-messages#create-
|
---|
90 | * message-thread).
|
---|
91 | * @return Message
|
---|
92 | * @throws \Google\Service\Exception
|
---|
93 | */
|
---|
94 | public function create($parent, Message $postBody, $optParams = [])
|
---|
95 | {
|
---|
96 | $params = ['parent' => $parent, 'postBody' => $postBody];
|
---|
97 | $params = array_merge($params, $optParams);
|
---|
98 | return $this->call('create', [$params], Message::class);
|
---|
99 | }
|
---|
100 | /**
|
---|
101 | * Deletes a message. For an example, see [Delete a
|
---|
102 | * message](https://developers.google.com/workspace/chat/delete-messages).
|
---|
103 | * Supports the following types of
|
---|
104 | * [authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
105 | * authorize): - [App
|
---|
106 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
107 | * authorize-chat-app) - [User
|
---|
108 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
109 | * authorize-chat-user) When using app authentication, requests can only delete
|
---|
110 | * messages created by the calling Chat app. (messages.delete)
|
---|
111 | *
|
---|
112 | * @param string $name Required. Resource name of the message. Format:
|
---|
113 | * `spaces/{space}/messages/{message}` If you've set a custom ID for your
|
---|
114 | * message, you can use the value from the `clientAssignedMessageId` field for
|
---|
115 | * `{message}`. For details, see [Name a message]
|
---|
116 | * (https://developers.google.com/workspace/chat/create-
|
---|
117 | * messages#name_a_created_message).
|
---|
118 | * @param array $optParams Optional parameters.
|
---|
119 | *
|
---|
120 | * @opt_param bool force Optional. When `true`, deleting a message also deletes
|
---|
121 | * its threaded replies. When `false`, if a message has threaded replies,
|
---|
122 | * deletion fails. Only applies when [authenticating as a
|
---|
123 | * user](https://developers.google.com/workspace/chat/authenticate-authorize-
|
---|
124 | * chat-user). Has no effect when [authenticating as a Chat app]
|
---|
125 | * (https://developers.google.com/workspace/chat/authenticate-authorize-chat-
|
---|
126 | * app).
|
---|
127 | * @return ChatEmpty
|
---|
128 | * @throws \Google\Service\Exception
|
---|
129 | */
|
---|
130 | public function delete($name, $optParams = [])
|
---|
131 | {
|
---|
132 | $params = ['name' => $name];
|
---|
133 | $params = array_merge($params, $optParams);
|
---|
134 | return $this->call('delete', [$params], ChatEmpty::class);
|
---|
135 | }
|
---|
136 | /**
|
---|
137 | * Returns details about a message. For an example, see [Get details about a
|
---|
138 | * message](https://developers.google.com/workspace/chat/get-messages). Supports
|
---|
139 | * the following types of
|
---|
140 | * [authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
141 | * authorize): - [App
|
---|
142 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
143 | * authorize-chat-app) - [User
|
---|
144 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
145 | * authorize-chat-user) Note: Might return a message from a blocked member or
|
---|
146 | * space. (messages.get)
|
---|
147 | *
|
---|
148 | * @param string $name Required. Resource name of the message. Format:
|
---|
149 | * `spaces/{space}/messages/{message}` If you've set a custom ID for your
|
---|
150 | * message, you can use the value from the `clientAssignedMessageId` field for
|
---|
151 | * `{message}`. For details, see [Name a message]
|
---|
152 | * (https://developers.google.com/workspace/chat/create-
|
---|
153 | * messages#name_a_created_message).
|
---|
154 | * @param array $optParams Optional parameters.
|
---|
155 | * @return Message
|
---|
156 | * @throws \Google\Service\Exception
|
---|
157 | */
|
---|
158 | public function get($name, $optParams = [])
|
---|
159 | {
|
---|
160 | $params = ['name' => $name];
|
---|
161 | $params = array_merge($params, $optParams);
|
---|
162 | return $this->call('get', [$params], Message::class);
|
---|
163 | }
|
---|
164 | /**
|
---|
165 | * Lists messages in a space that the caller is a member of, including messages
|
---|
166 | * from blocked members and spaces. If you list messages from a space with no
|
---|
167 | * messages, the response is an empty object. When using a REST/HTTP interface,
|
---|
168 | * the response contains an empty JSON object, `{}`. For an example, see [List m
|
---|
169 | * essages](https://developers.google.com/workspace/chat/api/guides/v1/messages/
|
---|
170 | * list). Requires [user
|
---|
171 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
172 | * authorize-chat-user). (messages.listSpacesMessages)
|
---|
173 | *
|
---|
174 | * @param string $parent Required. The resource name of the space to list
|
---|
175 | * messages from. Format: `spaces/{space}`
|
---|
176 | * @param array $optParams Optional parameters.
|
---|
177 | *
|
---|
178 | * @opt_param string filter Optional. A query filter. You can filter messages by
|
---|
179 | * date (`create_time`) and thread (`thread.name`). To filter messages by the
|
---|
180 | * date they were created, specify the `create_time` with a timestamp in
|
---|
181 | * [RFC-3339](https://www.rfc-editor.org/rfc/rfc3339) format and double
|
---|
182 | * quotation marks. For example, `"2023-04-21T11:30:00-04:00"`. You can use the
|
---|
183 | * greater than operator `>` to list messages that were created after a
|
---|
184 | * timestamp, or the less than operator `<` to list messages that were created
|
---|
185 | * before a timestamp. To filter messages within a time interval, use the `AND`
|
---|
186 | * operator between two timestamps. To filter by thread, specify the
|
---|
187 | * `thread.name`, formatted as `spaces/{space}/threads/{thread}`. You can only
|
---|
188 | * specify one `thread.name` per query. To filter by both thread and date, use
|
---|
189 | * the `AND` operator in your query. For example, the following queries are
|
---|
190 | * valid: ``` create_time > "2012-04-21T11:30:00-04:00" create_time >
|
---|
191 | * "2012-04-21T11:30:00-04:00" AND thread.name = spaces/AAAAAAAAAAA/threads/123
|
---|
192 | * create_time > "2012-04-21T11:30:00+00:00" AND create_time <
|
---|
193 | * "2013-01-01T00:00:00+00:00" AND thread.name = spaces/AAAAAAAAAAA/threads/123
|
---|
194 | * thread.name = spaces/AAAAAAAAAAA/threads/123 ``` Invalid queries are rejected
|
---|
195 | * by the server with an `INVALID_ARGUMENT` error.
|
---|
196 | * @opt_param string orderBy Optional. How the list of messages is ordered.
|
---|
197 | * Specify a value to order by an ordering operation. Valid ordering operation
|
---|
198 | * values are as follows: - `ASC` for ascending. - `DESC` for descending. The
|
---|
199 | * default ordering is `create_time ASC`.
|
---|
200 | * @opt_param int pageSize Optional. The maximum number of messages returned.
|
---|
201 | * The service might return fewer messages than this value. If unspecified, at
|
---|
202 | * most 25 are returned. The maximum value is 1000. If you use a value more than
|
---|
203 | * 1000, it's automatically changed to 1000. Negative values return an
|
---|
204 | * `INVALID_ARGUMENT` error.
|
---|
205 | * @opt_param string pageToken Optional. A page token received from a previous
|
---|
206 | * list messages call. Provide this parameter to retrieve the subsequent page.
|
---|
207 | * When paginating, all other parameters provided should match the call that
|
---|
208 | * provided the page token. Passing different values to the other parameters
|
---|
209 | * might lead to unexpected results.
|
---|
210 | * @opt_param bool showDeleted Optional. Whether to include deleted messages.
|
---|
211 | * Deleted messages include deleted time and metadata about their deletion, but
|
---|
212 | * message content is unavailable.
|
---|
213 | * @return ListMessagesResponse
|
---|
214 | * @throws \Google\Service\Exception
|
---|
215 | */
|
---|
216 | public function listSpacesMessages($parent, $optParams = [])
|
---|
217 | {
|
---|
218 | $params = ['parent' => $parent];
|
---|
219 | $params = array_merge($params, $optParams);
|
---|
220 | return $this->call('list', [$params], ListMessagesResponse::class);
|
---|
221 | }
|
---|
222 | /**
|
---|
223 | * Updates a message. There's a difference between the `patch` and `update`
|
---|
224 | * methods. The `patch` method uses a `patch` request while the `update` method
|
---|
225 | * uses a `put` request. We recommend using the `patch` method. For an example,
|
---|
226 | * see [Update a message](https://developers.google.com/workspace/chat/update-
|
---|
227 | * messages). Supports the following types of
|
---|
228 | * [authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
229 | * authorize): - [App
|
---|
230 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
231 | * authorize-chat-app) - [User
|
---|
232 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
233 | * authorize-chat-user) When using app authentication, requests can only update
|
---|
234 | * messages created by the calling Chat app. (messages.patch)
|
---|
235 | *
|
---|
236 | * @param string $name Identifier. Resource name of the message. Format:
|
---|
237 | * `spaces/{space}/messages/{message}` Where `{space}` is the ID of the space
|
---|
238 | * where the message is posted and `{message}` is a system-assigned ID for the
|
---|
239 | * message. For example, `spaces/AAAAAAAAAAA/messages/BBBBBBBBBBB.BBBBBBBBBBB`.
|
---|
240 | * If you set a custom ID when you create a message, you can use this ID to
|
---|
241 | * specify the message in a request by replacing `{message}` with the value from
|
---|
242 | * the `clientAssignedMessageId` field. For example,
|
---|
243 | * `spaces/AAAAAAAAAAA/messages/client-custom-name`. For details, see [Name a
|
---|
244 | * message](https://developers.google.com/workspace/chat/create-
|
---|
245 | * messages#name_a_created_message).
|
---|
246 | * @param Message $postBody
|
---|
247 | * @param array $optParams Optional parameters.
|
---|
248 | *
|
---|
249 | * @opt_param bool allowMissing Optional. If `true` and the message isn't found,
|
---|
250 | * a new message is created and `updateMask` is ignored. The specified message
|
---|
251 | * ID must be [client-
|
---|
252 | * assigned](https://developers.google.com/workspace/chat/create-
|
---|
253 | * messages#name_a_created_message) or the request fails.
|
---|
254 | * @opt_param string updateMask Required. The field paths to update. Separate
|
---|
255 | * multiple values with commas or use `*` to update all field paths. Currently
|
---|
256 | * supported field paths: - `text` - `attachment` - `cards` (Requires [app
|
---|
257 | * authentication](/chat/api/guides/auth/service-accounts).) - `cards_v2`
|
---|
258 | * (Requires [app authentication](/chat/api/guides/auth/service-accounts).) -
|
---|
259 | * `accessory_widgets` (Requires [app
|
---|
260 | * authentication](/chat/api/guides/auth/service-accounts).)
|
---|
261 | * @return Message
|
---|
262 | * @throws \Google\Service\Exception
|
---|
263 | */
|
---|
264 | public function patch($name, Message $postBody, $optParams = [])
|
---|
265 | {
|
---|
266 | $params = ['name' => $name, 'postBody' => $postBody];
|
---|
267 | $params = array_merge($params, $optParams);
|
---|
268 | return $this->call('patch', [$params], Message::class);
|
---|
269 | }
|
---|
270 | /**
|
---|
271 | * Updates a message. There's a difference between the `patch` and `update`
|
---|
272 | * methods. The `patch` method uses a `patch` request while the `update` method
|
---|
273 | * uses a `put` request. We recommend using the `patch` method. For an example,
|
---|
274 | * see [Update a message](https://developers.google.com/workspace/chat/update-
|
---|
275 | * messages). Supports the following types of
|
---|
276 | * [authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
277 | * authorize): - [App
|
---|
278 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
279 | * authorize-chat-app) - [User
|
---|
280 | * authentication](https://developers.google.com/workspace/chat/authenticate-
|
---|
281 | * authorize-chat-user) When using app authentication, requests can only update
|
---|
282 | * messages created by the calling Chat app. (messages.update)
|
---|
283 | *
|
---|
284 | * @param string $name Identifier. Resource name of the message. Format:
|
---|
285 | * `spaces/{space}/messages/{message}` Where `{space}` is the ID of the space
|
---|
286 | * where the message is posted and `{message}` is a system-assigned ID for the
|
---|
287 | * message. For example, `spaces/AAAAAAAAAAA/messages/BBBBBBBBBBB.BBBBBBBBBBB`.
|
---|
288 | * If you set a custom ID when you create a message, you can use this ID to
|
---|
289 | * specify the message in a request by replacing `{message}` with the value from
|
---|
290 | * the `clientAssignedMessageId` field. For example,
|
---|
291 | * `spaces/AAAAAAAAAAA/messages/client-custom-name`. For details, see [Name a
|
---|
292 | * message](https://developers.google.com/workspace/chat/create-
|
---|
293 | * messages#name_a_created_message).
|
---|
294 | * @param Message $postBody
|
---|
295 | * @param array $optParams Optional parameters.
|
---|
296 | *
|
---|
297 | * @opt_param bool allowMissing Optional. If `true` and the message isn't found,
|
---|
298 | * a new message is created and `updateMask` is ignored. The specified message
|
---|
299 | * ID must be [client-
|
---|
300 | * assigned](https://developers.google.com/workspace/chat/create-
|
---|
301 | * messages#name_a_created_message) or the request fails.
|
---|
302 | * @opt_param string updateMask Required. The field paths to update. Separate
|
---|
303 | * multiple values with commas or use `*` to update all field paths. Currently
|
---|
304 | * supported field paths: - `text` - `attachment` - `cards` (Requires [app
|
---|
305 | * authentication](/chat/api/guides/auth/service-accounts).) - `cards_v2`
|
---|
306 | * (Requires [app authentication](/chat/api/guides/auth/service-accounts).) -
|
---|
307 | * `accessory_widgets` (Requires [app
|
---|
308 | * authentication](/chat/api/guides/auth/service-accounts).)
|
---|
309 | * @return Message
|
---|
310 | * @throws \Google\Service\Exception
|
---|
311 | */
|
---|
312 | public function update($name, Message $postBody, $optParams = [])
|
---|
313 | {
|
---|
314 | $params = ['name' => $name, 'postBody' => $postBody];
|
---|
315 | $params = array_merge($params, $optParams);
|
---|
316 | return $this->call('update', [$params], Message::class);
|
---|
317 | }
|
---|
318 | }
|
---|
319 |
|
---|
320 | // Adding a class alias for backwards compatibility with the previous class name.
|
---|
321 | class_alias(SpacesMessages::class, 'Google_Service_HangoutsChat_Resource_SpacesMessages');
|
---|