Skip to content

Commit

Permalink
Update: README
Browse files Browse the repository at this point in the history
  • Loading branch information
benchambule committed Aug 25, 2024
1 parent 6088675 commit 16dba0d
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 4 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,56 @@ console.log(message);

message = await options.process({prompt:"2"}, message);
console.log(message);
```

Let's update the code to use lottus built-in features

```javascript
import { form_processor, format_message, lottus } from "../index.js";

let options = lottus();

options.info("main", async (_, msg) => {
msg.body = "Please select an option";

msg.addAutoOption({label: "Name", next:"name"});
msg.addAutoOption({label: "Profession", next:"profession"});

return msg;
});

options.form("main", form_processor);

options.info("name", async (_, msg) => {
msg.body = "You selected 1 - Name";
msg.addOption({label: "Back", key: 0, next: "main"});

return msg;
});

options.form("name", form_processor);

options.info("profession", async (_, msg) => {
msg.body = "You selected 2 - Profession";
msg.addOption({label: "Back", key: 0, next: "main"});

return msg;
});

options.form("profession", form_processor);

let message = await options.process({prompt:"hello"});
console.log(format_message(message));

message = await options.process({prompt:"1"}, message);
console.log(format_message(message));

message = await options.process({prompt:"0"}, message);
console.log(format_message(message));

message = await options.process({prompt:"2"}, message);
console.log(format_message(message));

message = await options.process({prompt:"0"}, message);
console.log(format_message(message));
```
6 changes: 3 additions & 3 deletions examples/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ input.info("show_details", async (req, res) => {
res.form = false;

for(const key in req.parameters){
res.body = "[" + key + ":" + req.parameters[key] + "]";
res.body += "[" + key + ":" + req.parameters[key] + "]";
}

return res;
Expand All @@ -56,9 +56,9 @@ let message = await input.process({prompt: "hello"});
console.log(message);
console.log("--------------------------------------------------");

message = await input.process({prompt: "Ben Chambule"}, message);
message = await input.process({prompt: "Ben Chambule", parameters: message.parameters}, message);
console.log(message);
console.log("--------------------------------------------------");

message = await input.process({prompt: "Developer"}, message);
message = await input.process({prompt: "Developer", parameters: message.parameters}, message);
console.log(message);
41 changes: 41 additions & 0 deletions examples/lottus_inputs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { form_processor, lottus, redirect } from "../index.js";

let input = lottus();

input.info("main", async (_, res) => {
res.body = "Please tell me your name";
res.addInput({name: "name", next: "profession"});

return res;
});

input.form("main", form_processor);

input.info("profession", async (_, res) => {
res.addInput({name: "profession", next: "show_details"});

res.body = "Please tell me your profession";

return res;
});

input.form("profession", form_processor);

input.info("show_details", async (req, res) => {
for(const key in req.parameters){
res.body += "[" + key + ":" + req.parameters[key] + "]";
}

return res;
});

let message = await input.process({prompt: "hello"});
console.log(message);
console.log("--------------------------------------------------");

message = await input.process({prompt: "Ben Chambule", parameters: message.parameters}, message);
console.log(message);
console.log("--------------------------------------------------");

message = await input.process({prompt: "Developer", parameters: message.parameters}, message);
console.log(message);
47 changes: 47 additions & 0 deletions examples/lottus_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { form_processor, format_message, lottus } from "../index.js";

let options = lottus();

options.info("main", async (_, msg) => {
msg.body = "Please select an option";

msg.addAutoOption({label: "Name", next:"name"});
msg.addAutoOption({label: "Profession", next:"profession"});

return msg;
});

options.form("main", form_processor);

options.info("name", async (_, msg) => {
msg.body = "You selected 1 - Name";
msg.addOption({label: "Back", key: 0, next: "main"});

return msg;
});

options.form("name", form_processor);

options.info("profession", async (_, msg) => {
msg.body = "You selected 2 - Profession";
msg.addOption({label: "Back", key: 0, next: "main"});

return msg;
});

options.form("profession", form_processor);

let message = await options.process({prompt:"hello"});
console.log(format_message(message));

message = await options.process({prompt:"1"}, message);
console.log(format_message(message));

message = await options.process({prompt:"0"}, message);
console.log(format_message(message));

message = await options.process({prompt:"2"}, message);
console.log(format_message(message));

message = await options.process({prompt:"0"}, message);
console.log(format_message(message));
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class Message {
/**
*
* @param {object} option
* @example {lable: "name", next: "display_name", parameters: {selected: "name"}}
* @example {label: "name", next: "display_name", parameters: {selected: "name"}}
*/
addAutoOption(option){
if(!this.form){
Expand Down

0 comments on commit 16dba0d

Please sign in to comment.