Giter Club home page Giter Club logo

speedybot-mini's Introduction

๐Ÿ“š 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

speedybot-mini's People

Contributors

valgaze avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

speedybot-mini's Issues

Test

Current problem

test

image

Attempted solution

Test

Speedybot Version

2.0.3

Other remarks?

Test leaving off version

hotsheet

  • make api docs more useful/cool
  • video: lambda from scratch to bot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.