Skip to content

Instantly share code, notes, and snippets.

@Mirv
Created February 20, 2020 15:04
Show Gist options
  • Save Mirv/b4430c82278e77f49ff829b449f02233 to your computer and use it in GitHub Desktop.
Save Mirv/b4430c82278e77f49ff829b449f02233 to your computer and use it in GitHub Desktop.
Vanilla JavaScript framework to create conversational bots
<!-- Star me on Github: https://github.com/ThibaultJanBeyer/ui-landing-bot -->
/*
* Star me on Github: https://github.com/ThibaultJanBeyer/ui-landing-bot
*/
var uilb = new UILandingBot(document.body);
uilb
.message({
content: "Hey! ๐Ÿ‘‹",
cssClass: "no-icon",
delay: 1000
})
.then(ok =>
uilb.message({
content:
"Iโ€™m the friendly bot and Iโ€™m here to make you <strong>feel good</strong>!",
delay: 1000
})
)
.then(ok =>
uilb.message({
cssClass: "fill-img no-icon",
content:
'heyas pretty person',
delay: 1000
})
)
.then(ok =>
uilb.message({
content: "How do you feel?",
delay: 1000
})
)
.then(ok =>
uilb.action({
type: "button",
items: [
{
text: "cat",
value: "meow!"
},
{
text: "awesome",
value: "awesum!"
}
]
})
)
.then(ok =>
uilb.message({
human: true,
content: ok
})
)
.then(ok =>
uilb.message({
content: 'Feeling good now? Well, check out my <a href="https://github.com/ThibaultJanBeyer/ui-landing-bot">documentation on Github</a> and leave me a Star now ๐ŸŒŸ๐Ÿ˜Ž๐ŸŒŸ',
delay: 1000
})
)
.then(ok =>
uilb.message({
human: true,
content: "I love you! ๐Ÿ˜",
delay: 2000
})
)
.catch(error => console.log('error', error));
// Hash format for UILB: message, content, delay
// Param is response key of ok
// Pointing to a uilb class obj
// Which has keys: human, cssclass, content, delay
function navMenuGetChild(response_obj) {
// need to setup ...
// single step, no decisions
// single step, button options
// retrieveNext grabs the step in process
// UILB grabs message, formats and returns promise
return uilb.message(retrieveNext());
}
<script src="https://thibaultjanbeyer.github.io/ui-landing-bot/dist/uilb.min.js"></script>
/*
* Star me on Github: https://github.com/ThibaultJanBeyer/ui-landing-bot
*/
html {
background: linear-gradient(to bottom right, #00ffba, #00ffde);
width: 100%;
height: 100%;
color: #fff;
}
<link href="https://thibaultjanbeyer.github.io/ui-landing-bot/dist/uilb.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment