-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: form and info routers; remove: at routers
- Loading branch information
1 parent
356d46c
commit 5ac1cf9
Showing
34 changed files
with
3,187 additions
and
1,718 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,34 @@ | ||
const {Bot} = require('../index'); | ||
import { Lottus } from "../index.js"; | ||
|
||
let input = new Lottus(); | ||
|
||
input.at("main", | ||
// info | ||
async function(_, res){ | ||
res.form = {input: "name"}; | ||
res.body = "Please tell me your profession"; | ||
|
||
return res; | ||
}, | ||
|
||
// proc | ||
async (req, res) => { | ||
if(req.prompt.trim().length > 0){ | ||
res.body = "Congratulations. Your profession is " + req.prompt; | ||
res.form = null; | ||
}else { | ||
res.body = "Profession cannot be empty. Please tell us your profession"; | ||
} | ||
|
||
let info = new Bot( | ||
{ | ||
name: "info-bot", | ||
entrypoint: 'main', | ||
keyword: "@info", | ||
description: "Reverses a provided string" | ||
return res; | ||
} | ||
); | ||
|
||
info.at('main', async () => { | ||
const menu = { | ||
name: 'main', | ||
title: "Welcome to Ben's bot", | ||
message: "Select an option", | ||
options: [ | ||
{key: 1, label: "name", menu: "name"}, | ||
{key: 2, label: "profession", menu: "profession"}, | ||
{key: 3, label: "age", menu: "age"}, | ||
{key: 4, label: "country", menu: "country"} | ||
] | ||
} | ||
return { | ||
menu: menu | ||
}; | ||
}); | ||
|
||
info.at('profession', async () => { | ||
const menu = { | ||
name: 'profession', | ||
title: "Ben's profession", | ||
message: "Data Engineer @ VM", | ||
options: [ | ||
{key: 0, label: "back", menu: "main"}, | ||
] | ||
} | ||
return { | ||
menu: menu | ||
}; | ||
}); | ||
|
||
info.at('name', async () => { | ||
const menu = { | ||
name: "name", | ||
title: "Ben's full name", | ||
message: "Benjamim J. Chambule", | ||
options: [ | ||
{key: 0, label: "back", menu: "main"}, | ||
] | ||
} | ||
return { | ||
menu: menu | ||
}; | ||
}); | ||
|
||
info.at('age', async () => { | ||
const menu = { | ||
name: "age", | ||
title: "Ben's age", | ||
message: "Ben's age is 30", | ||
options: [ | ||
{key: 0, label: "back", menu: "main"}, | ||
] | ||
} | ||
return { | ||
menu: menu | ||
}; | ||
}); | ||
|
||
info.at('country', async () => { | ||
const menu = { | ||
name: "country", | ||
title: "Ben's country", | ||
message: "Ben's country is Mozambique", | ||
options: [ | ||
{key: 0, label: "back", menu: "main"}, | ||
] | ||
} | ||
return { | ||
menu: menu | ||
}; | ||
}); | ||
|
||
info.intercept('*', async (request) => { | ||
if(request.prompt.trim() === '@exit'){ | ||
return { | ||
menu: { | ||
title: "Thank you for using Ben's bot", | ||
} | ||
} | ||
} | ||
}); | ||
(async () => { | ||
let session = await info.process({msisdn: "123", prompt: "@info"}); | ||
console.log(session); | ||
|
||
session = await info.process({msisdn: "123", prompt: "1"}, session); | ||
console.log(session); | ||
|
||
session = await info.process({msisdn: "123", prompt: "0"}, session); | ||
console.log(session); | ||
let message = await input.process({prompt: "hello"}) | ||
console.log(message); | ||
|
||
session = await info.process({msisdn: "123", prompt: "2"}, session); | ||
console.log(session); | ||
message = await input.process({prompt: ""}, message); | ||
console.log(message); | ||
|
||
session = await info.process({msisdn: "123", prompt: "@exit"}, session); | ||
console.log(session); | ||
})(); | ||
message = await input.process({prompt: "Data engineer"}, message); | ||
console.log(message); |
Oops, something went wrong.