aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_api.py
diff options
context:
space:
mode:
authorPierguido Lambri <plambri@redhat.com>2024-01-13 18:35:36 +0000
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 12:55:39 +0100
commit3b6bc38b53ca9ea81c8a055c78b9d93f0d75768b (patch)
treeaed4439a3491bca17c18174c1f5e5b2c1b639552 /slack/slack_api.py
parent0531090db0976b1261a033dd2eabd4c641a91d2c (diff)
downloadwee-slack-3b6bc38b53ca9ea81c8a055c78b9d93f0d75768b.tar.gz
Set user status
It's now possible to set and clear the uses status. For now it's not possible to set the status emoji or the status expiration. Signed-off-by: Pierguido Lambri <plambri@redhat.com>
Diffstat (limited to 'slack/slack_api.py')
-rw-r--r--slack/slack_api.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/slack/slack_api.py b/slack/slack_api.py
index e71860b..83e8962 100644
--- a/slack/slack_api.py
+++ b/slack/slack_api.py
@@ -2,7 +2,14 @@ from __future__ import annotations
import json
from itertools import chain
-from typing import TYPE_CHECKING, Iterable, Mapping, Optional, Sequence, Union
+from typing import (
+ TYPE_CHECKING,
+ Iterable,
+ Mapping,
+ Optional,
+ Sequence,
+ Union,
+)
from urllib.parse import urlencode
from slack.error import SlackApiError
@@ -26,7 +33,12 @@ if TYPE_CHECKING:
from slack_api.slack_team_info import SlackTeamInfoResponse
from slack_api.slack_usergroups_info import SlackUsergroupsInfoResponse
from slack_api.slack_users_conversations import SlackUsersConversationsResponse
- from slack_api.slack_users_info import SlackUserInfoResponse, SlackUsersInfoResponse
+ from slack_api.slack_users_info import (
+ SlackProfile,
+ SlackSetProfile,
+ SlackUserInfoResponse,
+ SlackUsersInfoResponse,
+ )
from slack_api.slack_users_prefs import SlackUsersPrefsGetResponse
from slack_edgeapi.slack_usergroups_info import SlackEdgeUsergroupsInfoResponse
from slack_edgeapi.slack_users_search import SlackUsersSearchResponse
@@ -242,6 +254,20 @@ class SlackApi(SlackApiCommon):
raise SlackApiError(self.workspace, method, response, params)
return response
+ async def _set_user_profile(self, profile: SlackSetProfile):
+ method = "users.profile.set"
+ params: Params = {"profile": dict(profile)}
+ response: SlackProfile = await self._fetch(method, params)
+ if response["ok"] is False:
+ raise SlackApiError(self.workspace, method, response, params)
+ return response
+
+ async def set_user_status(self, status: str):
+ return await self._set_user_profile({"status_text": status})
+
+ async def clear_user_status(self):
+ return await self._set_user_profile({"status_emoji": "", "status_text": ""})
+
async def _fetch_users_info_without_splitting(self, user_ids: Iterable[str]):
method = "users.info"
params: Params = {"users": ",".join(user_ids)}