Skip to content

Invisible and indispensable conversation design tooling (serverless bots)

License

Notifications You must be signed in to change notification settings

valgaze/speedybot-mini

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

32 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š API Docs | πŸš€ Quickstarts | πŸ’¬ Get Help

npm version

Speedybot-mini

Speedybot is a tool to take you from zero to a user-valuable bot as quickly as possible w/ a buttery-smooth developer experience. In short, Speedybot lets you focus on the stuff that actually matters-- content and powerful integrations.

If you're in a hurry, see the quickstarts to get up and running fast on a variety of infrastructure (websockets, server, serverless, container-less, etc).

The era of manually writing "handlers" or matching text with RegEx's is coming to an end (though Speedybot has several trick to make writing those easier). In the future, there will be far fewer "keyword" handlers and instead deeper integration with 3rd-party conversation services like Voiceflow, Amazon Lex, DialogFlow and Speedybot can help make that transition as smooth as possible

Quickstarts

You can get up and running FAST with Speedybot. Speedybot can run on a variety of architectures and environments

Platform Needs server? Needs webhooks?
πŸ”Œ Deploy with websockets ❌ ❌
πŸ’» Deploy to Simple Express Server βœ… βœ…
Ξ» Deploy to AWS Lamda ❌ βœ…
πŸ”₯ Deploy to Worker ❌ βœ…
πŸ¦– Deploy to Deno ❌ βœ…

Syntax

npm install speedybot-mini

See starter bot

How to make a bot

Keywords

Speedybot is made up of "handlers" that trigger based on special conditions-- depending on your needs you'll probably need only one or two in your project

Keyword Description
.contains This will match if a trigger phrase is the 1st or only word in a message sent from a user
.fuzzy This will match if a trigger phrase exists anywhere inside a message sent from the user
.exact This will match if a trigger phrase is exactly (case-sensitve) a message sent from a user
.fuzzy This will match if a message sent from a user passes the regex
.every This will match on every message from a user
.nlu This will match on every message from a user except if the trigger phrase is used by hard-coded handler, designed for use with natural language systems
.onSubmit This will trigger when data is sent from an
.onFile This will trigger every time a file is sent to the agent and will provide file meta data
.onCamera This will trigger every time an image file sent to the agent
.noMatch This will trigger if there are no registered handlers for the user's text
Note on Precedence

Rule: the 1st registered handler will match in the event of a conflict

Ex. Below since it was set first, fuzzy will take precedence over contains

import { Speedybot, Config } from "speedybot-mini";

const botConfig: Config = {
  token: "__REPLACE__ME__",
};

// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(botConfig);

CultureBot.fuzzy("hi", ($bot, msg) => {
  $bot.send("Fuzzy launched");
});

CultureBot.contains("hi", ($bot, msg) => {
  $bot.send("Contains launched");
});

See the main sample for all you can do, but here's how you could make a simple agent

import { Speedybot } from "speedybot-mini";

// In a production environment use a secrets manager to pass in token
// Get a token: https://developer.webex.com/my-apps/new/bot
const botConfig = { token: "__REPLACE__ME__" };

// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(botConfig);

// 2) Export your bot
export default CultureBot;

// 3) Do whatever you want!

// Match handlers based on user input
CultureBot.contains(["hi", "yo", "hola"], async ($bot, msg) => {
  $bot.send(`You said '${msg.text}', ${msg.author.displayName}!`);
  $bot.send(
    $bot
      .card({
        title: `Hi ${msg.author.displayName}!`,
        subTitle: `Glad to have you here, you said ${msg.text}`,
        chips: ["ping", "pong"],
      })
      .setInput(`What's on your mind?`)
  );
});

// Can also do Regex's
CultureBot.regex(new RegExp("x"), ($bot, msg) => {
  $bot.send(`Regex matched on this text:  ${msg.text}`);
});

// Special keywords: .onSubmit, .onFile, .onCamera, .every, .noMatch, etc

// Handle AdpativeCard submissions
CultureBot.onSubmit(($bot, msg) => {
  $bot.send(`You submitted ${JSON.stringify(msg.data.inputs)}`);
});

// Runs on file upload, can pass bytes to 3rd-party service
CultureBot.onFile(async ($bot, msg, fileData) => {
  $bot.send(`You uploaded '${fileData.fileName}'`);
  $bot.send(`snip: ${fileData.markdownSnippet}`);
  $bot.send(fileData.data);
}).config({ matchText: true });

// Runs on EVERY input, kinda like middleware
// This is where you would interact with an NLU service like DialogFlow, Amazon Lex, Voiceflow, etc
CultureBot.every(async ($bot, msg) => {
  const { text } = msg;
  $bot.log(`.every handler ran with this text: '${text}'`);
}).config({
  skipList: ["$clear"],
});

// If no matched handlers
CultureBot.noMatch(($bot, msg) => {
  $bot.say(`Bummer, there was no matching handler for '${msg.text}'`);
});

There's much more, see this sample for all you can do

SpeedyCard

ex. Tell the bot "sendcard" to get a card, type into the card & tap submit, catch submission using <@submit> and echo back to user.

sb

(Tap to see code)
import { Speedybot } from "speedybot-mini";

// In a production environment use a secrets manager to pass in token
// Get a token: https://developer.webex.com/my-apps/new/bot
const botConfig = { token: "__REPLACE__ME__" };

// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(botConfig);

// 2) Export your bot
export default CultureBot;

// 3) Do whatever you want!
// Match handlers based on user input like
CultureBot.contains("hi", async ($bot, msg) => {
  $bot.send(`You said '${msg.text}', ${msg.author.displayName}!`);
});

// Handle/capture AdpativeCard submissions
CultureBot.onSubmit(($bot, msg) => {
  $bot.send(`You submitted ${JSON.stringify(msg.data.inputs)}`);
});

// send a card

CultureBot.contains("sendcard", async ($bot, msg) => {
  const cardPayload = $bot
    .card()
    .setTitle("System is πŸ‘")
    .setSubtitle("If you see this card, everything is working")
    .setImage("https://i.imgur.com/SW78JRd.jpg")
    .setInput(`What's on your mind?`)
    .setTable([[`Bot's Time`, new Date().toTimeString()]])
    .setData({ mySpecialData: { a: 1, b: 2 } })
    .setUrl(
      "https://www.youtube.com/watch?v=3GwjfUFyY6M",
      "Take a moment to celebrate"
    );
});

Chips

ex. Tell the bot "chips" to get a card with tappable "chips"

sb

(Tap to see code)
import { Speedybot } from "speedybot-mini";

// In a production environment use a secrets manager to pass in token
// Get a token: https://developer.webex.com/my-apps/new/bot
const botConfig = { token: "__REPLACE__ME__" };

// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(botConfig);

// 2) Export your bot
export default CultureBot;

// 3) Do whatever you want!
// Match handlers based on user input like
CultureBot.contains("hi", async ($bot, msg) => {
  $bot.send(`You said '${msg.text}', ${msg.author.displayName}!`);
});

// Handle/capture AdpativeCard submissions (non-chip submission)
CultureBot.onSubmit(($bot, msg) => {
  $bot.send(`You submitted ${JSON.stringify(msg.data.inputs)}`);
});

CultureBot.contains(["ping", "pong"], ($bot, msg) => {
  const { text } = msg;
  if (text === "ping") {
    $bot.send("pong");
  } else if (text === "pong") {
    $bot.send("ping");
  }
});

// send a card with tappable chips

CultureBot.contains("chips", async ($bot, msg) => {
  $bot.send(
    $bot
      .card()
      .setChips([
        "hey",
        "ping",
        { label: "say the phrase pong", keyword: "pong" },
      ])
  );
});

Credits/Attribution