Skip to content

speedybot / Exports / SpeedyBot

Class: SpeedyBot<S>

Type parameters

NameType
Sextends string = string

Table of contents

Constructors

Methods

Constructors

constructor

new SpeedyBot<S>(_token?, makeRequest?)

Type parameters

NameType
Sextends string = string

Parameters

NameTypeDefault value
_tokenstring""
makeRequestCoreMakerequest<unknown>mainRequester

Defined in

speedybot.ts:55

Methods

Setup

Setup(url, secret): Promise<[Webhook, Webhook]>

Create firehose and attachmentActions webhooks

Parameters

NameType
urlstring
secretstring

Returns

Promise<[Webhook, Webhook]>

Defined in

speedybot.ts:932


addSecret

addSecret(key, value): void

Parameters

NameType
keyS
valuestring | number

Returns

void

Defined in

speedybot.ts:69


addSecrets

addSecrets(payload): void

Parameters

NameType
payloadObject

Returns

void

Defined in

speedybot.ts:73


addStep

addStep<T>(middleware): void

Core part of SpeedyBot Listener, it MUST return $.next (continues chain) or $.end

The $ parameter's $.send and $.reply methods will be autobound to incoming message

ts
const Bot = new SpeedyBot();
Bot.addStep(async ($) => {
 await Bot.sendTo($.author.email, "my message");
 const parentMessageID = $.id;
 await Bot.replyTo(parentMessageID, $.author.email, "my great reply message");
 await $.send("Hello the right person");
 await $.reply("Reply to the right message");
 return $.next;
});

Type parameters

NameType
TAttachedData

Parameters

NameType
middlewareMiddleware<T>

Returns

void

Defined in

speedybot.ts:154


addStepSequence

addStepSequence<T>(middlewares): void

Type parameters

NameType
TAttachedData

Parameters

NameType
middlewaresMiddleware<T>[]

Returns

void

Defined in

speedybot.ts:158


appCard

appCard(appName, logoUrl, config?): SpeedyCard

Parameters

NameType
appNamestring
logoUrlstring
configOmit<HeaderConfig, "iconURL">

Returns

SpeedyCard

Defined in

speedybot.ts:1425


captureError

captureError(func): void

Parameters

NameType
func(e: SpeedyError) => unknown

Returns

void

Defined in

speedybot.ts:247


card

card(config?): SpeedyCard

Convenience helper that creates a SpeedyCard

cards

ts
import { SpeedyBot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new SpeedyBot('tokenPlaceholder');

// 2) Export your bot
export default CultureBot;

// 3) Do whatever you want!

CultureBot.contains(["hi", "hey"],
 async ($bot, msg) => {
  const cardData = $bot.card({
    title: "SpeedyBot Hub",
    subTitle: "Sign the paperwork",
    chips: ["ping", "pong", "hi",],
    image: "https://github.com/valgaze/speedybot-mini/raw/deploy/docs/assets/logo.png?raw=true",
    url: "https://github.com/valgaze/speedybot-mini"
  });
  $bot.send(cardData);
 })

Parameters

NameType
config?Partial<AbbreviatedSpeedyCard & { label: string }>

Returns

SpeedyCard

Defined in

speedybot.ts:710


checkAuthor

Private checkAuthor(authorObj): Promise<boolean>

Parameters

NameType
authorObjSelfData

Returns

Promise<boolean>

Defined in

speedybot.ts:1024


contains

contains(keyword, cb): void

Performs a case-insensitive check to determine if the input text contains the specified keyword or a list of supplied words. If a match is found, the provided middleware function is executed.

Parameters

NameTypeDescription
keywordstring | string[]The keyword or array of keywords to check for in the input text.
cbMiddleware<AttachedData>The middleware function to be executed if a match is found.

Returns

void

Defined in

speedybot.ts:223


convertToHash

convertToHash(arr): Object

Convert a list of pairs into an object for secrets consumption.

example

typescript
const input: string[] = ['secret1=value1', 'secret2=value2', 'secret3=value3'];
const output = convertToHash(input);
console.log(output);
// Output:
// {
//   secret1: 'value1',
//   secret2: 'value2',
//   secret3: 'value3'
// }

Parameters

NameTypeDescription
arrstring[]The list of pairs to convert.

Returns

Object

The converted object.

Defined in

speedybot.ts:1417


createWebhook

createWebhook(payload): Promise<Webhook>

Parameters

NameType
payloadObject
payload.eventstring
payload.namestring
payload.resourcestring
payload.secret?string
payload.targetUrlstring

Returns

Promise<Webhook>

Defined in

speedybot.ts:1008


deleteMessage

deleteMessage(msgId): Promise<unknown>

Parameters

NameType
msgIdstring

Returns

Promise<unknown>

Defined in

speedybot.ts:857


deleteWebhook

deleteWebhook(webhookId): Promise<void>

Parameters

NameType
webhookIdstring

Returns

Promise<void>

Defined in

speedybot.ts:870


detectType

Private detectType(envelope): MessageTypes

Parameters

NameType
envelopeENVELOPES

Returns

MessageTypes

Defined in

speedybot.ts:842


editMessage

editMessage(roomId, messageId, message): Promise<MessageResponse>

Edit a message

Parameters

NameType
roomIdstring
messageIdstring
messagestring

Returns

Promise<MessageResponse>

Defined in

speedybot.ts:792


errorCard

errorCard(title, message): SpeedyCard

Parameters

NameType
titlestring
messagestring

Returns

SpeedyCard

Defined in

speedybot.ts:775


exact

exact(keyword, cb): void

Performs a case-sensitive match to check if the input text exactly matches the specified keyword. If there is a match, the provided middleware function is executed.

Parameters

NameTypeDescription
keywordstringThe keyword to match against the input text.
cbMiddleware<AttachedData>The middleware function to be executed if there is a match.

Returns

void

Defined in

speedybot.ts:205


extractFiledata

Private extractFiledata(res): Object

Parameters

NameType
resStubbedRes<unknown>

Returns

Object

NameType
bytesnumber
contentTypestring
extensionstring
namestring

Defined in

speedybot.ts:1298


fetchWebhooks

fetchWebhooks(): Promise<{ id: string ; name: string ; resource: string ; targetUrl: string }[]>

Return abbreviated array of webhook data

Returns

Promise<{ id: string ; name: string ; resource: string ; targetUrl: string }[]>

Defined in

speedybot.ts:905


fuzzyMatch

fuzzyMatch(candidate, options): boolean

Utility to traverse Link headers for pagination, built-in back-off

Parameters

NameType
candidatestring
optionsstring[]

Returns

boolean

Defined in

speedybot.ts:1393


generateFileName

Private generateFileName(): string

Returns

string

Defined in

speedybot.ts:1138


getFile

getFile(url, opts?): Promise<SpeedyFile & { data: unknown }>

Parameters

NameType
urlstring
optsObject
opts.responseType?"arraybuffer" | "json"

Returns

Promise<SpeedyFile & { data: unknown }>

Defined in

speedybot.ts:1242


getPerson

getPerson(personId): Promise<SelfData>

Parameters

NameType
personIdstring

Returns

Promise<SelfData>

Defined in

speedybot.ts:1075


getRecentRooms

getRecentRooms(limit?): Promise<{ id: string ; title: string ; type: string }[]>

Parameters

NameTypeDefault value
limitnumber100

Returns

Promise<{ id: string ; title: string ; type: string }[]>

Defined in

speedybot.ts:941


getRoom

getRoom(roomId): Promise<Room_Details>

Parameters

NameType
roomIdstring

Returns

Promise<Room_Details>

Defined in

speedybot.ts:1089


getSecret

getSecret(key): undefined | string | number

Parameters

NameType
keyS

Returns

undefined | string | number

Defined in

speedybot.ts:77


getSelf

getSelf(token?): Promise<SelfData>

Parameters

NameType
token?string

Returns

Promise<SelfData>

Defined in

speedybot.ts:1030


getToken

getToken(): string

Returns

string

Defined in

speedybot.ts:107


getWebhooks

getWebhooks(): Promise<{ items: Webhook[] }>

Return array of full webhook data

Returns

Promise<{ items: Webhook[] }>

Defined in

speedybot.ts:887


insertStepToFront

insertStepToFront(middleware): void

Parameters

NameType
middlewareMiddleware<AttachedData>

Returns

void

Defined in

speedybot.ts:115


onCamera

onCamera(cb, formats?): void

Shorthand-handler for files w/ image types

For use w/ vision + text prompting systems

Parameters

NameTypeDefault value
cbMiddleware<AttachedData>undefined
formatsstring[][]

Returns

void

Defined in

speedybot.ts:185


onReject

Private onReject(e): void

Parameters

NameType
eSpeedyError

Returns

void

Defined in

speedybot.ts:241


pickRandom

pickRandom<P>(list): P

Type parameters

Name
P

Parameters

NameType
listP[]

Returns

P

Defined in

speedybot.ts:122

pickRandom<P>(min, max): number

Type parameters

Name
P

Parameters

NameType
minnumber
maxnumber

Returns

number

Defined in

speedybot.ts:123

pickRandom<P>(listOrMin, max?): number | P

Type parameters

Name
P

Parameters

NameType
listOrMinnumber | P[]
max?number

Returns

number | P

Defined in

speedybot.ts:124


rando

rando(): string

Generate a random string of 11 characters (letters + numbers)

Returns

string

Defined in

speedybot.ts:1145


regex

regex(reg, cb): void

Parameters

NameType
regRegExp
cbMiddleware<AttachedData>

Returns

void

Defined in

speedybot.ts:162


replyTo

replyTo(roomIdParam, param2, param3?): Promise<MessageResponse>

Parameters

NameType
roomIdParamstring | MessageResponse
param2undefined | string
param3?string

Returns

Promise<MessageResponse>

Defined in

speedybot.ts:812


runMiddleware

runMiddleware(env, startingCtx?): Promise<boolean>

Main workhorse that takes in a webhook and passes it through provided flows

ts
import

Parameters

NameType
envENVELOPES
startingCtxObject

Returns

Promise<boolean>

Defined in

speedybot.ts:262


sendFileTo

sendFileTo(destination, data, extensionOrFileName, textLabel?, contentType?): Promise<MessageResponse>

Send a file to a destination-- a downloadable file will be generated

At minimum, provide the file data & desired file extension

ts

import { SpeedyBot } from 'speedybot'
const Bot = new SpeedyBot('__REPLACE__ME__')
const myData = { a: 1, b: 2, c: [1,2,3,'hello', 'bonjour']}
$bot.sendFileTo('target@email.com', myData, 'json')

Parameters

NameTypeDefault value
destinationstring | { personId: string }undefined
dataanyundefined
extensionOrFileNamestringundefined
textLabelstring""
contentTypenull | stringnull

Returns

Promise<MessageResponse>

Defined in

speedybot.ts:1186


sendTo

sendTo(emailOrRoomId, message): Promise<MessageResponse>

Send a message to a room, email, or personId

ts

import { SpeedyBot } from 'speedybot'
// 1) Initialize your bot w/ config
const Bot = new SpeedyBot({ token: '__REPLACE__ME__'});

Bot.sendTo('targetEmail@account.com', '**here is a message**')
Bot.sendTo('aaa-bbb-ccc-ddd-eee-fff', '**Here is a message to a room**')
Bot.sendTo({toPersonId: 'xxxyyyzzz', '**here is a message**')

Parameters

NameType
emailOrRoomIdstring | { personId: string }
messageMessage

Returns

Promise<MessageResponse>

Defined in

speedybot.ts:624


setFallbackText

setFallbackText(t): void

Parameters

NameType
tstring

Returns

void

Defined in

speedybot.ts:111


setToken

setToken(token): SpeedyBot<S>

Sets the token to transact with APIs (needed to send messages, receive webhooks, files, etc)

Parameters

NameType
tokenstring

Returns

SpeedyBot<S>

Defined in

speedybot.ts:102


stashCard

stashCard(secret, message?, unwrapLabel?, destroyLabel?): SpeedyCard

Parameters

NameTypeDefault value
secretstring | numberundefined
message?stringundefined
unwrapLabelstringCONSTANTS.unwrapLabel
destroyLabelstringCONSTANTS.destroyLabel

Returns

SpeedyCard

Defined in

speedybot.ts:764


successCard

successCard(title, message): SpeedyCard

Parameters

NameType
titlestring
messagestring

Returns

SpeedyCard

Defined in

speedybot.ts:782


validateToken

validateToken(token): Promise<boolean>

Parameters

NameType
tokenstring

Returns

Promise<boolean>

Defined in

speedybot.ts:667


whoAmI

whoAmI(): Promise<SelfData & { webhooks: Webhook[] }>

Returns

Promise<SelfData & { webhooks: Webhook[] }>

Defined in

speedybot.ts:1044