Skip to content

Instantly share code, notes, and snippets.

@larkintuckerllc
Created January 6, 2026 01:05
Show Gist options
  • Select an option

  • Save larkintuckerllc/5ab12d74a47e0cb0a373ce8f775b1b94 to your computer and use it in GitHub Desktop.

Select an option

Save larkintuckerllc/5ab12d74a47e0cb0a373ce8f775b1b94 to your computer and use it in GitHub Desktop.
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
from slack_sdk.errors import SlackApiError
app = App(token=os.environ.get("SLACK_BOT_TOKEN"))
@app.command("/agent")
def handle_agent_command(ack, command, client, respond):
ack()
channel_id = command["channel_id"]
prompt = command.get("text", "")
message = f"Working on the prompt... {prompt}"
try:
client.chat_postMessage(channel=channel_id, text=message)
except SlackApiError as e:
error = e.response["error"]
if error == "not_in_channel":
try:
client.conversations_join(channel=channel_id)
client.chat_postMessage(channel=channel_id, text=message)
except SlackApiError as join_error:
respond(f"Something went wrong: {join_error.response['error']}")
elif error == "channel_not_found":
respond("I don't have access to this channel. Please invite me by typing `/invite @Hello LangChain` and try again.")
else:
respond(f"Something went wrong: {error}")
if __name__ == "__main__":
SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment