convo
Version:
Easily create conversations (for more natural bots)
91 lines (84 loc) • 2.46 kB
Markdown
```js
// Conversation with a clerk
"food" => q1 "What would you like to eat today?"
"I don't like eating" => "God have mercy on your soul" => q1
/(apple|pear|orange)/ => `Great! ${fruit}s are ${price}`
"no" => "well, would you like anything else?"
"no" => "Okay... is there anything else I can get you?" => q1
/.*/ => q1
/.*/ => "Awesome, thanks for your business! Would you like anything else?" => q1
/.*/ => "Did not understand, what would you like to eat?" => q1
```
```js
[
{
incoming: "food",
next: {
id: 'q1'
outgoing: "What would you like to eat today?"
choices: [
{
incoming: "I don't like eating",
next: {
outgoing: "God have mercy on your soul",
goto: 'q1'
}
},
{
incoming: /(apple|pear|orange)/,
outgoing: {
response: `Great! ${fruit}s are ${price}`,
choices: [
{
"incoming": "no",
outgoing: {
response: "well, would you like anything else?",
choices: [
{
incoming: "no",
outgoing: {
response: "Okay... is there anything else I can get you?",
goto: 'q1'
}
},
{
incoming: /.*/,
outgoing: {
goto: 'q1'
}
}
]
}
},
{
incoming: /.*/,
outgoing: {
response: "Awesome, thanks for your business! Would you like anything else?",
goto: 'q1'
}
}
]
}
},
{
incoming: /.*/,
outgoing: {
response: "Did not understand, what would you like to eat?",
goto: 'q1'
}
}
]
}
}
]
```
```js
var res = say("food") // res = "What would you like to eat today?"
var res = say("apple") // res = fn({ price: "14.50", fruit: "apple" }) => `Great! apples are 14.50`
var res = say('awesome, thanks!') // res() => no, thank you!
var res = say('can i get something else?') // res() => What would you like to eat today?
```