| Home | API Documentation |
Internal: Mug · ThorsMug · ThorsSlack · NisseServer · NisseHTTP · ThorsSocket · ThorsCrypto · ThorsSerializer · ThorsMongo · ThorsLogging · ThorsIOUtil
Implementation details for the ThorsSlack library.
Source: third/Mug/src/ThorsSlack/
ThorsSlack is a header-heavy library that provides type-safe C++ representations of Slack API objects. It relies heavily on ThorsSerializer for automatic JSON serialization.
┌──────────────────────────────────────────────────┐
│ User Application │
├──────────────────────────────────────────────────┤
│ ThorsSlack │
│ SlackClient · SlackEventHandler · API types │
├──────────────────────────────────────────────────┤
│ ThorsSerializer (JSON) · NisseHTTP (webhooks) │
└──────────────────────────────────────────────────┘
| File | Purpose |
|---|---|
SlackClient.h |
HTTP client for making REST API calls to Slack |
SlackStream.h |
Stream-based communication with Slack APIs |
SlackEventHandler.h |
Webhook event handler for incoming Slack events |
SlashCommand.h |
Slash command request/response types |
Each API*.h file defines request and response types for a group of Slack API endpoints:
| File | Slack API Methods |
|---|---|
API.h |
Common API types |
APIAuth.h |
auth.test |
APIChat.h |
Common chat types |
APIChatMessage.h |
chat.postMessage, chat.update, chat.delete |
APIChatSchedule.h |
chat.scheduleMessage, chat.scheduledMessages.list |
APIChatStream.h |
Stream-based chat operations |
APIChatUtil.h |
Chat utility types |
APIConversationsHistory.h |
conversations.history |
APIDialog.h |
Dialog interactions |
APIPins.h |
pins.add, pins.remove, pins.list |
APIReactions.h |
reactions.add, reactions.remove, reactions.get, reactions.list |
APIStar.h |
stars.add, stars.remove, stars.list |
APIViews.h |
View operations |
APIBlockActions.h |
Block action interactions |
| File | Event Type |
|---|---|
Event.h |
Base event types and discriminators |
EventCallback.h |
Event callback wrapper |
EventCallbackAppMentioned.h |
App mention events |
EventCallbackMessage.h |
Message events |
EventCallbackPin.h |
Pin add/remove events |
EventCallbackReaction.h |
Reaction add/remove events |
EventCallbackStar.h |
Star add/remove events |
EventURLVerification.h |
URL verification challenge (required by Slack) |
| File | Purpose |
|---|---|
SlackBlockKit.h |
Block Kit UI elements (sections, actions, inputs, etc.) |
All Slack API types use ThorsSerializer macros for automatic JSON conversion:
struct PostMessage {
std::string channel;
std::string text;
// ... other fields
};
ThorsAnvil_MakeTrait(PostMessage, channel, text, ...);
This means:
Slack sends events via HTTP POST webhooks. The event handling uses polymorphic deserialization:
"type" field to identify the event type.SlackEventHandler dispatches to the appropriate callback.Slack requires URL verification when setting up event subscriptions. EventURLVerification handles the challenge-response protocol:
{"type": "url_verification", "challenge": "..."}{"challenge": "..."}.Manages authentication tokens and HTTP communication with Slack’s API:
Authorization: Bearer <token>)"ok": false)ThorsSlack is designed to run as a Mug plugin. A typical Slack bot:
MugPluginSimple subclassSlackClient to make outbound API callsTests are in test/ and use Environment.h to provide test OAuth tokens and channel IDs. Tests verify serialization round-trips for all API types.