From 0057931a0e009cf40c0b1bb651d60432347e0dc7 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 14 Mar 2024 20:43:25 +0200 Subject: Add user handle to response, small improvements --- src/index.ts | 21 ++++++++++++++++++--- src/instagram_task.ts | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index a485a95..3a48757 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,11 +23,21 @@ app.command("/veeti", async ({ command, ack, respond, client }) => { const url = command.text.trim(); if (!url.includes("instagram.com")) { - respond("Only instagram.com URLs are supported"); + void respond({ + text: "Only instagram.com URLs are supported at the moment", + response_type: "ephemeral", + }); return; } - const respondWithFile = async (message: string, filePath: string) => { + // send a message only visible to the user who sent the command + void respond({ + text: "Sharing instagram video, this can take a minute...", + thread_ts: command.ts, + response_type: "ephemeral", + }); + + const respondWithFile = async (filePath: string) => { try { console.log("Uploading file", filePath); const fileContent = fs.readFileSync(filePath); @@ -36,13 +46,18 @@ app.command("/veeti", async ({ command, ack, respond, client }) => { console.log("Sending message to channel", command.channel_id); await client.filesUploadV2({ channel_id: command.channel_id, - initial_comment: message, + initial_comment: `By: @${command.user_name}`, file: fileContent, filename: fileName, }); console.log("Success"); } catch (e) { console.error("Failed to upload file", e); + void respond({ + text: + "Failed to share file, please try again later. Error: " + String(e), + response_type: "ephemeral", + }); } }; diff --git a/src/instagram_task.ts b/src/instagram_task.ts index 7ca0c77..09b82b5 100644 --- a/src/instagram_task.ts +++ b/src/instagram_task.ts @@ -5,7 +5,7 @@ import { wait } from "./utils"; export interface InstagramTask { type: "download_instagram"; url: string; - respondWithFile: (message: string, filePath: string) => Promise; + respondWithFile: (filePath: string) => Promise; } export const runDownloadInstagramTask = async (task: InstagramTask) => { @@ -122,7 +122,7 @@ export const runDownloadInstagramTask = async (task: InstagramTask) => { const downloadedFile = downloadedFiles[0]; - await task.respondWithFile("🗿🗿🗿", `./downloads/${downloadedFile}`); + await task.respondWithFile(`./downloads/${downloadedFile}`); } finally { await page.close(); await browser.close(); -- cgit v1.3