speedybot / Exports / SpeedyBot
Class: SpeedyBot<S>
Type parameters
Name | Type |
---|---|
S | extends string = string |
Table of contents
Constructors
Methods
- Setup
- addSecret
- addSecrets
- addStep
- addStepSequence
- appCard
- captureError
- card
- checkAuthor
- contains
- convertToHash
- createWebhook
- deleteMessage
- deleteWebhook
- detectType
- editMessage
- errorCard
- exact
- extractFiledata
- fetchWebhooks
- fuzzyMatch
- generateFileName
- getFile
- getPerson
- getRecentRooms
- getRoom
- getSecret
- getSelf
- getToken
- getWebhooks
- insertStepToFront
- onCamera
- onReject
- pickRandom
- rando
- regex
- replyTo
- runMiddleware
- sendFileTo
- sendTo
- setFallbackText
- setToken
- stashCard
- successCard
- validateToken
- whoAmI
Constructors
constructor
• new SpeedyBot<S
>(_token?
, makeRequest?
)
Type parameters
Name | Type |
---|---|
S | extends string = string |
Parameters
Name | Type | Default value |
---|---|---|
_token | string | "" |
makeRequest | CoreMakerequest <unknown > | mainRequester |
Defined in
Methods
Setup
▸ Setup(url
, secret
): Promise
<[Webhook
, Webhook
]>
Create firehose and attachmentActions webhooks
Parameters
Name | Type |
---|---|
url | string |
secret | string |
Returns
Promise
<[Webhook
, Webhook
]>
Defined in
addSecret
▸ addSecret(key
, value
): void
Parameters
Name | Type |
---|---|
key | S |
value | string | number |
Returns
void
Defined in
addSecrets
▸ addSecrets(payload
): void
Parameters
Name | Type |
---|---|
payload | Object |
Returns
void
Defined in
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
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
Name | Type |
---|---|
T | AttachedData |
Parameters
Name | Type |
---|---|
middleware | Middleware <T > |
Returns
void
Defined in
addStepSequence
▸ addStepSequence<T
>(middlewares
): void
Type parameters
Name | Type |
---|---|
T | AttachedData |
Parameters
Name | Type |
---|---|
middlewares | Middleware <T >[] |
Returns
void
Defined in
appCard
▸ appCard(appName
, logoUrl
, config?
): SpeedyCard
Parameters
Name | Type |
---|---|
appName | string |
logoUrl | string |
config | Omit <HeaderConfig , "iconURL" > |
Returns
Defined in
captureError
▸ captureError(func
): void
Parameters
Name | Type |
---|---|
func | (e : SpeedyError ) => unknown |
Returns
void
Defined in
card
▸ card(config?
): SpeedyCard
Convenience helper that creates a SpeedyCard
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
Name | Type |
---|---|
config? | Partial <AbbreviatedSpeedyCard & { label : string }> |
Returns
Defined in
checkAuthor
▸ Private
checkAuthor(authorObj
): Promise
<boolean
>
Parameters
Name | Type |
---|---|
authorObj | SelfData |
Returns
Promise
<boolean
>
Defined in
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
Name | Type | Description |
---|---|---|
keyword | string | string [] | The keyword or array of keywords to check for in the input text. |
cb | Middleware <AttachedData > | The middleware function to be executed if a match is found. |
Returns
void
Defined in
convertToHash
▸ convertToHash(arr
): Object
Convert a list of pairs into an object for secrets consumption.
example
const input: string[] = ['secret1=value1', 'secret2=value2', 'secret3=value3'];
const output = convertToHash(input);
console.log(output);
// Output:
// {
// secret1: 'value1',
// secret2: 'value2',
// secret3: 'value3'
// }
Parameters
Name | Type | Description |
---|---|---|
arr | string [] | The list of pairs to convert. |
Returns
Object
The converted object.
Defined in
createWebhook
▸ createWebhook(payload
): Promise
<Webhook
>
Parameters
Name | Type |
---|---|
payload | Object |
payload.event | string |
payload.name | string |
payload.resource | string |
payload.secret? | string |
payload.targetUrl | string |
Returns
Promise
<Webhook
>
Defined in
deleteMessage
▸ deleteMessage(msgId
): Promise
<unknown
>
Parameters
Name | Type |
---|---|
msgId | string |
Returns
Promise
<unknown
>
Defined in
deleteWebhook
▸ deleteWebhook(webhookId
): Promise
<void
>
Parameters
Name | Type |
---|---|
webhookId | string |
Returns
Promise
<void
>
Defined in
detectType
▸ Private
detectType(envelope
): MessageTypes
Parameters
Name | Type |
---|---|
envelope | ENVELOPES |
Returns
MessageTypes
Defined in
editMessage
▸ editMessage(roomId
, messageId
, message
): Promise
<MessageResponse
>
Edit a message
Parameters
Name | Type |
---|---|
roomId | string |
messageId | string |
message | string |
Returns
Promise
<MessageResponse
>
Defined in
errorCard
▸ errorCard(title
, message
): SpeedyCard
Parameters
Name | Type |
---|---|
title | string |
message | string |
Returns
Defined in
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
Name | Type | Description |
---|---|---|
keyword | string | The keyword to match against the input text. |
cb | Middleware <AttachedData > | The middleware function to be executed if there is a match. |
Returns
void
Defined in
extractFiledata
▸ Private
extractFiledata(res
): Object
Parameters
Name | Type |
---|---|
res | StubbedRes <unknown > |
Returns
Object
Name | Type |
---|---|
bytes | number |
contentType | string |
extension | string |
name | string |
Defined in
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
fuzzyMatch
▸ fuzzyMatch(candidate
, options
): boolean
Utility to traverse Link headers for pagination, built-in back-off
Parameters
Name | Type |
---|---|
candidate | string |
options | string [] |
Returns
boolean
Defined in
generateFileName
▸ Private
generateFileName(): string
Returns
string
Defined in
getFile
▸ getFile(url
, opts?
): Promise
<SpeedyFile
& { data
: unknown
}>
Parameters
Name | Type |
---|---|
url | string |
opts | Object |
opts.responseType? | "arraybuffer" | "json" |
Returns
Promise
<SpeedyFile
& { data
: unknown
}>
Defined in
getPerson
▸ getPerson(personId
): Promise
<SelfData
>
Parameters
Name | Type |
---|---|
personId | string |
Returns
Promise
<SelfData
>
Defined in
getRecentRooms
▸ getRecentRooms(limit?
): Promise
<{ id
: string
; title
: string
; type
: string
}[]>
Parameters
Name | Type | Default value |
---|---|---|
limit | number | 100 |
Returns
Promise
<{ id
: string
; title
: string
; type
: string
}[]>
Defined in
getRoom
▸ getRoom(roomId
): Promise
<Room_Details
>
Parameters
Name | Type |
---|---|
roomId | string |
Returns
Promise
<Room_Details
>
Defined in
getSecret
▸ getSecret(key
): undefined
| string
| number
Parameters
Name | Type |
---|---|
key | S |
Returns
undefined
| string
| number
Defined in
getSelf
▸ getSelf(token?
): Promise
<SelfData
>
Parameters
Name | Type |
---|---|
token? | string |
Returns
Promise
<SelfData
>
Defined in
getToken
▸ getToken(): string
Returns
string
Defined in
getWebhooks
▸ getWebhooks(): Promise
<{ items
: Webhook
[] }>
Return array of full webhook data
Returns
Promise
<{ items
: Webhook
[] }>
Defined in
insertStepToFront
▸ insertStepToFront(middleware
): void
Parameters
Name | Type |
---|---|
middleware | Middleware <AttachedData > |
Returns
void
Defined in
onCamera
▸ onCamera(cb
, formats?
): void
Shorthand-handler for files w/ image types
For use w/ vision + text prompting systems
Parameters
Name | Type | Default value |
---|---|---|
cb | Middleware <AttachedData > | undefined |
formats | string [] | [] |
Returns
void
Defined in
onReject
▸ Private
onReject(e
): void
Parameters
Name | Type |
---|---|
e | SpeedyError |
Returns
void
Defined in
pickRandom
▸ pickRandom<P
>(list
): P
Type parameters
Name |
---|
P |
Parameters
Name | Type |
---|---|
list | P [] |
Returns
P
Defined in
▸ pickRandom<P
>(min
, max
): number
Type parameters
Name |
---|
P |
Parameters
Name | Type |
---|---|
min | number |
max | number |
Returns
number
Defined in
▸ pickRandom<P
>(listOrMin
, max?
): number
| P
Type parameters
Name |
---|
P |
Parameters
Name | Type |
---|---|
listOrMin | number | P [] |
max? | number |
Returns
number
| P
Defined in
rando
▸ rando(): string
Generate a random string of 11 characters (letters + numbers)
Returns
string
Defined in
regex
▸ regex(reg
, cb
): void
Parameters
Name | Type |
---|---|
reg | RegExp |
cb | Middleware <AttachedData > |
Returns
void
Defined in
replyTo
▸ replyTo(roomIdParam
, param2
, param3?
): Promise
<MessageResponse
>
Parameters
Name | Type |
---|---|
roomIdParam | string | MessageResponse |
param2 | undefined | string |
param3? | string |
Returns
Promise
<MessageResponse
>
Defined in
runMiddleware
▸ runMiddleware(env
, startingCtx?
): Promise
<boolean
>
Main workhorse that takes in a webhook and passes it through provided flows
import
Parameters
Name | Type |
---|---|
env | ENVELOPES |
startingCtx | Object |
Returns
Promise
<boolean
>
Defined in
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
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
Name | Type | Default value |
---|---|---|
destination | string | { personId : string } | undefined |
data | any | undefined |
extensionOrFileName | string | undefined |
textLabel | string | "" |
contentType | null | string | null |
Returns
Promise
<MessageResponse
>
Defined in
sendTo
▸ sendTo(emailOrRoomId
, message
): Promise
<MessageResponse
>
Send a message to a room, email, or personId
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
Name | Type |
---|---|
emailOrRoomId | string | { personId : string } |
message | Message |
Returns
Promise
<MessageResponse
>
Defined in
setFallbackText
▸ setFallbackText(t
): void
Parameters
Name | Type |
---|---|
t | string |
Returns
void
Defined in
setToken
▸ setToken(token
): SpeedyBot
<S
>
Sets the token to transact with APIs (needed to send messages, receive webhooks, files, etc)
Parameters
Name | Type |
---|---|
token | string |
Returns
SpeedyBot
<S
>
Defined in
stashCard
▸ stashCard(secret
, message?
, unwrapLabel?
, destroyLabel?
): SpeedyCard
Parameters
Name | Type | Default value |
---|---|---|
secret | string | number | undefined |
message? | string | undefined |
unwrapLabel | string | CONSTANTS.unwrapLabel |
destroyLabel | string | CONSTANTS.destroyLabel |
Returns
Defined in
successCard
▸ successCard(title
, message
): SpeedyCard
Parameters
Name | Type |
---|---|
title | string |
message | string |
Returns
Defined in
validateToken
▸ validateToken(token
): Promise
<boolean
>
Parameters
Name | Type |
---|---|
token | string |
Returns
Promise
<boolean
>
Defined in
whoAmI
▸ whoAmI(): Promise
<SelfData
& { webhooks
: Webhook
[] }>
Returns
Promise
<SelfData
& { webhooks
: Webhook
[] }>