-
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.
fix: input_processor and options_processor
- Loading branch information
1 parent
0fa8120
commit ae4a385
Showing
2 changed files
with
122 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { lottus, form_processor, InMemorySessionManager, process_w_session, format_message } from "../index.js"; | ||
|
||
(async function () { | ||
const bot = create_bot(); | ||
const session_manager = new InMemorySessionManager(); | ||
|
||
let input = ["", "1", "0", "2"]; | ||
|
||
for(const i of input){ | ||
const identifier = "841234567"; | ||
|
||
console.log(await process_request(bot, session_manager, identifier, {prompt: i})); | ||
} | ||
|
||
input = ["", "2", "0", "1", "1", "1", "0"]; | ||
|
||
for(const i of input){ | ||
const identifier = "841234568"; | ||
|
||
console.log(await process_request(bot, session_manager, identifier, {prompt: i})); | ||
} | ||
})(); | ||
|
||
async function process_request(bot, session_manager, msisdn, request){ | ||
try{ | ||
const session = await process_w_session(bot, session_manager, msisdn, request); | ||
|
||
return format_message(session.message); | ||
}catch(e){ | ||
console.log(e); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function get_main(req, res){ | ||
|
||
res.title = "Main"; | ||
res.addAutoOption({label: "Home", next: "home"}); | ||
res.addAutoOption({label: "About", next: "about"}); | ||
|
||
return res; | ||
} | ||
|
||
|
||
function get_about(req, res){ | ||
|
||
res.title = "About"; | ||
res.addOption({label: "Back to main", next:"main", key: 0}); | ||
res.body = "You selected about"; | ||
|
||
return res; | ||
} | ||
|
||
function get_home(req, res){ | ||
|
||
res.title = "Home"; | ||
res.addOption({label: "Back to main", next:"main", key: 0}); | ||
res.body = "You selected home"; | ||
|
||
return res; | ||
} | ||
|
||
|
||
function create_bot(){ | ||
const bot = lottus(); | ||
|
||
bot.get("main", get_main); | ||
bot.post("main", form_processor); | ||
|
||
bot.at("home", get_home, form_processor); | ||
bot.at("about", get_about, form_processor); | ||
|
||
return bot; | ||
} |
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