To schedule recurring status changes on Slack, you can use a combination of Slack's API and a serverless function on a platform like AWS Lambda, Google Cloud Functions, or Azure Functions. This will allow you to create a function that updates your status at specified intervals.
Here's a step-by-step guide to achieve this:
Create a Slack App:
a. Go to https://api.slack.com/apps and click on "Create New App." b. Name your app, select the workspace you want to develop it in, and click "Create App." c. Click on "OAuth & Permissions" in the sidebar, then scroll down to "Scopes." d. Add the
users.profile:write
scope to your app. This will allow your app to update your profile status. e. Click on "Install App" in the sidebar, then click "Install App to Workspace." Grant the required permissions.Obtain your access token:
After installing the app, you'll receive a "Bot User OAuth Access Token." Save this token, as you'll need it to authenticate requests to the Slack API.
Write a serverless function:
Create a function using your preferred cloud platform (AWS Lambda, Google Cloud Functions, or Azure Functions) with a language of your choice (e.g., Python, Node.js, etc.).
Here's a Python example using the
slack_sdk
library:pythonimport os from slack_sdk import WebClient from slack_sdk.errors import SlackApiError def set_status(event, context): client = WebClient(token=os.environ['SLACK_APP_TOKEN']) status_text = event['status_text'] status_emoji = event['status_emoji'] status_expiration = event['status_expiration'] try: response = client.users_profile_set( profile={ "status_text": status_text, "status_emoji": status_emoji, "status_expiration": status_expiration } ) except SlackApiError as e: print(f"Error updating status: {e}")
Replace
SLACK_APP_TOKEN
with the token obtained in step 2.Set up scheduled events:
Use your cloud platform's scheduling mechanism (e.g., AWS EventBridge, Google Cloud Scheduler, or Azure Logic Apps) to trigger the function you created in step 3 at the desired intervals.
Deploy the function and schedule:
Deploy your serverless function and set up the scheduler with the desired recurring intervals. You'll need to provide the status text, emoji, and expiration timestamp as inputs to your function.
Now, your Slack status should update automatically according to the schedule you've set up.