-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Hi,
TLDR : It would be nice to allow customization of http headers sent + a pre-login phase
Long version :
I want to use Webhook (latest version 1.0.12) to send a message to our instance of Rocket Chat.
I don't actually understand how the multiple platforms are managed. I saw the 3 authentication methods (None / Basic Auth / Encoded Basic Auth), but none of them apply to Rocket Chat, since it requires two specific headers : X-Auth-Token and X-User-Id (source).
For my testing purposes, I used secret field for X-Auth-Token and user field for X-User-Id, and I didn't bother to add a new Auth Method, so I simply added following lines in inc/notificationeventwebhook.class.php :
case 1: // No Authentication
$headers =
[
'Content-type: application/json',
'X-Auth-Token: '.$webhook_infos['additionnaloption']['secret'],
'X-User-Id: '.$webhook_infos['additionnaloption']['user']
];
break;I don't know how long token is valid, so I'm fully aware this piece of code is messy (not to mention I broke the "no authentication" case). A better approach would be to log in first, get token, and then post message.
I'm surprised this problem doesn't occur more often : it seems to me each platform has its own method, and headers can't literally be anything.
Since follow all platforms and all possible actions and update the code accordingly is impossible, I think it would be a great addition if user could set http headers.
However, it would solve half of the problem with rocket chat, since it requires to be logged in before the message posting.
I'm not quite sure it would address every problem, but an option allowing us to login (login url + name of token field to be used in "real" request) in a first place may be useful.
For the record, there is a wrapper to use rocket chat. Not quite sure it's useful (post message in chat and send message to single user are the two only functions which make sense IMHO), but an option to use a library could be a possible solution too.