File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ export class Handler {
3939 public async handle ( request : Request ) : Promise < void > {
4040 const me = await BOT . people . get ( 'me' ) ;
4141 // Don't do anything if the bot is receiving a hook from its own message.
42- if ( me . id !== request . body . data . personId ) {
42+ if ( request . body . data . personId && me . id !== request . body . data . personId ) {
4343 // This is the earliest we can put this try catch, any earlier
4444 // and an error will cause a loop which continuously sends messages
4545 // since the bot will respond to its own messages.
@@ -99,6 +99,9 @@ export class Handler {
9999 LOGGER . error ( innerError ) ;
100100 }
101101 }
102+ } else if ( ! request . body . data . personId ) {
103+ // Sometimes this happens in production where a personId is not coming in from the webex server
104+ console . error ( request . body . data ) ;
102105 }
103106
104107 }
Original file line number Diff line number Diff line change @@ -60,6 +60,14 @@ describe('Handler is working', () => {
6060 expect ( BOT . messages . create ) . toHaveBeenCalledTimes ( 0 ) ;
6161 } ) ;
6262
63+ test ( 'handler appropriately errors and logs when message originator can\'t be determined' , async ( ) => {
64+ BOT . people . get . mockReturnValueOnce ( { id : MOCK_REQUEST . body . data . personId } ) ;
65+ expect ( await new Handler ( ) . handle ( { body : { ...MOCK_REQUEST . body , data : { ...MOCK_REQUEST . body . data , personId : undefined } } } as Request ) ) . toEqual ( undefined ) ;
66+ expect ( BOT . people . get ) . toHaveBeenCalledWith ( 'me' ) ;
67+ expect ( BOT . messages . get ) . toHaveBeenCalledTimes ( 0 ) ;
68+ expect ( BOT . messages . create ) . toHaveBeenCalledTimes ( 0 ) ;
69+ } ) ;
70+
6371 test ( 'handler appropriately returns response if command is invalid' , async ( ) => {
6472 BOT . messages . get . mockReturnValueOnce ( { text : 'invalid foo command' , personId : 'mockPersonId' } ) ;
6573 BOT . people . get . mockReturnValue ( { id : MOCK_REQUEST . body . data . personId , displayName : 'mockDisplayName' } ) ;
You can’t perform that action at this time.
0 commit comments