Skip to content

Commit 81b7d88

Browse files
fwump38seratch
authored andcommitted
Fixed view_* methods to allow using View model
1 parent 01e06f8 commit 81b7d88

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

slack_sdk/web/async_client.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ async def views_open(
22722272
return await self.api_call("views.open", json=kwargs)
22732273

22742274
async def views_push(
2275-
self, *, trigger_id: str, view: dict, **kwargs
2275+
self, *, trigger_id: str, view: Union[dict, View], **kwargs
22762276
) -> AsyncSlackResponse:
22772277
"""Push a view onto the stack of a root view.
22782278
@@ -2286,13 +2286,17 @@ async def views_push(
22862286
Args:
22872287
trigger_id (str): Exchange a trigger to post to the user.
22882288
e.g. '12345.98765.abcd2358fdea'
2289-
view (dict): The view payload.
2289+
view (dict or View): The view payload.
22902290
"""
2291-
kwargs.update({"trigger_id": trigger_id, "view": view})
2291+
kwargs.update({"trigger_id": trigger_id})
2292+
if isinstance(view, View):
2293+
kwargs.update({"view": view.to_dict()})
2294+
else:
2295+
kwargs.update({"view": view})
22922296
return await self.api_call("views.push", json=kwargs)
22932297

22942298
async def views_update(
2295-
self, *, view: dict, external_id: str = None, view_id: str = None, **kwargs
2299+
self, *, view: Union[dict, View], external_id: str = None, view_id: str = None, **kwargs
22962300
) -> AsyncSlackResponse:
22972301
"""Update an existing view.
22982302
@@ -2303,15 +2307,18 @@ async def views_update(
23032307
to learn more about updating views and avoiding race conditions with the hash argument.
23042308
23052309
Args:
2306-
view (dict): The view payload.
2310+
view (dict or View): The view payload.
23072311
external_id (str): A unique identifier of the view set by the developer.
23082312
e.g. 'bmarley_view2'
23092313
view_id (str): A unique identifier of the view to be updated.
23102314
e.g. 'VMM512F2U'
23112315
Raises:
23122316
SlackRequestError: Either view_id or external_id is required.
23132317
"""
2314-
kwargs.update({"view": view})
2318+
if isinstance(view, View):
2319+
kwargs.update({"view": view.to_dict()})
2320+
else:
2321+
kwargs.update({"view": view})
23152322
if external_id:
23162323
kwargs.update({"external_id": external_id})
23172324
elif view_id:
@@ -2322,7 +2329,7 @@ async def views_update(
23222329
return await self.api_call("views.update", json=kwargs)
23232330

23242331
async def views_publish(
2325-
self, *, user_id: str, view: dict, **kwargs
2332+
self, *, user_id: str, view: Union[dict, View], **kwargs
23262333
) -> AsyncSlackResponse:
23272334
"""Publish a static view for a User.
23282335
Create or update the view that comprises an
@@ -2331,9 +2338,13 @@ async def views_publish(
23312338
Args:
23322339
user_id (str): id of the user you want publish a view to.
23332340
e.g. 'U0BPQUNTA'
2334-
view (dict): The view payload.
2341+
view (dict or View): The view payload.
23352342
"""
2336-
kwargs.update({"user_id": user_id, "view": view})
2343+
kwargs.update({"user_id": user_id})
2344+
if isinstance(view, View):
2345+
kwargs.update({"view": view.to_dict()})
2346+
else:
2347+
kwargs.update({"view": view})
23372348
return await self.api_call("views.publish", json=kwargs)
23382349

23392350
async def workflows_stepCompleted(

slack_sdk/web/client.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ def views_open(
21382138
kwargs.update({"view": view})
21392139
return self.api_call("views.open", json=kwargs)
21402140

2141-
def views_push(self, *, trigger_id: str, view: dict, **kwargs) -> SlackResponse:
2141+
def views_push(self, *, trigger_id: str, view: Union[dict, View], **kwargs) -> SlackResponse:
21422142
"""Push a view onto the stack of a root view.
21432143
21442144
Push a new view onto the existing view stack by passing a view
@@ -2151,13 +2151,17 @@ def views_push(self, *, trigger_id: str, view: dict, **kwargs) -> SlackResponse:
21512151
Args:
21522152
trigger_id (str): Exchange a trigger to post to the user.
21532153
e.g. '12345.98765.abcd2358fdea'
2154-
view (dict): The view payload.
2154+
view (dict or View): The view payload.
21552155
"""
21562156
kwargs.update({"trigger_id": trigger_id, "view": view})
2157+
if isinstance(view, View):
2158+
kwargs.update({"view": view.to_dict()})
2159+
else:
2160+
kwargs.update({"view": view})
21572161
return self.api_call("views.push", json=kwargs)
21582162

21592163
def views_update(
2160-
self, *, view: dict, external_id: str = None, view_id: str = None, **kwargs
2164+
self, *, view: Union[dict, View], external_id: str = None, view_id: str = None, **kwargs
21612165
) -> SlackResponse:
21622166
"""Update an existing view.
21632167
@@ -2168,15 +2172,18 @@ def views_update(
21682172
to learn more about updating views and avoiding race conditions with the hash argument.
21692173
21702174
Args:
2171-
view (dict): The view payload.
2175+
view (dict or View): The view payload.
21722176
external_id (str): A unique identifier of the view set by the developer.
21732177
e.g. 'bmarley_view2'
21742178
view_id (str): A unique identifier of the view to be updated.
21752179
e.g. 'VMM512F2U'
21762180
Raises:
21772181
SlackRequestError: Either view_id or external_id is required.
21782182
"""
2179-
kwargs.update({"view": view})
2183+
if isinstance(view, View):
2184+
kwargs.update({"view": view.to_dict()})
2185+
else:
2186+
kwargs.update({"view": view})
21802187
if external_id:
21812188
kwargs.update({"external_id": external_id})
21822189
elif view_id:
@@ -2186,17 +2193,21 @@ def views_update(
21862193

21872194
return self.api_call("views.update", json=kwargs)
21882195

2189-
def views_publish(self, *, user_id: str, view: dict, **kwargs) -> SlackResponse:
2196+
def views_publish(self, *, user_id: str, view: Union[dict, View], **kwargs) -> SlackResponse:
21902197
"""Publish a static view for a User.
21912198
Create or update the view that comprises an
21922199
app's Home tab (https://api.slack.com/surfaces/tabs)
21932200
for a specific user.
21942201
Args:
21952202
user_id (str): id of the user you want publish a view to.
21962203
e.g. 'U0BPQUNTA'
2197-
view (dict): The view payload.
2204+
view (dict or View): The view payload.
21982205
"""
2199-
kwargs.update({"user_id": user_id, "view": view})
2206+
kwargs.update({"user_id": user_id})
2207+
if isinstance(view, View):
2208+
kwargs.update({"view": view.to_dict()})
2209+
else:
2210+
kwargs.update({"view": view})
22002211
return self.api_call("views.publish", json=kwargs)
22012212

22022213
def workflows_stepCompleted(

0 commit comments

Comments
 (0)