@@ -22,8 +22,8 @@ module.exports = function (controller) {
2222 return ;
2323 }
2424
25- // Ask for favorite color
26- askForFavoriteColor ( controller , bot , message , userId ) ;
25+ // Ask for prefrence
26+ askForUserPreference ( controller , bot , message , userId ) ;
2727 } ) ;
2828 } ) ;
2929}
@@ -33,19 +33,14 @@ function showUserPreference(controller, bot, message, userId, color) {
3333
3434 convo . sayFirst ( `Hey, I know you <@personId:${ userId } >!<br/> '${ color } ' is your favorite color.` ) ;
3535
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)" , [
4437 {
4538 pattern : "^yes|ya|da|si|oui$" ,
4639 callback : function ( response , convo ) {
4740
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 ) {
4944 if ( err ) {
5045 convo . say ( message , 'sorry, could not access storage, err: ' + err . message ) ;
5146 convo . repeat ( ) ;
@@ -61,15 +56,15 @@ function showUserPreference(controller, bot, message, userId, color) {
6156 {
6257 default : true ,
6358 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." ) ;
6560 convo . next ( ) ;
6661 }
6762 }
6863 ] ) ;
6964 } ) ;
7065}
7166
72- function askForFavoriteColor ( controller , bot , message , userId ) {
67+ function askForUserPreference ( controller , bot , message , userId ) {
7368 bot . startConversation ( message , function ( err , convo ) {
7469
7570 convo . ask ( "What is your favorite color?" , [
@@ -87,21 +82,25 @@ function askForFavoriteColor(controller, bot, message, userId) {
8782 return ;
8883 }
8984
90- convo . transitionTo ( "success" , `_stored user preference_` ) ;
85+ convo . transitionTo ( "success" , "_successfully stored user preference_" ) ;
9186 } ) ;
9287
9388 } ,
9489 } ,
9590 {
9691 default : true ,
9792 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' ) ;
10194 }
10295 }
10396 ] , { key : "answer" } ) ;
10497
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+
105104 // Success thread
106105 convo . addMessage (
107106 "Cool, I love '{{responses.answer}}' too" ,
0 commit comments