@@ -42,6 +42,38 @@ const pickCategory = {
42
42
typing : true
43
43
}
44
44
45
+ const WELCOME_SENTENCES = [
46
+ "Hey, so I've heard that you need a little kick in the butt from time to time? Don't worry mate, that's my job and I'll do that for you 👏" ,
47
+ "In exchange I only ask from you that you don't talk to me like I was human.. I'm clearly not! 🤖" ,
48
+ "👉 Let's just stick to using buttons, that's going to be easier for the both of us"
49
+ ]
50
+
51
+ const WELCOME_TEXT_QUICK_REPLY = "That being said, choose a category right away and I'll make sure you get pumped up!"
52
+
53
+ const DEFAULT_ANSWERS = event => [
54
+ event . user . first_name + ", I told you, I'm a bit dumb. I assume you want motivation, 'cause that's all I'm able to do :)" ,
55
+ "I don't understand much of what you say " + event . user . first_name ,
56
+ "I'm only here to give you motivation" ,
57
+ "My creators made me dumb on purpose, they say I shouldn't try to be human-like :s" ,
58
+ "I'm not here to talk " + event . user . first_name + ", I'm here to give you motivation!"
59
+ ]
60
+
61
+ const shareTemplate = {
62
+ template_type : 'generic' ,
63
+ elements : [ {
64
+ title : 'Clicking this button could literally change your life' ,
65
+ item_url : 'https://m.me/boostfuel' ,
66
+ image_url : 'https://s27.postimg.org/dl8i0udqb/motivation_on_demand.png' ,
67
+ buttons : [ {
68
+ type : 'web_url' ,
69
+ title : '👏 Make it happen' ,
70
+ url : 'https://m.me/boostfuel'
71
+ } , { type : 'element_share' } ]
72
+ } ]
73
+ }
74
+
75
+ const SHARE_TEXT = "PLEASE! If you enjoy the service I am giving you, consider sharing the card below with some of your friends 👇!"
76
+
45
77
module . exports = function ( bp ) {
46
78
bp . middlewares . load ( )
47
79
subscription ( bp )
@@ -55,21 +87,11 @@ module.exports = function(bp) {
55
87
56
88
bp . subscription . subscribe ( event . user . id , 'daily' )
57
89
58
- const WELCOME_SENTENCES = [
59
- "Hey, so I've heard that you need a little kick in the butt from time to time? Don't worry mate, that's my job and I'll do that for you 👏" ,
60
- "In exchange I only ask from you that you don't talk to me like I was human.. I'm clearly not! 🤖" ,
61
- "👉 Let's just stick to using buttons, that's going to be easier for the both of us"
62
- ]
63
-
64
- const WELCOME_TEXT_QUICK_REPLY = "That being said, choose a category right away and I'll make sure you get pumped up!"
65
-
66
- Promise . mapSeries ( WELCOME_SENTENCES , txt => {
67
- bp . messenger . sendText ( event . user . id , txt , { typing : true } )
68
- return Promise . delay ( 2000 )
69
- } )
70
- . then ( ( ) => {
71
- bp . messenger . sendText ( event . user . id , WELCOME_TEXT_QUICK_REPLY , pickCategory )
90
+ return Promise . mapSeries ( WELCOME_SENTENCES , txt => {
91
+ return bp . messenger . sendText ( event . user . id , txt , { typing : true , waitDelivery : true } )
92
+ . then ( Promise . delay ( 250 ) )
72
93
} )
94
+ . then ( ( ) => bp . messenger . sendText ( event . user . id , WELCOME_TEXT_QUICK_REPLY , pickCategory ) )
73
95
} )
74
96
75
97
bp . hear ( / T R I G G E R _ D A I L Y / i, ( event , next ) => {
@@ -79,9 +101,7 @@ module.exports = function(bp) {
79
101
const hearGetVideo = category => {
80
102
bp . hear ( { text : 'GET_VIDEO_' + category } , ( event , next ) => {
81
103
const text = _ . sample ( TEXT_CATEGORIES [ category ] )
82
- bp . messenger . sendText ( event . user . id , text )
83
-
84
- Promise . delay ( 1000 )
104
+ bp . messenger . sendText ( event . user . id , text , { waitDelivery : true } )
85
105
. then ( ( ) => bp . sendRandomVideo ( event . user . id , category ) )
86
106
} )
87
107
}
@@ -90,22 +110,14 @@ module.exports = function(bp) {
90
110
_ . keys ( TEXT_CATEGORIES ) . forEach ( hearGetVideo )
91
111
92
112
bp . botDefaultResponse = event => {
93
- const ANSWERS = [
94
- event . user . first_name + ", I told you, I'm a bit dumb. I assume you want motivation, 'cause that's all I'm able to do :)" ,
95
- "I don't understand much of what you say " + event . user . first_name ,
96
- "I'm only here to give you motivation" ,
97
- "My creators made me dumb on purpose, they say I shouldn't try to be human-like :s" ,
98
- "I'm not here to talk " + event . user . first_name + ", I'm here to give you motivation!"
99
- ]
100
-
101
- const text = _ . sample ( ANSWERS )
102
- bp . messenger . sendText ( event . user . id , text , pickCategory )
113
+ const text = _ . sample ( DEFAULT_ANSWERS ( event ) )
114
+ return bp . messenger . sendText ( event . user . id , text , pickCategory )
103
115
}
104
116
105
117
bp . sendRandomVideo = ( userId , category ) => {
106
- videos . getRandomVideo ( category )
118
+ return videos . getRandomVideo ( category )
107
119
. then ( meta => {
108
- bp . messenger . sendTemplate ( userId , {
120
+ return bp . messenger . sendTemplate ( userId , {
109
121
template_type : 'generic' ,
110
122
elements : [ {
111
123
title : meta . title ,
@@ -129,36 +141,28 @@ module.exports = function(bp) {
129
141
} ]
130
142
} )
131
143
} )
144
+ . then ( ( ) => {
145
+ // 10% chance of saying this
146
+ const n = _ . random ( 0 , 10 )
147
+ if ( n === 5 ) {
148
+ return Promise . delay ( 15000 )
149
+ . then ( ( ) => bp . sendShare ( userId ) )
150
+ }
151
+ } )
152
+ }
132
153
133
- const n = _ . random ( 0 , 10 )
134
- if ( n === 5 ) { // 10% chance of saying this
135
- setTimeout ( ( ) => {
136
- bp . messenger . sendText ( userId , "PLEASE! If you enjoy the service I am giving you, consider sharing the card below with some of your friends 👇!" )
137
-
138
- setTimeout ( ( ) => {
139
- bp . messenger . sendTemplate ( userId , {
140
- template_type : 'generic' ,
141
- elements : [ {
142
- title : 'Clicking this button could literally change your life' ,
143
- item_url : 'https://m.me/boostfuel' ,
144
- image_url : 'https://s27.postimg.org/dl8i0udqb/motivation_on_demand.png' ,
145
- buttons : [ {
146
- type : 'web_url' ,
147
- title : '👏 Make it happen' ,
148
- url : 'https://m.me/boostfuel'
149
- } , { type : 'element_share' } ]
150
- } ]
151
- } )
152
- } , 2000 )
153
- } , 15 * 1000 )
154
- }
154
+ bp . sendShare = userId => {
155
+ return bp . messenger . sendText ( userId , SHARE_TEXT )
156
+ . then ( Promise . delay ( 1000 ) )
157
+ . then ( ( ) => bp . messenger . sendTemplate ( userId , shareTemplate ) )
155
158
}
156
159
157
- bp . sendDailyVideo = ( userId ) => {
160
+ bp . sendDailyVideo = userId => {
158
161
const category = _ . sample ( _ . keys ( TEXT_CATEGORIES ) )
159
162
const text = "Here's your daily motivational video, have an excellent day 😁!"
160
163
161
164
bp . messenger . sendText ( userId , text )
162
- setTimeout ( ( ) => bp . sendRandomVideo ( userId , category ) , 1000 )
165
+ . then ( Promise . delay ( 1000 ) )
166
+ . then ( ( ) => bp . sendRandomVideo ( userId , category ) )
163
167
}
164
168
}
0 commit comments