@@ -13,51 +13,57 @@ const fetch = require('node-fetch');
1313const openFaas = require ( '../lib/openfaas' ) ;
1414const logger = require ( '../lib/log' ) ;
1515
16- function sendCommand ( command ) {
16+ function sendCommand ( command , light = '' ) {
1717 payload = {
1818 command,
19+ light,
1920 } ;
2021
2122 return openFaas ( 'office-lights-api' , {
2223 method : 'POST' ,
24+ headers : { 'Content-Type' : 'application/json' } ,
2325 body : JSON . stringify ( payload ) ,
2426 } ) . then ( ( response ) => {
2527 return ;
2628 } ) ;
2729}
2830
2931module . exports = ( robot ) => {
30- robot . respond ( / l i g h t s o f f / i, ( msg ) => {
32+ robot . respond ( / l i g h t s o f f ( . + ) ? / i, ( msg ) => {
3133 logger . log ( msg ) ;
3234 const send = msg . send . bind ( msg ) ;
33- sendCommand ( 'force_power_off' ) . catch ( ( error ) => send ( error . message ) ) ;
35+ const light = msg . match [ 1 ] ? msg . match [ 1 ] . trim ( ) : '' ;
36+ sendCommand ( 'force_power_off' , light ) . catch ( ( error ) => send ( error . message ) ) ;
3437 robot . adapter . client . web . reactions . add ( 'mobile_phone_off' , {
3538 channel : msg . message . room ,
3639 timestamp : msg . message . id ,
3740 } ) ;
3841 } ) ;
39- robot . respond ( / l i g h t s o n / i, ( msg ) => {
42+ robot . respond ( / l i g h t s o n ( . + ) ? / i, ( msg ) => {
4043 logger . log ( msg ) ;
4144 const send = msg . send . bind ( msg ) ;
42- sendCommand ( 'force_power_on' ) . catch ( ( error ) => send ( error . message ) ) ;
45+ const light = msg . match [ 1 ] ? msg . match [ 1 ] . trim ( ) : '' ;
46+ sendCommand ( 'force_power_on' , light ) . catch ( ( error ) => send ( error . message ) ) ;
4347 robot . adapter . client . web . reactions . add ( 'bulb' , {
4448 channel : msg . message . room ,
4549 timestamp : msg . message . id ,
4650 } ) ;
4751 } ) ;
48- robot . respond ( / l i g h t s l o c k / i, ( msg ) => {
52+ robot . respond ( / l i g h t s l o c k ( . + ) ? / i, ( msg ) => {
4953 logger . log ( msg ) ;
5054 const send = msg . send . bind ( msg ) ;
51- sendCommand ( 'power_lock' ) . catch ( ( error ) => send ( error . message ) ) ;
55+ const light = msg . match [ 1 ] ? msg . match [ 1 ] . trim ( ) : '' ;
56+ sendCommand ( 'power_lock' , light ) . catch ( ( error ) => send ( error . message ) ) ;
5257 robot . adapter . client . web . reactions . add ( 'lock' , {
5358 channel : msg . message . room ,
5459 timestamp : msg . message . id ,
5560 } ) ;
5661 } ) ;
57- robot . respond ( / l i g h t s u n l o c k / i, ( msg ) => {
62+ robot . respond ( / l i g h t s u n l o c k ( . + ) ? / i, ( msg ) => {
5863 logger . log ( msg ) ;
5964 const send = msg . send . bind ( msg ) ;
60- sendCommand ( 'power_unlock' ) . catch ( ( error ) => send ( error . message ) ) ;
65+ const light = msg . match [ 1 ] ? msg . match [ 1 ] . trim ( ) : '' ;
66+ sendCommand ( 'power_unlock' , light ) . catch ( ( error ) => send ( error . message ) ) ;
6167 robot . adapter . client . web . reactions . add ( 'unlock' , {
6268 channel : msg . message . room ,
6369 timestamp : msg . message . id ,
0 commit comments