Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(control-ui): generate a Slack app manifest with both request URLs

Jose Ramirez54a27bd33ce2
diff --git a/control-ui/app/communication-channels/[name]/edit/page.tsx b/control-ui/app/communication-channels/[name]/edit/page.tsx
index eb2d08a84..90bf9db52 100644
--- a/control-ui/app/communication-channels/[name]/edit/page.tsx
+++ b/control-ui/app/communication-channels/[name]/edit/page.tsx
@@ -16,6 +16,8 @@ import { SegmentedControl } from '@components/SegmentedControl'
import { SelectionDropdown } from '@components/SelectionDropdown'
import { IconBroadcast } from '@components/Sidebar/icons'
import { useToast } from '@components/Toast'
+import { IconCopy } from '@components/icons'
+import { Button } from '@components/ui'
import { CONTROL_ROUTES } from '@constants/routes'
import { apiGet, apiSend, isSilentApiError } from '@lib/api'
import type { ChannelType } from '@lib/channelTypes'
@@ -37,10 +39,13 @@ import {
slackWebhookUrlForChannel,
teamsWebhookUrlForChannel,
} from '@lib/communicationChannels'
+import { canGenerateSlackAppManifest, slackAppManifest } from '@lib/slackAppManifest'
type ChannelProvider = CommunicationChannelProvider
type DraftState = CommunicationChannelDraftState
+const DEFAULT_SLACK_APP_NAME = 'Evenfire'
+
type HostItem = {
metadata?: { name?: string; namespace?: string }
}
@@ -145,6 +150,13 @@ export default function EditCommunicationChannelPage() {
const activeConversations = draft ? conversationsForProvider(activeTab, draft) : []
const slackRequestUrl = item ? slackWebhookUrlForChannel(item) : null
const teamsRequestUrl = item ? teamsWebhookUrlForChannel(item) : null
+ // A relative request_url is invalid to Slack, so warn instead of handing over a manifest that
+ // cannot work. slackWebhookUrlForChannel falls back to a bare path when the deployment has no
+ // public webhook address.
+ const slackManifest =
+ slackRequestUrl && canGenerateSlackAppManifest(slackRequestUrl)
+ ? slackAppManifest(draft?.slackBotHandle.trim() || DEFAULT_SLACK_APP_NAME, slackRequestUrl)
+ : null
async function persistDraft(nextDraft: DraftState, successMessage: string) {
setSaving(true)
@@ -207,6 +219,17 @@ export default function EditCommunicationChannelPage() {
)
}
+ async function copySlackAppManifest() {
+ if (!slackManifest) return
+ const copied = await copyTextToClipboard(slackManifest)
+ showToast(
+ copied
+ ? 'Slack app manifest copied.'
+ : 'Could not copy to clipboard. Select the manifest and copy it manually.',
+ { tone: copied ? 'success' : 'error' }
+ )
+ }
+
async function copyTeamsRequestUrl() {
if (!teamsRequestUrl) return
const copied = await copyTextToClipboard(teamsRequestUrl)
@@ -446,6 +469,46 @@ export default function EditCommunicationChannelPage() {
Use this URL for Slack Event Subscriptions and Interactivity.
</span>
</div>
+ {slackRequestUrl ? (
+ slackManifest ? (
+ <div className="cu-field">
+ <span className="cu-field__label">Slack App Manifest</span>
+ <div className="cu-command-block">
+ <div className="cu-command-block__toolbar">
+ <span>YAML</span>
+ <Button
+ type="button"
+ variant="secondary"
+ size="sm"
+ className="cu-command-block__copy"
+ onClick={copySlackAppManifest}
+ disabled={saving}
+ aria-label="Copy Slack app manifest"
+ >
+ <IconCopy width={15} height={15} />
+ Copy
+ </Button>
+ </div>
+ <pre className="cu-command-block__pre cu-slack-manifest__pre">
+ <code>{slackManifest}</code>
+ </pre>
+ </div>
+ <span className="cu-field__hint">
+ In Slack, Create New App → From an app manifest. It fills in both
+ Request URLs, on Event Subscriptions and on Interactivity &amp;
+ Shortcuts. Setting only Event Subscriptions leaves approval buttons dead
+ with nothing in the logs.
+ </span>
+ </div>
+ ) : (
+ <div className="cu-banner cu-banner--warning">
+ No app manifest: this deployment has no public webhook address, so the
+ Request URL above is a path and Slack cannot reach it. Expose the webhook
+ proxy publicly and set NEXT_PUBLIC_WORKFLOW_APPROVAL_READER_BASE_URL to
+ that address, or prefix the path with it by hand in Slack.
+ </div>
+ )
+ ) : null}
</>
) : (
<>
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 88da59318..f335cccb8 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -9778,6 +9778,13 @@ textarea.cu-input {
white-space: pre;
}
+/* The Slack app manifest runs ~25 lines. Cap it so the credentials panel below
+ stays reachable instead of being pushed off the form. */
+.cu-slack-manifest__pre {
+ max-height: 18rem;
+ overflow-y: auto;
+}
+
.cu-channel-conversations-table__name {
font-weight: 600;
}
diff --git a/control-ui/lib/__tests__/slackAppManifest.test.ts b/control-ui/lib/__tests__/slackAppManifest.test.ts
new file mode 100644
index 000000000..74ec971b8
--- /dev/null
+++ b/control-ui/lib/__tests__/slackAppManifest.test.ts
@@ -0,0 +1,82 @@
+import { describe, expect, it } from 'vitest'
+import { canGenerateSlackAppManifest, slackAppManifest } from '../slackAppManifest'
+
+const URL = 'https://webhook.example.com/webhooks/slack/slack%3AeyJ4IjoxfQ'
+
+describe('slackAppManifest', () => {
+ const yaml = slackAppManifest('Evenfire', URL)
+
+ it('sets BOTH request URLs to the same value', () => {
+ const occurrences = yaml.split(URL).length - 1
+ expect(occurrences).toBe(2)
+ expect(yaml).toContain('event_subscriptions:')
+ expect(yaml).toContain('interactivity:')
+ // Counting occurrences alone still passes when one URL merely has something appended, so
+ // pin the whole line. Events-only setup is the mistake this manifest exists to prevent:
+ // Slack blocks the button click client-side and nothing reaches the cluster.
+ const requestUrlLines = yaml.split('\n').filter(line => line.trim().startsWith('request_url:'))
+ expect(requestUrlLines).toEqual([` request_url: ${URL}`, ` request_url: ${URL}`])
+ })
+
+ it('subscribes to every bot event the reader handles', () => {
+ for (const event of [
+ 'app_mention',
+ 'message.channels',
+ 'message.groups',
+ 'message.im',
+ 'message.mpim',
+ ]) {
+ expect(yaml).toContain(event)
+ }
+ })
+
+ it('requests every scope the platform calls', () => {
+ for (const scope of [
+ 'app_mentions:read',
+ 'channels:history',
+ 'groups:history',
+ 'im:history',
+ 'mpim:history',
+ 'channels:read',
+ 'groups:read',
+ 'im:read',
+ 'mpim:read',
+ 'chat:write',
+ 'files:write',
+ 'users:read',
+ ]) {
+ expect(yaml).toContain(scope)
+ }
+ })
+
+ it('disables socket mode, which this platform does not use', () => {
+ expect(yaml).toContain('socket_mode_enabled: false')
+ })
+
+ it('uses the app name given', () => {
+ expect(yaml).toContain('name: Evenfire')
+ })
+
+ it('quotes an app name that would otherwise break the YAML', () => {
+ const quoted = slackAppManifest('Acme: support bot', URL)
+ expect(quoted).toContain('name: "Acme: support bot"')
+ expect(quoted).not.toContain('name: Acme: support bot')
+ })
+})
+
+describe('canGenerateSlackAppManifest', () => {
+ it('accepts an absolute request URL', () => {
+ expect(canGenerateSlackAppManifest(URL)).toBe(true)
+ expect(canGenerateSlackAppManifest('http://webhook.example.com/webhooks/slack/x')).toBe(true)
+ })
+
+ it('refuses a bare path, which Slack rejects as a request_url', () => {
+ expect(canGenerateSlackAppManifest('/webhooks/slack/slack%3AeyJ4IjoxfQ')).toBe(false)
+ })
+
+ it('refuses a channel with no Slack webhook at all', () => {
+ expect(canGenerateSlackAppManifest(null)).toBe(false)
+ expect(canGenerateSlackAppManifest(undefined)).toBe(false)
+ expect(canGenerateSlackAppManifest('')).toBe(false)
+ })
+})
diff --git a/control-ui/lib/slackAppManifest.ts b/control-ui/lib/slackAppManifest.ts
new file mode 100644
index 000000000..57d0c76af
--- /dev/null
+++ b/control-ui/lib/slackAppManifest.ts
@@ -0,0 +1,76 @@
+const BOT_SCOPES = [
+ 'app_mentions:read',
+ 'channels:history',
+ 'groups:history',
+ 'im:history',
+ 'mpim:history',
+ 'channels:read',
+ 'groups:read',
+ 'im:read',
+ 'mpim:read',
+ 'chat:write',
+ 'files:write',
+ 'users:read',
+]
+
+const BOT_EVENTS = [
+ 'app_mention',
+ 'message.channels',
+ 'message.groups',
+ 'message.im',
+ 'message.mpim',
+]
+
+/** Plain YAML scalars cannot carry ': ', '#', quotes, or leading punctuation. */
+const YAML_PLAIN_SAFE = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/
+
+function yamlScalar(value: string): string {
+ const trimmed = value.trim()
+ if (YAML_PLAIN_SAFE.test(trimmed)) return trimmed
+ return `"${trimmed.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
+}
+
+/**
+ * Slack rejects a manifest whose `request_url` is relative, and
+ * `slackWebhookUrlForChannel` falls back to a bare path when the deployment has
+ * no public webhook address (the minikube case). Callers must warn instead of
+ * handing over a manifest Slack cannot accept.
+ */
+export function canGenerateSlackAppManifest(requestUrl: string | null | undefined): boolean {
+ return /^https?:\/\//i.test(requestUrl ?? '')
+}
+
+/**
+ * Slack app manifest for this channel. Both request URLs are the same value:
+ * the reader serves events and interactivity on one route. Setting only the
+ * events URL leaves approval buttons silently dead, because Slack blocks the
+ * click client-side and nothing reaches the cluster.
+ *
+ * `requestUrl` must be absolute. Slack rejects a relative `request_url`, so
+ * callers render a warning instead of a manifest when they only have a path.
+ */
+export function slackAppManifest(appName: string, requestUrl: string): string {
+ const name = yamlScalar(appName)
+ return `display_information:
+ name: ${name}
+features:
+ bot_user:
+ display_name: ${name}
+ always_online: false
+oauth_config:
+ scopes:
+ bot:
+${BOT_SCOPES.map(scope => ` - ${scope}`).join('\n')}
+settings:
+ event_subscriptions:
+ request_url: ${requestUrl}
+ bot_events:
+${BOT_EVENTS.map(event => ` - ${event}`).join('\n')}
+ interactivity:
+ is_enabled: true
+ request_url: ${requestUrl}
+ org_deploy_enabled: false
+ socket_mode_enabled: false
+ token_rotation_enabled: false
+`
+}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 141817c09..9acef6613 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.397",
+ "version": "0.1.398",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.397",
+ "version": "0.1.398",
"dependencies": {
"@clerum/llm-providers": "file:../packages/llm-providers",
"@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",
diff --git a/control-ui/package.json b/control-ui/package.json
index bb4eb3a4d..ffeb17067 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.397",
+ "version": "0.1.398",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",