-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.html
136 lines (117 loc) · 4.06 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello BotScript!</title>
<link rel="icon" href="data:,">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<!--link app scripts-->
<script src="botscript.ai.js"></script>
<script src="botscript.plugins.js"></script>
</head>
<body>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="jumbotron">
<div class="container">
<h1 class="display-3">Hello, BotScript!</h1>
<p>A text-based scripting language, dialog system and bot engine for Conversational User Interfaces</p>
<p>
<a class="btn-primary btn-lg" href="https://botscript-ai.web.app/#/register" target="_blank">Register Now
»</a>
<iframe src="https://ghbtns.com/github-btn.html?user=yeuai&repo=botscript&type=star&count=true&size=large"
frameborder="0" scrolling="0" width="170" height="30" title="GitHub"></iframe>
</p>
</div>
</div>
<div class="container">
<h2 id="greeting">Do you have any questions to ask BotScript?</h2>
<p id="messages"></p>
</div>
<div id="fb-root"></div>
<div id="fb-customer-chat" class="fb-customerchat"></div>
<script>
const { BotScript } = BotScriptAI;
const bot = new BotScript();
const urlParams = new URLSearchParams(window.location.search);
const botId = urlParams.get('bot');
bot.parse('> addTimeNow');
bot.parse(`
/include:
- https://raw.githubusercontent.com/yeuai/botscript/master/examples/definition.bot
- https://raw.githubusercontent.com/yeuai/botscript/master/examples/basic.bot
${botId ? '- https://botscript-core.yeu.ai/api/kb/' + botId : ''}
@ geoip https://api.ipify.org/?format=json
#- header: value
#- header: value (2)
@ list_patient https://raw.githubusercontent.com/yeuai/botscript/master/examples/data/list.json
/format:list
{{#each people}}
{{name}} / {{age}},
{{/each}}
# conditional command
+ what is my ip
* true @> geoip
- Here is your ip: $ip
+ what time is it
- It is $time
+ show my list
* true @> list_patient
- Here is your list: $people /format:list
/plugin: test
\`\`\`js
req.variables.today = new Date().getDate();
req.variables.day = new Date().getDay();
# test 2
req.variables.year = new Date().getFullYear();
\`\`\`
> test
+ howdy
- Today is $today
`);
bot.init()
.then(async () => {
await sendBot(bot.newRequest('Hello!'));
await sendBot(bot.newRequest(`I'm vunb`));
await sendBot(bot.newRequest('What time is it?'));
await sendBot(bot.newRequest('What is my ip?'));
await sendBot(bot.newRequest('Show my list'));
});
/**
* Send bot message and wait response.
* */
async function sendBot(req) {
// human ask
appendChatbox(`Human ask: <strong>${req.message}</strong>`);
const reply = await bot.handleAsync(req);
// bot reply
appendChatbox(`Bot reply: <em>${reply.speechResponse}</em>`);
}
function appendChatbox(message, id = 'messages') {
const chatbox = document.getElementById(id);
const elem = document.createElement("div");
elem.innerHTML = message;
chatbox.append(elem);
}
</script>
<script>
// fb-customer-chat.js
var chatbox = document.getElementById('fb-customer-chat');
chatbox.setAttribute("page_id", "104330261088219");
chatbox.setAttribute("attribution", "biz_inbox");
window.fbAsyncInit = function () {
FB.init({
xfbml: true,
version: 'v11.0'
});
};
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = 'https://connect.facebook.net/vi_VN/sdk/xfbml.customerchat.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
</body>
</html>