speedybot-mini / Exports / Speedybot
Name | Type |
---|---|
T |
extends string = never |
- IncomingWebhooks
- actionHandler
- addSecret
- addSecrets
- buildDetails
- checkList
- checkStrings
- contains
- deleteMessage
- detectType
- every
- exact
- exposeToken
- fuzzy
- getAuthor
- getData
- getSecret
- getSelf
- getToken
- isEnvelope
- isHuman
- nlu
- noMatch
- onCamera
- onFile
- onSubmit
- peekFile
- processIncoming
- processSubmit
- processText
- regex
- setConfig
- setHandler
- setToken
- setWelcome
• new Speedybot<T
>(config?
, makeRequest?
)
Name | Type |
---|---|
T |
extends string = never |
Name | Type | Default value |
---|---|---|
config? |
string | Config |
undefined |
makeRequest |
CoreMakerequest <any > |
RequesterFunc |
• FileHandler: null
| FileHandlerFunc
<any
> = null
• Private
_config: Config
• Private
handlers: Object
▪ [key: string
]: GenericHandlerFunc
| null
Name | Type |
---|---|
ALL |
null | GenericHandlerFunc <any > |
NO_MATCH |
null | GenericHandlerFunc <any > |
camera |
null | GenericHandlerFunc <any > |
file |
null | GenericHandlerFunc <any > |
submit |
null | GenericHandlerFunc <any > |
• Private
nluHandler: null
| NLUHandlerFunc
<any
> = null
• Private
rootList: RootList
= []
• Private
secrets: Partial
<Secrets
<T
>> = {}
▸ IncomingWebhooks(): Object
Object
Name | Type |
---|---|
card |
(config? : Partial <AbbreviatedSpeedyCard >) => SpeedyCard |
dm |
(personIdOrEmail : string , message : string | string [] | SpeedyCard , fallback? : string ) => Promise <Response > |
dmDataAsFile |
(personIdOrEmail : string , data : any , extensionOrFileName : string , contentType : null , textLabel? : string , overrides : { toPersonEmail? : string ; toPersonId? : string }) => Promise <Response > |
sendRoom |
(roomId : string , message : string | string [] | SpeedyCard ) => Promise <void > |
sendRoomDataAsFile |
(roomId : string , data : any , extensionOrFileName : string , contentType : null , textLabel? : string , overrides : { toPersonEmail? : string ; toPersonId? : string }) => Promise <Response > |
snippet |
(data : any , dataType : string ) => string |
▸ actionHandler(details
): Promise
<void
>
Name | Type |
---|---|
details |
AA_Details |
Promise
<void
>
▸ addSecret<K
>(key
, value
): void
Add a secret to your Speedybot bot instance. Note bot tokens are special are are still set by setToken Note: Once you add a secret it is accessible on the instance so be careful
import { Speedybot } from 'speedybot-mini'
type MySecrets = 'special_token1' | 'special_token2'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot<MySecrets>('__REPLACE__ME__');
// 2) Export your bot
export default CultureBot;
// Add secret (can happen anytime to keep bots portable)
CultureBot.addSecret('special_token1', 'xxx-yyy')
CultureBot.getSecret('special_token1') // 'xxx-yyy'
CultureBot.addSecrets({'special_token2':'aaa-bbb'})
CultureBot.getSecret('special_token2') // 'aaa-bbb'
// 3) Do whatever you want!
CultureBot.contains(["hi", "hey"], async ($bot, msg) => {
$bot.send('This is the hi greeting handler!')
})
CultureBot.contains('trigger', async ($bot, msg) => {
$bot.send('About to trigger the hi trigger')
$bot.trigger('hi', msg)
})
Name | Type |
---|---|
K |
extends string |
Name | Type |
---|---|
key |
K |
value |
string |
void
▸ addSecrets(secrets
): void
Add a several secrets at once to your Speedybot bot instance. Note bot tokens are special are are still set by setToken Note: Once you add a secret it is accessible on the instance so be careful
import { Speedybot } from 'speedybot-mini'
type MySecrets = 'special_token1' | 'special_token2'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot<MySecrets>('__REPLACE__ME__');
// 2) Export your bot
export default CultureBot;
// Add secret (can happen anytime to keep bots portable)
CultureBot.addSecrets({'special_token1': 'xxx-yyy', 'special_token2':'aaa-bbb'})
CultureBot.getSecret('special_token1') // 'xxx-yyy'
CultureBot.getSecret('special_token2') // 'aaa-bbb'
// 3) Do whatever you want!
CultureBot.contains(["hi", "hey"], async ($bot, msg) => {
$bot.send('This is the hi greeting handler!')
})
CultureBot.contains('trigger', async ($bot, msg) => {
$bot.send('About to trigger the hi trigger')
$bot.trigger('hi', msg)
})
Name | Type |
---|---|
secrets |
Partial <Secrets <T >> |
void
▸ buildDetails(type
, envelope
): Promise
<{ author
: SelfData
; details
: Message_Details
| AA_Details
| File_Details
}>
Name | Type |
---|---|
type |
RequestTypes |
envelope |
ENVELOPES |
Promise
<{ author
: SelfData
; details
: Message_Details
| AA_Details
| File_Details
}>
▸ Private
checkList(incoming?
): number
Returns look up index of matching handler if one exists
Name | Type | Default value |
---|---|---|
incoming |
string |
"" |
number
▸ Private
checkStrings(check
, incoming
, flag?
): boolean
Name | Type |
---|---|
check |
string |
incoming |
string |
flag? |
Object |
flag.exact? |
boolean |
flag.fuzzy? |
boolean |
boolean
▸ contains(keyword
, cb
): void
Register a handler thats matches on a string or list of strings
Note: This will match if the target phrase is the 1st or only word in a sentence
Important: If you want to match on the input phrase located anywhere in an input phrase, use .fuzzy. If .fuzzy and .contains contain the same matching word, the first registered handler will take precedence Any fuzzy matches occur anywhere in the input from the user (if you want only the 1st word see .contains)
// This agent will match for ex. hi, hey how's it going, hey
// Will not match: hi!!, heya how are you?
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.contains(["hi", "hey"], async ($bot, msg) => {
$bot.send('You matched!')
})
Name | Type |
---|---|
keyword |
string | string [] |
cb |
MsgHandler |
void
▸ Private
deleteMessage(msgId
): Promise
<any
>
Name | Type |
---|---|
msgId |
string |
Promise
<any
>
▸ detectType(envelope
): RequestTypes
Name | Type |
---|---|
envelope |
ENVELOPES |
RequestTypes
▸ every(handler
, skipList?
): Object
Register a handler that runs on EVERY message sent to an agent Note: You can optionally pass in a list of keywords to skip
// This agent will match for only 'Hi'
// Will not match: hi, hi!!, heya how are you?
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.contains(['bingo', 'bongo'], ($bot, msg) => {
if (msg.text === 'bingo') {
$bot.send('bongo')
} else {
$bot.send('bingo')
}
})
// Run on every input except the words 'bingo' and 'bongo'
CultureBot.every(async ($bot, msg) => {
$bot.send('You matched because you said a word containing x!')
}).config({skipList: ['bingo', 'bongo']})
Name | Type | Default value |
---|---|---|
handler |
MsgHandler |
undefined |
skipList |
string [] |
[] |
Object
Name | Type |
---|---|
config |
(catchallConfig : { skipList? : string [] }) => void |
▸ exact(keyword
, cb
): void
Register a handler thats matches on a string exactly
Note: This will match if the target phrase has a case-sensitive match
// This agent will match for only 'Hi'
// Will not match: hi, hi!!, heya how are you?
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.exact("hi", async ($bot, msg) => {
$bot.send('You matched!')
})
Name | Type |
---|---|
keyword |
string |
cb |
MsgHandler |
void
▸ exposeToken(): string
string
▸ fuzzy(keyword
, cb
): void
Register a handler that "fuzzily" matches input from a user
Any fuzzy matches occur anywhere in the input from the user (if you want only the 1st word see Speedybot.contains)
// This agent will match for ex. hi, hi!!, here is a sentence hi and bye
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.fuzzy(["hi", "hey"], async ($bot, msg) => {
$bot.send('You matched!')
})
Name | Type |
---|---|
keyword |
string | string [] |
cb |
MsgHandler |
void
▸ Private
getAuthor(personId
): Promise
<any
>
Name | Type |
---|---|
personId |
string |
Promise
<any
>
▸ getData(type
, envelope
): Promise
<Message_Details
| AA_Details
| File_Details
>
Name | Type |
---|---|
type |
RequestTypes |
envelope |
ENVELOPES |
Promise
<Message_Details
| AA_Details
| File_Details
>
▸ getSecret<K
>(key
): undefined
| string
Retrieve a secret set on your Speedybot bot instance. Note bot tokens are special are are still set by setToken Note: Once you add a secret it is accessible on the instance so be careful
import { Speedybot } from 'speedybot-mini'
type MySecrets = 'special_token1' | 'special_token2'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot<MySecrets>('__REPLACE__ME__');
// 2) Export your bot
export default CultureBot;
// Add secret (can happen anytime to keep bots portable)
CultureBot.addSecret('special_token1', 'xxx-yyy')
CultureBot.getSecret('special_token1') // 'xxx-yyy'
CultureBot.addSecrets({'special_token2':'aaa-bbb'})
CultureBot.getSecret('special_token2') // 'aaa-bbb'
// 3) Do whatever you want!
CultureBot.contains(["hi", "hey"], async ($bot, msg) => {
$bot.send('This is the hi greeting handler!')
})
CultureBot.contains('trigger', async ($bot, msg) => {
$bot.send('About to trigger the hi trigger')
$bot.trigger('hi', msg)
})
Name | Type |
---|---|
K |
extends string |
Name | Type |
---|---|
key |
K |
undefined
| string
▸ Private
getSelf(): Promise
<SelfData
>
Promise
<SelfData
>
▸ getToken(): string
string
▸ isEnvelope(candidate
): boolean
Name | Type |
---|---|
candidate |
any |
boolean
▸ Private
isHuman(personId
, fullPayload?
): Promise
<boolean
| SelfData
>
Name | Type | Default value |
---|---|---|
personId |
string |
undefined |
fullPayload |
boolean |
false |
Promise
<boolean
| SelfData
>
▸ nlu(cb
): void
🌟SPECIAL🌟 Conversational Design convenience handler
Use this handler to send user input to a NLP/NLU
Any registered keywords handled with your agent will be ignored and not sent to the NLU system
// This agent will match for ping, pong, anything else will be sent to a
// 3rd-party service for content and conversation design
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.contains(["ping","pong"], async ($bot, msg) => {
$bot.send('You matched!')
})
CultureBot.nlu("hi", async ($bot, msg, api) => {
const payload = await api('https://www.nluservice.com', { text: msg.text }, )
const res = await payload.text()
$bot.send(`Response: ${text}`)
})
Name | Type |
---|---|
cb |
NLUHandlerFunc <any > |
void
▸ noMatch(handler
): void
Register a handler when there is no matching handler for a user's input
If you're not using an NLU system, it's a good idea to acknowledge a user's request isn't servicable rather than leaving them hanging
// This agent will match for only 'Hi'
// Will not match: hi, hi!!, heya how are you?
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.noMatch(async ($bot, msg) => {
$bot.send(`Bummer, no match for ${msg.text}`)
})
Name | Type |
---|---|
handler |
MsgHandler |
void
▸ onCamera(handler
): void
Camera handler-- will trigger by default for png, jpeg, & jpg
Name | Type | Description |
---|---|---|
handler |
FileHandlerFunc <any > |
ts import { Speedybot } from "speedybot-mini"; // 1) Initialize your bot const CultureBot = new Speedybot("__REPLACE__MEE__"); // 2) Export your bot export default CultureBot; // Add a camera handler CultureBot.onCamera(($bot, msg, fileData) => { const { fileName, extension, type } = fileData; $bot.send(`You sent a photo: ${fileName} ${extension} ${type}`); // file data available under fileData.data }); |
void
▸ onFile(handler
): Object
Register a handler when a user uploads a file to an agent
With optional confi
- matchText: boolean-- should any text attached to file upload also be processed? (default false)
- excludeFiles: string[]-- any files not to exclude from handling
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.onFile(async ($bot, msg, fileData) => {
const { fileName, extension, type } = fileData;
$bot.send(`You sent a file: ${fileName} ${extension} ${type}`);
// file data available under fileData.data
}).config({matchText: true})
Name | Type |
---|---|
handler |
FileHandlerFunc <any > |
Object
Name | Type |
---|---|
config |
(fileConfig : Partial <{ excludeFiles : string [] ; matchText : boolean }>) => void |
▸ onSubmit(handler
): Object
Register a handler when a user sends data from an Adaptive Card. Any attached data will be available under msg.data.inputs
In the example below this is the data available on card submission: {"cardName":"mySpecialCard7755","inputData":"My opinion is 123"}
:
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.contains("card", ($bot) => {
$bot.send('Here is a card to share your opinion')
$bot.send(
$bot
.card({ title: "Here is a card" })
.setData({ cardName: "mySpecialCard7755" })
.setInput("What is your opinion?")
);
})
CultureBot.onSubmit(async ($bot, msg, fileData) => {
$bot.send(`You submitted ${JSON.stringify(msg.data.inputs)}`);
})
Name | Type |
---|---|
handler |
AAHandler |
Object
Name | Type |
---|---|
config |
(fileConfig : Partial <{ excludeFiles : string [] ; matchText : boolean }>) => void |
▸ peekFile(url
): Promise
<{ extension
: string
; fileName
: string
; type
: string
}>
Cheap way to get content-dispoition header & content-type and get extension
Name | Type |
---|---|
url |
string |
Promise
<{ extension
: string
; fileName
: string
; type
: string
}>
▸ processIncoming(envelope
): Promise
<{ incomingProcessed
: boolean
}>
Name | Type |
---|---|
envelope |
ENVELOPES |
Promise
<{ incomingProcessed
: boolean
}>
▸ processSubmit(details
): null
| GenericHandlerFunc
<any
>
Name | Type |
---|---|
details |
AA_Details |
null
| GenericHandlerFunc
<any
>
▸ processText(incoming?
, skipNoMatchFallback?
): null
| GenericHandlerFunc
<any
>
If worst case (user enters text and we need to search for it) Check the list and find a 1-1 match or "contains"
Note: All queries are lower-cased
Name | Type | Default value |
---|---|---|
incoming |
string |
"" |
skipNoMatchFallback |
boolean |
false |
null
| GenericHandlerFunc
<any
>
▸ regex(rx
, cb
): void
Register a handler thats matches based on a Regular Expression
// This agent will match for only 'Hi'
// Will not match: hi, hi!!, heya how are you?
import { Speedybot } from 'speedybot-mini'
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot(config);
// 2) Export your bot
export default CultureBot;
// 3) Do whatever you want!
CultureBot.regex(new RegExp('x'), async ($bot, msg) => {
$bot.send('You matched because you said a word containing x!')
})
Name | Type |
---|---|
rx |
RegExp |
cb |
MsgHandler |
void
▸ Private
setConfig<T
>(route
, data
): void
Name | Type |
---|---|
T |
any |
Name | Type |
---|---|
route |
string |
data |
T |
void
▸ Private
setHandler(handlerType
, handler
): void
Name | Type |
---|---|
handlerType |
string |
handler |
any |
void
▸ setToken(token
): void
Add a bot token used to authenticate to APIs
// 1) Initialize your bot w/ config
const CultureBot = new Speedybot('__REPLACE__ME__');
// 2) Export your bot
export default CultureBot;
CultureBot.exposeToken() // '__REPLACE__ME__'
CultureBot.setToken('__REPLACE__ME__NEW_TOKEN!')
CultureBot.exposeToken() // __REPLACE__ME__NEW_TOKEN
// Add secret (can happen anytime to keep bots portable)
CultureBot.addSecret('special_token1', 'xxx-yyy')
CultureBot.getSecret('special_token1') // 'xxx-yyy'
CultureBot.addSecrets({'special_token2':'aaa-bbb'})
CultureBot.getSecret('special_token2') // 'aaa-bbb'
// 3) Do whatever you want!
CultureBot.contains(["hi", "hey"], async ($bot, msg) => {
$bot.send('This is the hi greeting handler!')
})
CultureBot.contains('trigger', async ($bot, msg) => {
$bot.send('About to trigger the hi trigger')
$bot.trigger('hi', msg)
})
Name | Type |
---|---|
token |
string |
void
▸ setWelcome(handler
): void
Name | Type |
---|---|
handler |
string | SpeedyCard |
void