@wellze/integration-slack
v0.0.0
Published
Slack integration for Wellze workflows.
Maintainers
Readme
@wellze/integration-slack
Slack integration for Wellze workflows.
Overview
This package provides Slack integration bindings, triggers, and steps for building workflows that interact with Slack.
Installation
pnpm add @wellze/integration-slackTrigger Presets
Webhook Triggers
Slack webhook triggers fire when events occur in your Slack workspace.
Message Webhooks
import { webhooks } from '@wellze/integration-slack';
import { attachTrigger } from '@wellze/workflow-core';
import { myWorkflow } from './workflow';
// Message received
const messageReceived = webhooks.messageReceived().createTrigger({
name: 'Slack Message Received',
description: 'Fires when a message is posted',
transform: (event, credentials) => {
// event: SlackEventPayload - typed automatically
// credentials: SlackCredentials - typed automatically
return {
channelId: event.event.channel,
userId: event.event.user,
text: event.event.text,
};
},
});
// App mentioned
const appMentioned = webhooks.appMentioned().createTrigger({
name: 'Slack App Mentioned',
description: 'Fires when the app is mentioned',
transform: (event) => ({
channelId: event.event.channel,
userId: event.event.user,
text: event.event.text,
}),
});
// Attach to workflow
export const binding = attachTrigger({
workflow: myWorkflow,
trigger: messageReceived,
transform: (payload, credentials) => {
return {
channelId: payload.event.channel,
userId: payload.event.user,
text: payload.event.text,
};
},
});Channel Webhooks
import { webhooks } from '@wellze/integration-slack';
// Channel created
const channelCreated = webhooks.channelCreated().createTrigger({
name: 'Slack Channel Created',
transform: (event) => ({
channelId: event.event.channel.id,
name: event.event.channel.name,
}),
});
// Member joined channel
const memberJoinedChannel = webhooks.memberJoinedChannel().createTrigger({
name: 'Slack Member Joined Channel',
transform: (event) => ({
channelId: event.event.channel,
userId: event.event.user,
}),
});
// Member left channel
const memberLeftChannel = webhooks.memberLeftChannel().createTrigger({
name: 'Slack Member Left Channel',
transform: (event) => ({
channelId: event.event.channel,
userId: event.event.user,
}),
});Reaction Webhooks
import { webhooks } from '@wellze/integration-slack';
// Reaction added
const reactionAdded = webhooks.reactionAdded().createTrigger({
name: 'Slack Reaction Added',
transform: (event) => ({
channelId: event.event.item.channel,
messageTs: event.event.item.ts,
userId: event.event.user,
reaction: event.event.reaction,
}),
});
// Reaction removed
const reactionRemoved = webhooks.reactionRemoved().createTrigger({
name: 'Slack Reaction Removed',
transform: (event) => ({
channelId: event.event.item.channel,
messageTs: event.event.item.ts,
userId: event.event.user,
reaction: event.event.reaction,
}),
});Team Webhooks
import { webhooks } from '@wellze/integration-slack';
// Team join
const teamJoin = webhooks.teamJoin().createTrigger({
name: 'Slack Team Join',
transform: (event) => ({
userId: event.event.user.id,
email: event.event.user.profile?.email,
}),
});Steps
Messages
import { sendMessage, updateMessage, deleteMessage } from '@wellze/integration-slack';
// Send message
const message = await sendMessage({
channel: 'C1234567890',
text: 'Hello, world!',
});
// Update message
await updateMessage({
channel: 'C1234567890',
ts: '1234567890.123456',
text: 'Updated message',
});
// Delete message
await deleteMessage({
channel: 'C1234567890',
ts: '1234567890.123456',
});Channels
import { createChannel, getChannelInfo, listChannels } from '@wellze/integration-slack';
// Create channel
const channel = await createChannel({
name: 'my-channel',
isPrivate: false,
});
// Get channel info
const info = await getChannelInfo({
channel: 'C1234567890',
});
// List channels
const channels = await listChannels({
excludeArchived: true,
});Users
import { getUserInfo, listUsers, lookupUserByEmail } from '@wellze/integration-slack';
// Get user info
const user = await getUserInfo({
user: 'U1234567890',
});
// List users
const users = await listUsers();
// Lookup user by email
const userByEmail = await lookupUserByEmail({
email: '[email protected]',
});Type Safety
All triggers and steps provide full type inference:
import type { InferTriggerPayload, InferTriggerCredentials } from '@wellze/workflow-core';
const messageReceived = webhooks.messageReceived().createTrigger({
name: 'Message Received',
});
type Payload = InferTriggerPayload<typeof messageReceived>; // SlackEventPayload
type Credentials = InferTriggerCredentials<typeof messageReceived>; // SlackCredentialsCredentials
Slack credentials require:
botToken: string- Slack bot token (starts withxoxb-)signingSecret: string- Slack signing secret for webhook verification
Webhook Verification
Slack webhooks are automatically verified using the integration's verification logic, which validates the X-Slack-Signature header using the signing secret.
Event Types
The integration supports the following Slack event types:
message- Message postedapp_mention- App mentionedchannel_created- Channel createdmember_joined_channel- Member joined channelmember_left_channel- Member left channelreaction_added- Reaction addedreaction_removed- Reaction removedteam_join- Team member joined
Examples
See packages/test-workflows/workflows/ for complete workflow examples using Slack triggers and steps.
