-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
96 lines (82 loc) · 2.15 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
// Global imports
const BootBot = require('bootbot');
const config = require('config');
// Local imports
const intro = require('./src');
const helpModule = require('./src/modules/help');
// Initialize bot
const bot = new BootBot({
accessToken: config.get('accessToken'),
verifyToken: config.get('verifyToken'),
appSecret: config.get('appSecret'),
});
bot.module(helpModule);
// --- List to certain words/phrases ---
// Array example
bot.hear(['hello', 'hi', /hey( there)?/i], (payload, chat) => {
console.log('The user said "hello", "hi", "hey", or "hey there"');
chat.getUserProfile().then(user => {
console.log('User Profile:', user);
chat.say(`Hello, ${user.first_name}!`);
});
});
// Regex example
bot.hear([/(good)?bye/i, /see (ya|you)/i, 'adios'], (payload, chat) => {
// Matches: goodbye, bye, see ya, see you, adios
chat.say('Bye, human!');
});
// Help me button
bot.on('postback:HELP_ME', (payload, chat) => {
console.log('The Help Me button was clicked!');
});
// Authentication
bot.on('authentication', (payload, chat) => {
console.log('AUTHENTICATION! - User arrived');
});
// User returns
bot.on('referral', (payload, chat) => {
console.log('REFERRAL! - User returns');
});
// Start CodeCanary lesson
// bot.hear([/yes/i, /yeah\!?/i, /sure/i], (payload, chat) => {
// chat.conversation(convo => {
// intro(convo);
// });
// });
bot.on('postback:BOOTBOT_GET_STARTED', (payload, chat) => {
chat.conversation(convo => {
intro(convo);
});
});
/**
* Show a persistent menu
*/
bot.setPersistentMenu([
{
type: 'postback',
title: 'Pause course (keep progress)',
payload: 'PAUSE_COURSE',
},
{
type: 'postback',
title: 'I need some help',
payload: 'HELP',
},
{
type: 'web_url',
title: 'Project website',
url: 'https://codecanary.now.sh/',
webview_height_ratio: 'full',
},
]);
/**
* Customize greetings text
*/
bot.setGreetingText(
'Welcome to CodeCanary! 😃 Do you want to learn how to program your own website 💻 without a computer?'
);
// bot.setGetStartedButton((user, other) => {
// console.log({ user, other });
// });
bot.start(config.get('botPort'));