Mark Orel
JS Addicted
@markbaraban
Software Engineer
Full-Stack Developer
- All in all, when will we create our own bot, to help people with booking?
- Think it's a great idea.
Alcohol game:
1. Open any website.
2. If website has its own chat-bot -> drink.
is the input alphabet
is a finite, non-empty set of states
is an initial state
is the set of final states (possibly empty)
is the state-transition function
action => handler(state, action) => state
const Q = {
"0": hello,
"01": doYouLikeMe,
"010": sad,
"011": happy,
};
const doYouLikeMe = (state, params) => {
if (params) {
const goTo = makeStateDecision(state.id, params);
return {
id: goTo,
type: "transition"
...state
}
} else {
return {
message: "Do you like me?",
type: "input",
...state
}
}
}
const makeStateDecision = (id, param) => {
if (param === 'YES') {
return '011';
}
return '010';
}
let state = { id: 0 }
let params = null
while(true) {
const handler = Q[q.id]
state = handler(state, params)
if (state.type === 'message') {
say(state.message)
}
if (state.type === 'input') {
params = ask(params, state.message)
}
}