The Open Framework for Building Agents
feat(eve): pass trigger_id to Slack onInteraction actions (#4337)
roboeve[bot]3c8919a8ffc1
diff --git a/.changeset/slack-interaction-trigger-id.md b/.changeset/slack-interaction-trigger-id.mdnew file mode 100644index 000000000..6eb4f14a3--- /dev/null+++ b/.changeset/slack-interaction-trigger-id.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Slack `onInteraction` actions now include `triggerId`, so a button on a message can open a modal with `views.open`.diff --git a/docs/channels/slack.mdx b/docs/channels/slack.mdxindex b6de8b83c..c37cd040b 100644--- a/docs/channels/slack.mdx+++ b/docs/channels/slack.mdx@@ -167,7 +167,7 @@ Only the first available handler runs. A message hook returning `null` drops theMessage hooks only decide whether and how a message starts a turn. They don't render anything, so replacing one never changes what people see: eve still acknowledges the message, shows progress, and posts the reply. To change what the agent posts, add [renderers](#customize-rendering).-`onInteraction(action, ctx)` separately handles user-owned `block_actions` callbacks. eve-owned HITL buttons and modal submissions go through `onInputResponse(ctx, submission)` instead. eve attaches the triggering Slack user id to the same model message as its text, preserving speaker attribution without profile lookups.+`onInteraction(action, ctx)` separately handles user-owned `block_actions` callbacks. eve-owned HITL buttons and modal submissions go through `onInputResponse(ctx, submission)` instead. `action.triggerId` carries the click's `trigger_id`, so a button can open a modal with `ctx.slack.request("views.open", { trigger_id, view })`. Slack accepts the id for about 3 seconds. eve attaches the triggering Slack user id to the same model message as its text, preserving speaker attribution without profile lookups.Use `onShortcut(shortcut, ctx)` for message shortcuts and global shortcuts configured under **Interactivity & Shortcuts** in your Slack app. The handler receives the shortcut callback ID, user, workspace, and trigger ID. Message shortcuts also include the selected message and channel. The context exposes workspace-scoped Slack API access because global shortcuts have no channel or message. eve acknowledges shortcut requests immediately and keeps their handlers alive in the background.diff --git a/packages/eve/src/public/channels/slack/interactions.ts b/packages/eve/src/public/channels/slack/interactions.tsindex 6cbfadf98..47f1efacb 100644--- a/packages/eve/src/public/channels/slack/interactions.ts+++ b/packages/eve/src/public/channels/slack/interactions.ts@@ -129,6 +129,7 @@ export function parseBlockActionsPayload(blockId: a.block_id != null ? String(a.block_id) : undefined,selectedOptionValue: extractSelectedOptionValue(a),messageTs: message?.ts,+ triggerId: typeof rawBody.trigger_id === "string" ? rawBody.trigger_id : undefined,label: extractActionLabel(a),user,})),@@ -158,6 +159,7 @@ function parseSharedBlockActionsPayload(blockId: action.blockId,selectedOptionValue: action.selectedOptionValue,messageTs: body.messageTs,+ triggerId: body.triggerId,label: action.label,user: {id: action.user?.id ?? body.userId,diff --git a/packages/eve/src/public/channels/slack/slackChannel.test.ts b/packages/eve/src/public/channels/slack/slackChannel.test.tsindex e4106fe5e..e2f7d4879 100644--- a/packages/eve/src/public/channels/slack/slackChannel.test.ts+++ b/packages/eve/src/public/channels/slack/slackChannel.test.ts@@ -4448,6 +4448,35 @@ describe("slackChannel() HITL interaction pipeline", () => {expect(send).not.toHaveBeenCalled();});+ it("passes the click's trigger_id to onInteraction", async () => {+ const triggerIds: (string | undefined)[] = [];+ const channel = slackChannel({+ credentials: { botToken: "xoxb-test" },+ async onInteraction(action) {+ triggerIds.push(action.triggerId);+ },+ });++ await firePost(+ channel,+ buildSignedInteractionRequest({+ type: "block_actions",+ trigger_id: "13345224609.738474920.8088930838d88f008e0",+ team: { id: "T01" },+ user: { id: "U01", username: "ada" },+ channel: { id: "C01" },+ message: {+ ts: "1700000000.000010",+ thread_ts: "1700000000.000001",+ blocks: [],+ },+ actions: [{ action_id: "edit", text: { type: "plain_text", text: "Edit" } }],+ }),+ );++ expect(triggerIds).toEqual(["13345224609.738474920.8088930838d88f008e0"]);+ });+it("gives a Slack Connect user one principal across messages and button clicks", async () => {const botToken = vi.fn((_context: { readonly teamId?: string }) => "xoxb-test");fetchMock.mockImplementation(diff --git a/packages/eve/src/public/channels/slack/slackChannel.ts b/packages/eve/src/public/channels/slack/slackChannel.tsindex 348b3aa0b..cf6ec7c07 100644--- a/packages/eve/src/public/channels/slack/slackChannel.ts+++ b/packages/eve/src/public/channels/slack/slackChannel.ts@@ -484,6 +484,12 @@ export interface SlackInteractionAction {* inside thread replies.*/readonly messageTs?: string;+ /**+ * Slack `trigger_id` of the click. Pass it to `views.open` (for example+ * through `ctx.slack.request`) to open a modal from a message button. Slack+ * accepts it for about 3 seconds, so call `views.open` first in the handler.+ */+ readonly triggerId?: string;/*** Display label of the clicked widget: `text.text` for buttons,* `selected_option.text.text` for radio/static_select. Renders the