@@ -22,8 +22,8 @@ module.exports = function (controller) {
22
22
return ;
23
23
}
24
24
25
- // Ask for favorite color
26
- askForFavoriteColor ( controller , bot , message , userId ) ;
25
+ // Ask for prefrence
26
+ askForUserPreference ( controller , bot , message , userId ) ;
27
27
} ) ;
28
28
} ) ;
29
29
}
@@ -33,19 +33,14 @@ function showUserPreference(controller, bot, message, userId, color) {
33
33
34
34
convo . sayFirst ( `Hey, I know you <@personId:${ userId } >!<br/> '${ color } ' is your favorite color.` ) ;
35
35
36
- // Remove user preferences if supported
37
- if ( ! controller . storage . users . remove ) {
38
- convo . say ( "_To erase your preference, simply restart the bot as you're using in-memory transient storage._" ) ;
39
- convo . next ( ) ;
40
- return ;
41
- }
42
-
43
- convo . ask ( "Should I erase your preference? yes/(no)" , [
36
+ convo . ask ( "Should I erase your preference? (yes/no)" , [
44
37
{
45
38
pattern : "^yes|ya|da|si|oui$" ,
46
39
callback : function ( response , convo ) {
47
40
48
- controller . storage . users . remove ( userId , function ( err ) {
41
+ // [WORKAROUND] use storage.users.delete if in-memory storage and storage.users.remove if redis storage
42
+ // controller.storage.users.remove(userId, function (err) {
43
+ controller . storage . users . delete ( userId , function ( err ) {
49
44
if ( err ) {
50
45
convo . say ( message , 'sorry, could not access storage, err: ' + err . message ) ;
51
46
convo . repeat ( ) ;
@@ -61,15 +56,15 @@ function showUserPreference(controller, bot, message, userId, color) {
61
56
{
62
57
default : true ,
63
58
callback : function ( response , convo ) {
64
- convo . say ( "Got it, leaving your color preference as is." ) ;
59
+ convo . say ( "Got it, leaving your preference as is." ) ;
65
60
convo . next ( ) ;
66
61
}
67
62
}
68
63
] ) ;
69
64
} ) ;
70
65
}
71
66
72
- function askForFavoriteColor ( controller , bot , message , userId ) {
67
+ function askForUserPreference ( controller , bot , message , userId ) {
73
68
bot . startConversation ( message , function ( err , convo ) {
74
69
75
70
convo . ask ( "What is your favorite color?" , [
@@ -87,21 +82,25 @@ function askForFavoriteColor(controller, bot, message, userId) {
87
82
return ;
88
83
}
89
84
90
- convo . transitionTo ( "success" , `_stored user preference_` ) ;
85
+ convo . transitionTo ( "success" , "_successfully stored user preference_" ) ;
91
86
} ) ;
92
87
93
88
} ,
94
89
} ,
95
90
{
96
91
default : true ,
97
92
callback : function ( response , convo ) {
98
- convo . say ( "Sorry, I don't know this color. Try another one..." ) ;
99
- convo . repeat ( ) ;
100
- convo . next ( ) ;
93
+ convo . gotoThread ( 'bad_response' ) ;
101
94
}
102
95
}
103
96
] , { key : "answer" } ) ;
104
97
98
+ // Bad response
99
+ convo . addMessage ( {
100
+ text : "Sorry, I don't know this color.<br/>_Tip: try blue, green, pink, red or yellow!_" ,
101
+ action : 'default' ,
102
+ } , 'bad_response' ) ;
103
+
105
104
// Success thread
106
105
convo . addMessage (
107
106
"Cool, I love '{{responses.answer}}' too" ,
0 commit comments