Accepted webhook pattern matching?

hipchat
webhook

#1

I’m having a problem with two similarly named webhooks (in a hipchat descriptor) not firing their respective functions properly.

I’ve got 2 hooks defined as so:

 {
      "url": "https://www.somewhere.com/ack_by_text",
      "pattern": "^/[aA][cC][kK]",
      "event": "room_message",
      "authentication": "jwt",
      "name": "ack"
    },
    
    {
      "url": "https://www.somewhere.com/ack_cs_by_text",
      "pattern": "^/[aA][cC][kK][cC][sS]",
      "event": "room_message",
      "authentication": "jwt",
      "name": "ackcs"
    },

When I call /ackcs both functions fire, i see why this could be happening and i’ve tried:

This doesnt return anything and just breaks

^/[aA][cC][kK]$
^/[aA][cC][kK][cC][sS]$ 

This doesnt return anything and just breaks

\/\b(ack)\b
\/\b(ackcs)\b

This doesn’t return anything and just breaks

(^)\/ack($)
(^)\/ackcs($)

can someone please advise what will match the slash commands /ack and /ackcs explicitly? Thanks!


#2

Hey @oepstein,

Can you try the following regex:
/[aA][cC][kK]\b
/[aA][cC][kK][cC][sS]\b

Cheers,
Peter


#3

No dice. When using the regex you provided, neither function fires. I cant understand why it doesnt like that \b?


#4

@oepstein

Don’t try to do all of the heavy lifting with RegEx. You’ll hate life if you do that. If it were me I’d set up one webhook for both patterns. Here’s what my logic would look like in Node.js using ACE-HipChat:

app.post('/ack_by_text',
    validateJWT, 
    function (req, res) {
		
        var message = req.body;
        var status = 204; 
        if (message.toLowerCase() === "/ack") {
          callDoAck();
        } else if (message.toLowerCase() === "/ackcs") {
          callDoAckCs();
        } else {
          status = 404;
        }
        res.sendStatus(status);
    }
);

#5

Thats an interesting way to do that, just listening to the room and processing the message. I do this in a bunch of other places based on the actual message thats left after the slash command. When I process the message after the slash command, its because that slash command has already called the proper function to parse the message.

I agree, regex always makes me hate life. But I thought this was all supposed to happen in the capabilities descriptor, which is why Im trying to get it to work like that. Is there any way you know of making it work from the pattern match in the descriptor?