Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions handler/ExecuteViewSubmitHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ExecuteViewSubmitHandler {
private readonly http: IHttp,
private readonly modify: IModify,
private readonly persistence: IPersistence
) {}
) { }

public async run(context: UIKitViewSubmitInteractionContext) {
const { user, view } = context.getInteractionData();
Expand Down Expand Up @@ -47,27 +47,36 @@ export class ExecuteViewSubmitHandler {
private async handleAutomationCreateModal(
context: UIKitViewSubmitInteractionContext
) {
const { user, view } = context.getInteractionData();
let { user, view, room } = context.getInteractionData();

const action = view.state?.["actionBlock"]?.["action"] || "";
const users = view.state?.["usersBlock"]?.["users"] || "";
const channels = view.state?.["channelsBlock"]?.["channels"] || "";
let channels = view.state?.["channelsBlock"]?.["channels"] || "";
const condition = view.state?.["conditionBlock"]?.["condition"] || "";
let response = view.state?.["responseBlock"]?.["response"] || "";

if (action === "delete-message") {
response = "N/A";
}

if (users && channels && condition && action && response) {
if (!room) {
const result = await getRoom(this.read, user.id);
room = result.room as any;
}

if (!channels && room && room.slugifiedName) {
channels = room.slugifiedName;
}

if (condition && action && (response || action === 'delete-message')) {
const command = `When the user @${users} sends a message in the #${channels} channel that includes the phrase "${condition}", then perform the action "${action}" with response '${response}'.`;

const id = await saveTriggerResponse(
this.persistence,
{
command: command,
trigger: {
user: users,
user: users || null,
channel: channels,
condition: condition,
},
Expand All @@ -82,7 +91,6 @@ export class ExecuteViewSubmitHandler {
true
);

const { room, error } = await getRoom(this.read, user.id);
if (room) {
await sendNotification(
this.read,
Expand Down