forked from tshamz/brianwilliams
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathresponses.js
75 lines (75 loc) · 2.33 KB
/
responses.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
module.exports = {
confirm: function() {
return {
text: 'Would you like to proceed?',
attachments: [{
fallback: '*YES* to confirm',
text: '*YES* to confirm',
color: 'good',
mrkdwn_in: ['fallback', 'text']
}, {
fallback: '*NO* to abort',
text: '*NO* to abort',
color: 'danger',
mrkdwn_in: ['fallback', 'text']
}]
};
},
yes: function(bot, action, options) {
return {
pattern: bot.utterances.yes,
callback: function(response, convo) {
convo.say('Great! Moving forward...');
if (action === 'post') {
bot.say({
channel: '#' + options.channel,
username: 'ChainCoin Announcement',
icon_url: 'https://toaster.chaincoin.org/img/icons/chainbot/ChainBot.png',
text: '*Posted by:* ' + options.id + ' *on* ' + options.date + '\n<!channel>',
attachments: options.message,
});
} else if (action === 'delete') {
console.log(options);
bot.api.chat.delete(options, function(err, response) {
if (!response.ok) {
convo.say('Unable to delete due to error: ' + err);
console.log('Unable to delete due to error: ' + err);
convo.say('Trying one more time in 2 seconds');
console.log('Trying one more time in 2 seconds');
setTimeout(function() {
bot.api.chat.delete(options, function(err, response) {
if (!response.ok) {
convo.say('Unable to delete after a second attempt due to error: ' + err);
console.log('Unable to delete after a second attempt due to error: ' + err);
}
});
}, 2000);
} else {
convo.say('Message successfully deleted!');
console.log('Message successfully deleted!');
}
});
}
convo.next();
}
};
},
no: function(bot) {
return {
pattern: bot.utterances.no,
callback: function(response, convo) {
convo.say('Perhaps later.');
convo.next();
}
};
},
default: function() {
return {
default: true,
callback: function(response, convo) {
convo.repeat();
convo.next();
}
};
}
};