✅ Posting Method Using an Access Token (Slack Web API)
Slack’s “OAuth Token (such as xoxb-…)” is a key used to post using Slack’s Web API.
In this case, unlike Webhooks, you POST to the Slack API Endpoint with an Authorization: Bearer header.
🔑 Required Prerequisites
You need to include chat:write in the OAuth Scopes of your Slack app:
Setup Steps
- Go to https://api.slack.com/apps
- Create an app or select an existing one
- Under “OAuth & Permissions” >
Scopes→ Addchat:write - “Install to Workspace” or “Reinstall” to get the
Access Token(e.g.,xoxb-xxxxxxxxxx)
💻 C++ Code (Posting to Slack API using WinHTTP)
| |
📌 How to Get the Channel ID
Using just the channel name (e.g., #general) may sometimes result in an error.
A more reliable method is to use the ID found in the URL of the Slack channel page.
| |
✅ About Token Types (Supplementary)
| Token Format | Purpose | Example Use Case |
|---|---|---|
xoxb-... | Bot Token (Recommended) | Post, edit, delete |
xoxp-... | User Token (Not Recommended) | Non-bot operations |
| Refresh Token | Long-term token renewal | Usually not used |
📝 Summary
- To post to Slack from C++, the Slack Web API + Bearer Token method is reliable.
- Use the
chat.postMessageendpoint with HTTPS POST. - The token must be sent in the Bearer header.
- Specifying the channel by ID is recommended.
