Skip to content

Commit ce1e301

Browse files
committed
fix: bug and usability fixes in slack app wizard (#78)
* fix: bug and usability fixes in slack app wizard * chore: version 1.1.14
1 parent 2379f3c commit ce1e301

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

packages/blink/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blink",
3-
"version": "1.1.13",
3+
"version": "1.1.14",
44
"description": "Blink is a JavaScript runtime for building and deploying AI agents.",
55
"type": "module",
66
"bin": {

packages/blink/src/cli/init.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ export default async function init(directory?: string): Promise<void> {
4747

4848
const templateChoice = await select({
4949
options: [
50-
{
51-
label: "Scratch",
52-
value: "scratch",
53-
hint: "Basic agent with example tool",
54-
},
5550
{
5651
label: "Slack Bot",
5752
value: "slack-bot",
5853
hint: "Pre-configured Slack bot",
5954
},
55+
{
56+
label: "Scratch",
57+
value: "scratch",
58+
hint: "Basic agent with example tool",
59+
},
6060
],
6161
message: "Which template do you want to use?",
6262
});
@@ -140,6 +140,8 @@ export default async function init(directory?: string): Promise<void> {
140140
// Log a newline which makes it look a bit nicer.
141141
console.log("");
142142

143+
let exitProcessManually = false;
144+
143145
// Set up Slack app if using slack-bot template
144146
if (template === "slack-bot") {
145147
const shouldCreateSlackApp = await confirm({
@@ -155,6 +157,9 @@ export default async function init(directory?: string): Promise<void> {
155157
name,
156158
packageManager,
157159
});
160+
// the devhook takes a while to clean up, so we exit the process
161+
// manually
162+
exitProcessManually = true;
158163
}
159164

160165
console.log("");
@@ -171,4 +176,8 @@ export default async function init(directory?: string): Promise<void> {
171176
172177
${runDevCommand ?? "blink dev"}`);
173178
outro("Edit agent.ts to hot-reload your agent.");
179+
180+
if (exitProcessManually) {
181+
process.exit(0);
182+
}
174183
}

packages/blink/src/cli/setup-slack-app.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ export async function setupSlackApp(
195195
let botToken = "";
196196
let dmReceived = false;
197197
let dmChannel = "";
198+
let dmTimestamp = "";
198199
let signatureFailureDetected = false;
199200
let lastFailedChannel: string | undefined;
200201

@@ -261,6 +262,7 @@ export async function setupSlackApp(
261262
) {
262263
dmReceived = true;
263264
dmChannel = payload.event.channel;
265+
dmTimestamp = payload.event.ts;
264266
}
265267

266268
return new Response("OK");
@@ -350,15 +352,27 @@ export async function setupSlackApp(
350352
const slackAppUrl = createSlackApp(manifest);
351353

352354
log.info(
353-
`Opening browser to create Slack app...\n\n${chalk.gray(slackAppUrl)}`
355+
`Please visit this URL to create your Slack app and return here after finishing:\n\n${chalk.gray(slackAppUrl)}\n`
354356
);
355357

356-
try {
357-
await open(slackAppUrl);
358-
} catch (error) {
359-
log.warn(
360-
`Could not automatically open browser. Please visit the URL manually.`
361-
);
358+
const shouldOpen = await confirm({
359+
message: "Open this URL in your browser automatically?",
360+
initialValue: true,
361+
});
362+
363+
if (isCancel(shouldOpen)) {
364+
log.warn("Skipping Slack app setup");
365+
return;
366+
}
367+
368+
if (shouldOpen) {
369+
try {
370+
await open(slackAppUrl);
371+
} catch (error) {
372+
log.warn(
373+
`Could not automatically open browser. Please visit the URL manually.`
374+
);
375+
}
362376
}
363377

364378
// Ask for app ID
@@ -379,7 +393,7 @@ export async function setupSlackApp(
379393

380394
// Ask for signing secret with direct link
381395
signingSecret = (await password({
382-
message: `Paste your Signing Secret from https://api.slack.com/apps/${appId}/general:`,
396+
message: `Paste your Signing Secret from the same page:`,
383397
validate: (value) => {
384398
if (!value || value.trim().length === 0) {
385399
return "Signing secret is required";
@@ -396,7 +410,7 @@ export async function setupSlackApp(
396410
let tokenValid = false;
397411
while (!tokenValid) {
398412
botToken = (await password({
399-
message: `Paste your Bot Token from https://api.slack.com/apps/${appId}/install-on-team:`,
413+
message: `Install your app and paste your Bot Token from ${chalk.cyan(`https://api.slack.com/apps/${appId}/install-on-team`)}:`,
400414
validate: (value) => {
401415
if (!value || value.trim().length === 0) {
402416
return "Bot token is required";
@@ -479,7 +493,7 @@ export async function setupSlackApp(
479493

480494
// Prompt user to re-enter the signing secret
481495
const newSigningSecret = await password({
482-
message: `The signing secret appears to be incorrect. Please paste the correct Signing Secret from https://api.slack.com/apps/${appId}/general:`,
496+
message: `The signing secret appears to be incorrect. Please paste the correct Signing Secret from ${chalk.cyan(`https://api.slack.com/apps/${appId}/general`)}:`,
483497
validate: (value) => {
484498
if (!value || value.trim().length === 0) {
485499
return "Signing secret is required";
@@ -517,6 +531,7 @@ export async function setupSlackApp(
517531
},
518532
body: JSON.stringify({
519533
channel: dmChannel,
534+
thread_ts: dmTimestamp,
520535
text: `Congrats, your app is now installed and ready to use! Run \`${runDevCommand}\` to use your agent.`,
521536
}),
522537
});
@@ -537,4 +552,8 @@ export default async function setupSlackAppCommand(
537552
intro("Setting up Slack app");
538553

539554
await setupSlackApp(directory);
555+
556+
// the devhook takes a while to clean up, so we exit the process
557+
// manually
558+
process.exit(0);
540559
}

0 commit comments

Comments
 (0)