Skip to content

Commit

Permalink
add exit message
Browse files Browse the repository at this point in the history
  • Loading branch information
valgaze committed Feb 25, 2024
1 parent 642afb4 commit 4229dcd
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 38 deletions.
3 changes: 2 additions & 1 deletion examples/llm-stream/settings/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import "cross-fetch/polyfill";
import { config } from "dotenv";
import { resolve } from "path";
config({ path: resolve(__dirname, "..", ".env") });
import { websocketLauncher } from "./../util";
import { announceExit, websocketLauncher } from "../util";
process.on("exit", announceExit);

import Bot from "./bot";

Expand Down
24 changes: 23 additions & 1 deletion examples/llm-stream/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SpeedyBot, logoRoll } from "speedybot";
import { Websocket } from "./utils";

import { resolve } from "path";
export const websocketLauncher = async (
BotRef: SpeedyBot,
cb?: (data?: { email: string; name?: string }) => any
Expand Down Expand Up @@ -49,3 +49,25 @@ export const announceWebsockets = (email: string, name = "Your bot") => {
}
console.log(`You can reach ${name} here: ${email}`);
};

export const announceExit = (name = "Your bot") => {
const isColorSupported = process.stdout.isTTY;
if (isColorSupported) {
const BOT_DISCONNECTED = `\n\x1b[1m\x1b[7m\x1b[31m 🤖 DISCONNECTED \x1b[0m\x1b[31m Bot is now offline. \x1b[0m`;
process.stdout.write(BOT_DISCONNECTED + "\n");
} else {
console.log("Bot is now offline.");
}
console.log(
`
Your bot is now "off"
You can turn your bot back on by entering the following commands:
cd ${resolve(__dirname, "..")}
npm run dev
If you want to deploy your bot to a persistent server or serverless function, see here: https://speedybot.js.org/examples
`
);
};
3 changes: 2 additions & 1 deletion examples/speedybot-starter/settings/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import "cross-fetch/polyfill";
import { config } from "dotenv";
import { resolve } from "path";
config({ path: resolve(__dirname, "..", ".env") });
import { websocketLauncher } from "../util";
import { announceExit, websocketLauncher } from "../util";
process.on("exit", announceExit);

import Bot from "./bot";

Expand Down
24 changes: 23 additions & 1 deletion examples/speedybot-starter/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SpeedyBot, logoRoll } from "speedybot";
import { Websocket } from "./utils";

import { resolve } from "path";
export const websocketLauncher = async (
BotRef: SpeedyBot,
cb?: (data?: { email: string; name?: string }) => any
Expand Down Expand Up @@ -49,3 +49,25 @@ export const announceWebsockets = (email: string, name = "Your bot") => {
}
console.log(`You can reach ${name} here: ${email}`);
};

export const announceExit = (name = "Your bot") => {
const isColorSupported = process.stdout.isTTY;
if (isColorSupported) {
const BOT_DISCONNECTED = `\n\x1b[1m\x1b[7m\x1b[31m 🤖 DISCONNECTED \x1b[0m\x1b[31m Bot is now offline. \x1b[0m`;
process.stdout.write(BOT_DISCONNECTED + "\n");
} else {
console.log("Bot is now offline.");
}
console.log(
`
Your bot is now "off"
You can turn your bot back on by entering the following commands:
cd ${resolve(__dirname, "..")}
npm run dev
If you want to deploy your bot to a persistent server or serverless function, see here: https://speedybot.js.org/examples
`
);
};
19 changes: 5 additions & 14 deletions examples/voiceflow-kb/settings/launch.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
// npm i cross-fetch dotenv
import "cross-fetch/polyfill";
import { resolve } from "path";
import { config } from "dotenv";
import { resolve } from "path";
config({ path: resolve(__dirname, "..", ".env") });
import { websocketLauncher } from "../util";

// Assert these are available on process.env yadda-yadda, otherwise would have to `process.env.BOT_TOKEN as string`
declare global {
namespace NodeJS {
interface ProcessEnv {
BOT_TOKEN: string;
VOICEFLOW_API_KEY: string;
}
}
}
import { announceExit, websocketLauncher } from "../util";
process.on("exit", announceExit);

import Bot from "./bot";

Bot.setToken(process.env.BOT_TOKEN);
Bot.addSecret("VOICEFLOW_API_KEY", process.env.VOICEFLOW_API_KEY);
Bot.setToken(process.env.BOT_TOKEN as string);

// Pass in your SpeedyBot
websocketLauncher(Bot).catch((e) => console.log("##", e));
27 changes: 24 additions & 3 deletions examples/voiceflow-kb/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SpeedyBot } from "speedybot"; // REPLACE W/ SPEEDYBOT IMPORT
import { logoRoll } from "speedybot"; // REPLACE W/ SPEEDYBOT IMPORT
import { SpeedyBot, logoRoll } from "speedybot";
import { Websocket } from "./utils";

import { resolve } from "path";
export const websocketLauncher = async (
BotRef: SpeedyBot,
cb?: (data?: { email: string; name?: string }) => any
Expand Down Expand Up @@ -50,3 +49,25 @@ export const announceWebsockets = (email: string, name = "Your bot") => {
}
console.log(`You can reach ${name} here: ${email}`);
};

export const announceExit = (name = "Your bot") => {
const isColorSupported = process.stdout.isTTY;
if (isColorSupported) {
const BOT_DISCONNECTED = `\n\x1b[1m\x1b[7m\x1b[31m 🤖 DISCONNECTED \x1b[0m\x1b[31m Bot is now offline. \x1b[0m`;
process.stdout.write(BOT_DISCONNECTED + "\n");
} else {
console.log("Bot is now offline.");
}
console.log(
`
Your bot is now "off"
You can turn your bot back on by entering the following commands:
cd ${resolve(__dirname, "..")}
npm run dev
If you want to deploy your bot to a persistent server or serverless function, see here: https://speedybot.js.org/examples
`
);
};
19 changes: 5 additions & 14 deletions examples/voiceflow/settings/launch.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
// npm i cross-fetch dotenv
import "cross-fetch/polyfill";
import { resolve } from "path";
import { config } from "dotenv";
import { resolve } from "path";
config({ path: resolve(__dirname, "..", ".env") });
import { websocketLauncher } from "../util";

// Assert these are available on process.env yadda-yadda, otherwise would have to `process.env.BOT_TOKEN as string`
declare global {
namespace NodeJS {
interface ProcessEnv {
BOT_TOKEN: string;
VOICEFLOW_API_KEY: string;
}
}
}
import { announceExit, websocketLauncher } from "../util";
process.on("exit", announceExit);

import Bot from "./bot";

Bot.setToken(process.env.BOT_TOKEN);
Bot.addSecret("VOICEFLOW_API_KEY", process.env.VOICEFLOW_API_KEY);
Bot.setToken(process.env.BOT_TOKEN as string);

// Pass in your SpeedyBot
websocketLauncher(Bot).catch((e) => console.log("##", e));
27 changes: 24 additions & 3 deletions examples/voiceflow/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SpeedyBot } from "speedybot"; // REPLACE W/ SPEEDYBOT IMPORT
import { logoRoll } from "speedybot"; // REPLACE W/ SPEEDYBOT IMPORT
import { SpeedyBot, logoRoll } from "speedybot";
import { Websocket } from "./utils";

import { resolve } from "path";
export const websocketLauncher = async (
BotRef: SpeedyBot,
cb?: (data?: { email: string; name?: string }) => any
Expand Down Expand Up @@ -50,3 +49,25 @@ export const announceWebsockets = (email: string, name = "Your bot") => {
}
console.log(`You can reach ${name} here: ${email}`);
};

export const announceExit = (name = "Your bot") => {
const isColorSupported = process.stdout.isTTY;
if (isColorSupported) {
const BOT_DISCONNECTED = `\n\x1b[1m\x1b[7m\x1b[31m 🤖 DISCONNECTED \x1b[0m\x1b[31m Bot is now offline. \x1b[0m`;
process.stdout.write(BOT_DISCONNECTED + "\n");
} else {
console.log("Bot is now offline.");
}
console.log(
`
Your bot is now "off"
You can turn your bot back on by entering the following commands:
cd ${resolve(__dirname, "..")}
npm run dev
If you want to deploy your bot to a persistent server or serverless function, see here: https://speedybot.js.org/examples
`
);
};

0 comments on commit 4229dcd

Please sign in to comment.