Prompt
How do I connect an AI agent to Slack and Gmail?
Latest observation
Oct 9, 2026
OpenAI APIWeb search: off
To connect an AI agent to Slack and Gmail, you generally need to give the agent access through each product’s API, then define what actions it’s allowed to take.
High-level approach
-
Create app credentials
- Slack: create a Slack App and use a bot token.
- Gmail: use Google Cloud / Gmail API with OAuth credentials.
-
Authenticate the agent
- Store the tokens securely.
- Use OAuth for user-delegated access, especially for Gmail.
-
Expose tools/actions to the agent
- Slack: send messages, read channels, search messages, reply in threads.
- Gmail: read inbox, search emails, draft replies, send emails.
-
Connect those tools to your AI agent
- If you’re using an agent framework, register these API calls as “tools.”
- The model decides when to call them, and your code executes them.
Slack setup
1) Create a Slack App
- Go to the Slack API dashboard.
- Create a new app.
- Add a Bot User.
2) Add required scopes
Common scopes:
chat:write— send messageschannels:read— list public channelschannels:history— read public channel historygroups:read/groups:history— private channels if neededim:read,im:history— direct messagesusers:read— user info
3) Install the app to your workspace
- Use OAuth to install the app.
- Save the bot token.
4) Use Slack API / SDK
Example actions:
chat.postMessageconversations.historyconversations.replies
Gmail setup
1) Create a Google Cloud project
- Enable the Gmail API.
2) Configure OAuth consent screen
- Add your app name, scopes, and test users.
3) Create OAuth client credentials
- Typically a web app or desktop app client ID.
4) Request Gmail scopes
Common scopes:
https://www.googleapis.com/auth/gmail.readonlyhttps://www.googleapis.com/auth/gmail.sendhttps://www.googleapis.com/auth/gmail.modify
5) Authenticate with OAuth
- The user logs in with Google and approves access.
- Store the access/refresh tokens securely.
How to wire this into an AI agent
Your agent framework should have tools like:
send_slack_message(channel, text)read_slack_thread(channel, ts)search_gmail(query)draft_gmail_reply(message_id, text)send_gmail(to, subject, body)
The agent:
- Receives a user request.
- Chooses a tool.
- Your backend executes the API call.
- The result is returned to the model.
- The model responds to the user.
Security best practices
- Use OAuth, not hardcoded passwords.
- Limit scopes to only what you need.
- Keep tokens in a secrets manager.
- Log carefully; avoid exposing email contents or Slack messages unnecessarily.
- Add approval steps for risky actions like sending emails or posting messages.
- If the agent is autonomous, set guardrails:
- allowed channels
- allowed recipients
- approval required before sending
Example architecture
- Frontend: chat UI for the user
- Agent orchestrator: LLM + tool calling
- Slack connector: Slack API client
- Gmail connector: Google API client
- Database: store conversations, token metadata, and audit logs
- Secrets manager: store OAuth tokens securely
If you want a quick implementation path
- Use Slack Bolt for Slack integration.
- Use Google API client libraries for Gmail.
- Use an agent framework like:
- OpenAI Agents / tool calling
- LangChain
- LlamaIndex
- CrewAI
Minimal pseudo-flow
User: “Summarize my unread Gmail and post it to #team-updates.”
Agent:
1. Calls Gmail tool to fetch unread messages.
2. Summarizes them.
3. Calls Slack tool to post summary to #team-updates.
4. Confirms completion.
If you want, I can give you:
- a Python example for Slack + Gmail integration, or
- a step-by-step setup guide for one specific framework.