I am trying to create an App for my workspace which would set the user's presence at appropriate moments. I wrote the following test function:
from slack_sdk import WebClient
client = WebClient(token=SLACK_USER_TOKEN)
email = 'test.email=test.com'
response = client.users_lookupByEmail(email=email)
user_id = response["user"]["id"]
client.users_setPresence(user=user_id, presence="away")
status_message = "deactivated"
status_emoji = ":x:"
client.users_profile_set(
user=user_id,
profile={
"status_text": status_message,
"status_emoji": status_emoji
}
)
But upon executing this code, I get:
The request to the Slack API failed. (url: https://www.slack.com/api/users.profile.set) The server responded with: {'ok': False, 'error': 'invalid_user'}
I have the following scopes active for SLACK_USER_TOKEN:
users.profile:read
users.profile:write
users:read
users:read.email
users:write
Why am I getting Invalid ID
? I double checked and the user_id
is correct and belongs to an actual user...
I expected the status of the user changed with a message showing on their slack profile. Instead, I got the error I mentioned above.