-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathbot.js
82 lines (76 loc) · 2.31 KB
/
bot.js
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
const SOFA = require('sofa-js');
const Bot = require('./lib/Bot');
const unit = require('ethjs-unit');
let bot = new Bot();
bot.onEvent = function(session, message) {
switch (message.type) {
case "Message":
onMessage(session, message);
break;
case "Command":
onCommand(session, message);
break;
case "PaymentRequest":
onPaymentRequest(session, message);
break;
}
}
function onMessage(session, message) {
if (message.content.body.includes("red")) {
session.reply(SOFA.Message({
body: "What would you like me to do for you right now?",
controls: [
{
type: "group",
label: "Trip",
controls: [
{type: "button", label: "Directions", action: "Webview:/Directions"},
{type: "button", label: "Timetable", value: "timetable"},
{type: "button", label: "Exit Info", value: "exit"},
{type: "button", label: "Service Conditions", action: "Webview:/ServiceConditions"}
]
},{
type: "group",
label: "Services",
controls: [
{type: "button", label: "Buy Ticket", action: "buy-ticket"},
{type: "button", label: "Support", value: "support"}
]
},
{type: "button", label: "Nothing", value: -1}
],
showKeyboard: false
}));
} else {
sendColorPrompt(session, "I only want to talk about my favorite color. Guess what it is!");
}
}
function onCommand(session, command) {
if (command.content.value === "red") {
session.reply("Yep! Red is the best");
} else {
sendColorPrompt(session, "Nope! Try again.");
}
}
function sendColorPrompt(session, body) {
session.reply(SOFA.Message({
body: body,
controls: [
{type: "button", label: "Red", value: "red"},
{type: "button", label: "Green", value: "green"},
{type: "button", label: "Blue", value: "blue"}
],
showKeyboard: false
}));
}
function onPaymentRequest(session, message) {
let limit = unit.toWei(5, 'ether');
if (message.value.lt(limit)) {
session.sendEth(message.value, (session, error, result) => {
if (error) { session.reply('I tried but there was an error') }
if (result) { session.reply('Here you go!') }
})
} else {
session.reply('Sorry, I have a 5 ETH limit.')
}
}