import common from "../common/base.mjs";
import sampleEmit from "./test-event.mjs";
export default {
name: "New Interaction Events (Instant)",
version: "0.0.16",
key: "slack-new-interaction-event-received",
description: "Emit new events on new Slack [interactivity events](https://api.slack.com/interactivity) sourced from [Block Kit interactive elements](https://api.slack.com/interactivity/components), [Slash commands](https://api.slack.com/interactivity/slash-commands), or [Shortcuts](https://api.slack.com/interactivity/shortcuts).",
type: "source",
props: {
...common.props,
alert: {
type: "alert",
alertType: "info",
content: "Please note that only messages created via Pipedream's [Send Block Kit Message](https://pipedream.com/apps/slack/actions/send-block-kit-message) Action, or via API call from the Pipedream app will emit an interaction event with this trigger. \n\nBlock kit messages sent directly via the Slack's block kit builder will not trigger an interaction event. \n\nSee the [documentation](https://pipedream.com/apps/slack/triggers/new-interaction-event-received) for more details.",
},
action_ids: {
type: "string[]",
label: "Action IDs",
description: "Filter interaction events by specific `action_id`'s to subscribe for new interaction events. If none are specified, all `action_ids` created via Pipedream will emit new events.",
optional: true,
default: [],
},
conversations: {
propDefinition: [
common.props.slack,
"conversation",
],
type: "string[]",
label: "Channels",
description: "Filter interaction events by one or more channels. If none selected, any interaction event in any channel will emit new events.",
optional: true,
default: [],
},
slackApphook: {
type: "$.interface.apphook",
appProp: "slack",
async eventNames() {
const action_events = this.action_ids.reduce((carry, action_id) => {
if (this.conversations && this.conversations.length > 0) {
return [
...carry,
...this.conversations.map(
(channel) => `interaction_events:${channel}:${action_id}`,
),
];
}
return [
...carry,
`interaction_events:${action_id}`,
];
}, []);
if (action_events.length > 0) return action_events;
const channel_events = this.conversations.map(
(channel) => `interaction_events:${channel}`,
);
if (channel_events.length > 0) return channel_events;
return [
"interaction_events",
];
},
},
},
methods: {},
async run(event) {
this.$emit(
{
event,
},
{
summary: `New interaction event${
event?.channel?.id
? ` in channel ${event.channel.id}`
: ""
}${
event.actions?.length > 0
? ` from action_ids ${event.actions
.map((action) => action.action_id)
.join(", ")}`
: ""
}`,
ts: Date.now(),
},
);
},
sampleEmit,
};