Hydra AI
Future 🔮

Slack (Preview) 🚧

Build intelligent Slack apps with AI

Preview Feature

This feature is currently under active development. The documentation below represents our planned implementation and may change before release. Send feedback to support@usehydra.ai.

Why Hydra AI for Slack? ⚡

Hydra AI takes the complexity out of creating intelligent Slack workflows. By registering components once, Hydra handles:

  • Dynamic Selection: Automatically matches user queries with the best component.
  • Contextual Adaptation: Hydrates components with the most relevant data.

Whether you're building workflows, modals, or interactive home tabs, Hydra AI simplifies the process.

Slack Example 1
Slack Example 2

Getting Started

1. Install Required Dependencies

npm install --save jsx-slack @slack/web-api hydra-ai

2. Initialize HydraClient

Create an instance of HydraClient in your application:

src/hydra-client.ts
import HydraClient from "hydra-ai";
 
const hydraClient = new HydraClient("gpt-4", "openai");

3. Define and Register Components

Define Slack components using your preferred templating approach. We recommend jsx-slack for its familiar JSX syntax and type safety, but you can use any templating library or write raw Block Kit JSON as long as it compiles to valid Slack Block Kit format.

Example: Welcome Message

src/components/welcomeMessage.ts
import { jsxslack } from "jsx-slack";
import { Blocks, Section } from "jsx-slack";
 
export const welcomeMessage = ({ userName }: { userName: string }) => jsxslack`
  <Blocks>
    <Section>
      Hello, <b>${userName}</b>! 🎉 We're excited to have you onboard.
    </Section>
  </Blocks>
`;
 
await hydraClient.registerComponent(
  "welcomeMessage",
  "A personalized welcome message for Slack users.",
  welcomeMessage,
  { userName: { type: "string", required: true } }
);

4. Generate Components

Let HydraClient dynamically generate components based on user queries.

Example: Generate a Component for a User Query

src/generateComponent.ts
const generatedComponent = await hydraClient.generateComponent(
  "Send a welcome message to Jane Doe",
  (progress) => console.log(`Progress: ${progress}`)
);
 
console.log("Generated Component:", generatedComponent.component);

5. Send Generated Blocks to Slack

Use the Slack API to send the generated blocks.

Example: Send a Slack Message

src/sendSlackMessage.ts
import { WebClient } from "@slack/web-api";
 
const slackClient = new WebClient(process.env.SLACK_TOKEN);
 
await slackClient.chat.postMessage({
  channel: "C1234567890", // Replace with your channel ID
  blocks: generatedComponent.component,
});

Advanced Features

Context Tools for Dynamic Data

Add external data-fetching capabilities to your components with contextTools.

Example: Fetching a Dynamic User List

src/components/dynamicUserList.ts
await hydraClient.registerComponent(
  "dynamicUserList",
  "A Slack message showing a dynamic user list",
  (props) => jsxslack`
    <Blocks>
      <Section>
        <b>Here are the current users:</b>
      </Section>
      ${props.userList.map((user) => `<Section>${user}</Section>`).join("")}
    </Blocks>
  `,
  { userList: { type: "array", required: true } },
  [
    {
      definition: {
        name: "fetchUsers",
        description: "Fetch a list of users from an external API",
        parameters: [],
      },
      getComponentContext: async () => {
        const response = await fetch("https://api.example.com/users");
        return await response.json();
      },
    },
  ]
);

Differentiating Slack Workflows

HydraClient supports different types of Slack interactions:

  1. Messages: Generate blocks for chat messages.
  2. Modals: Create interactive forms and workflows.
  3. Home Tabs: Build personalized user dashboards.

Example: Create a Modal

src/components/feedbackModal.ts
import { Modal, Input, Section, Divider } from "jsx-slack";
 
export const feedbackModal = () => jsxslack`
  <Modal title="Feedback Form" close="Cancel">
    <Section>Please provide your feedback below:</Section>
    <Divider />
    <Input type="text" name="userName" label="Name" required />
    <Input type="textarea" name="feedback" label="Feedback" required />
    <Input type="submit" value="Submit" />
  </Modal>
`;
 
await hydraClient.registerComponent(
  "feedbackModal",
  "A feedback form in Slack modal format.",
  feedbackModal
);

Example: Open the Modal

src/openFeedbackModal.ts
await slackClient.views.open({
  trigger_id: "YOUR_TRIGGER_ID", // Replace with your trigger ID
  view: generatedModal.component,
});

Future Roadmap

We're constantly improving HydraClient! Here's what's coming:

FeatureDescriptionStatus
Slack Component LibraryPrebuilt components for common workflows like approvals and notifications.Coming Soon
Interactive ComponentsNative handling of Slack interactive elements (e.g., buttons, dropdowns).Coming Soon
Native Slack IntegrationDirectly send Slack messages and modals without external APIs.Coming Soon
Debug ModeVisualize and log generated Slack JSON payloads.Coming Soon
ValidationVerify compatibility of generated components with Slack Block Kit before sending.Coming Soon
Multi-Platform SupportExtend support to other platforms like Microsoft Teams and Discord.Coming Soon
Error HandlingComprehensive error handling with detailed logs and recovery strategies.Coming Soon
Error ReportingAutomated error reporting and monitoring capabilities.Coming Soon
Fallback MechanismsGraceful degradation and fallback options when components fail.Coming Soon

FAQ

How does HydraClient decide which component to use?

HydraClient uses the user query, context, and registered components to dynamically choose the best match. If no match is found, a default markdown text block is used.

Can I handle Slack interactive events with HydraClient?

Currently, you need to pass Slack events back to HydraClient as context. Native event handling is planned for future releases.

Is caching supported for generated components?

Not yet. HydraClient generates a new component for every request. Caching is a planned feature.


Feedback on our documentation:

This is being built right now so let us know if you want us to change or improve our implementation.