Skip to content

Commit c2a3dad

Browse files
committed
feat(chatbot): add member help messages
1 parent 2579c3d commit c2a3dad

4 files changed

Lines changed: 93 additions & 22 deletions

File tree

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Place your settings in this file to overwrite default and user settings.
22
{
33
"prettier.trailingComma": "es5",
4-
"prettier.singleQuote": false
4+
"prettier.singleQuote": false,
5+
"prettier.tabWidth": 2,
6+
"prettier.eslintIntegration": true
57
}

src/chatbot/constants.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
CONSENT_DENY: "CONSENT_DENY",
3+
CONSENT_ACCEPT: "CONSENT_ACCEPT",
4+
COINBOT_RELAX: "COINBOT_RELAX",
5+
COINBOT_FEEDBACK: "COINBOT_FEEDBACK",
6+
COINBOT_DONATE: "COINBOT_DONATE"
7+
};

src/chatbot/conversations.js

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,75 @@
1+
const {
2+
COINBOT_RELAX,
3+
COINBOT_UPGRADE,
4+
COINBOT_FEEDBACK,
5+
CONSENT_ACCEPT,
6+
CONSENT_DENY
7+
} = require("./constants");
8+
19
function askForConsent(convo) {
2-
convo.say("Just a quick introduction...");
3-
convo.say(
4-
"My name is Coinbot. I am here to help you keep an eye on cryptocurrency prices."
5-
);
10+
convo.say("I don't think we have met before!");
611
convo.say(
7-
"I will let you know if anything significant opportunities are occurring on the GDAX Exchange."
12+
"My name is Coinbot 🤖 I am here to help you keep an eye on cryptocurrency prices."
813
);
914
convo.say(
10-
"If you would like to learn more about the GDAX Exchange, check here:"
15+
"I will let you know if the market is like 📈 or like 📉 according to the GDAX exchange."
1116
);
1217
convo.say({
13-
text: "I am going to send you text messages about",
18+
text: "Do you want to me to keep you up to date via Messenger?",
1419
buttons: [
1520
{
1621
type: "postback",
1722
title: "👍",
18-
payload: "CONSENT_ACCEPT"
23+
payload: CONSENT_ACCEPT
1924
},
2025
{
2126
type: "postback",
2227
title: "👎",
23-
payload: "CONSENT_DENY"
28+
payload: CONSENT_DENY
2429
}
2530
]
2631
});
2732
}
2833

2934
function handleConsentDeny(chat) {
3035
chat.say(
31-
"Hmm, sorry to hear this. Chat with me any time to change your mind!"
36+
"Hmm, sorry to hear this. Chat with me any time to change your mind! 👋"
3237
);
3338
}
3439

3540
function handleConsentAccept(chat) {
3641
chat.say("Super excited to have you onboard! 😎");
42+
chat.say("I will let you know of significant coin moovement! Enjoy!");
43+
chat.say(
44+
"If you need help anytime, just type 'help', or 'info' if you want to learn about me."
45+
);
3746
chat.say(
38-
"I will let you know if anything significant is going on! Enjoy ! 😎"
47+
"Last thing... If you think I do a good job, you can learn how to support my growth by typing 'premium' ❤️ "
3948
);
49+
chat.say("Hope to hear from you soon! 🙇");
50+
}
51+
52+
function offerBasicHelp(convo) {
53+
cono.say({
54+
text: "How can I help you?",
55+
buttons: [
56+
{
57+
type: "postback",
58+
title: "Take a break",
59+
payload: COINBOT_RELAX
60+
},
61+
{
62+
type: "postback",
63+
title: "Give feedback",
64+
payload: COINBOT_FEEDBACK
65+
},
66+
{
67+
type: "postback",
68+
title: "Go Premium",
69+
payload: COINBOT_UPGRADE
70+
}
71+
]
72+
});
4073
}
4174

4275
module.exports = {

src/chatbot/index.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,28 @@ const bot = new BootBot({
1010
const {
1111
askForConsent,
1212
handleConsentDeny,
13-
handleConsentAccept
13+
handleConsentAccept,
14+
offerBasicHelp
1415
} = require("./conversations");
1516

17+
const {
18+
CONSENT_DENY,
19+
CONSENT_ACCEPT,
20+
COINBOT_RELAX,
21+
COINBOT_FEEDBACK,
22+
COINBOT_UPGRADE
23+
} = require("./constants");
24+
1625
// mock dummy db, need to consider DB solution.
1726
class Users {
18-
get = () => {};
19-
set = () => {};
27+
get() {}
28+
set() {}
2029
}
2130

2231
// will uncomment later and do in another branch
2332
// class Events {
24-
// store = event => {};
25-
// fire = event => {
33+
// store(event) {};
34+
// fire(event) {
2635
// this.store({
2736
// ...event,
2837
// timestamp: new Date.now(),
@@ -37,17 +46,21 @@ bot.on("message", async (payload, chat) => {
3746

3847
chat.say(`Hello, ${user.first_name}! 🙂`);
3948

40-
const store = users.get(sender.id);
49+
const store = Users.get(sender.id);
4150

4251
if (store) {
4352
// Events.fire({
4453
// user: { user, id: sender.id },
4554
// category: "message",
4655
// event: "message from member",
4756
// });
48-
// give them options for what a member can do
57+
58+
chat.say("Good to hear from you again. 😌");
59+
// offer basic help
60+
// check store id, if premium (paying), offer settings
61+
chat.conversation(convo => offerBasicHelp(convo));
4962
} else {
50-
//user has not registered, ask them to create a unique identifier
63+
// user has not registered, ask them to create a unique identifier
5164
chat.conversation(convo => askForConsent(convo));
5265
}
5366
});
@@ -62,16 +75,32 @@ bot.on("postback", async (payload, chat) => {
6275
// });
6376

6477
switch (payload) {
65-
case "CONSENT_DENY":
78+
case CONSENT_DENY:
6679
handleConsentDeny(chat);
6780
return;
68-
case "CONSENT_ACCEPT":
81+
case CONSENT_ACCEPT:
6982
handleConsentAccept(chat);
7083
Users.set({
7184
user,
7285
id: payload.sender.id
7386
});
7487
return;
88+
case COINBOT_UPGRADE:
89+
chat.say("Upgrade coming soon...");
90+
// payment conversation
91+
// set user as paying
92+
return;
93+
case COINBOT_RELAX:
94+
chat.say("Relax coming soon...");
95+
// update user to not get notified
96+
// 1 hour, 1 day, 1 week, custom
97+
return;
98+
case COINBOT_FEEDBACK:
99+
chat.say("Feedback coming soon...");
100+
// accept feedback message
101+
// offer a smiley face system
102+
// plus text
103+
return;
75104
}
76105
});
77106

0 commit comments

Comments
 (0)