infojunkie / MantisBT-Slack

Slack integration for Mantis bug tracker
GNU General Public License v2.0
48 stars 37 forks source link

Mattermost: Error on sending #40

Closed bafplus closed 6 years ago

bafplus commented 7 years ago

The error: APPLICATION ERROR #plugin_Slack_ERROR_CURL The request to Slack didn’t go through. Check your webhook URL. Also make sure there are no unusual characters in your bot name or bot icon settings. Further details may be printed below this box. Please use the “Back” button in your web browser to return to the previous page. There you can correct whatever problems were identified in this error or select another action. You can also click an option from the menu bar to go directly to a new section.

I cant seem to find something wrong else then a empty UID in the string. There was a commit 6 days ago in the 1.2 branch that fixes a simular issue. 90406927fd6e022af2d7d900b1d2e67c5d86bf8d

bafplus commented 7 years ago

If i replace the webhook with a slack webhook everything works fine. So there is something of in the mattermost code in this plugin or at mattermost code.

I myself are no coder so have no clue where to look for a fix.

infojunkie commented 7 years ago

Strange, it's the same commit that went into both branches. @secustor would you mind validating that the latest master works with Mattermost for you?

bafplus commented 7 years ago

Only the 1.2 branch was merged

infojunkie commented 7 years ago

Here's the commit on master: https://github.com/infojunkie/MantisBT-Slack/commit/8aa67a830ca791936c05eede149d240d95579bcb - or is there another one I missed?

bafplus commented 7 years ago

Probably because the slack.php in main branch was last updated 2 months ago?

Not saying its the root of my issue, but looks related.

infojunkie commented 7 years ago

The commit I point to above was made 6 days ago on master. Please make sure you are pulling the latest code, and from the correct repo: https://github.com/infojunkie/MantisBT-Slack or https://github.com/mantisbt-plugins/Slack

bafplus commented 7 years ago

naamloos So...why is it 2 months there? Or am i missing something?

infojunkie commented 7 years ago

I see.. the patch was submitted two months ago. I merged the PR 6 days ago.

bafplus commented 7 years ago

So that should be ok then?

infojunkie commented 7 years ago

Yes, the patch is in there. I doubt I will have time to test Mattermost myself, so I hope @secustor can confirm.

bafplus commented 7 years ago

I wil test the master

bafplus commented 7 years ago

I just tested current master and stil get that error.

secustor commented 7 years ago

@bafplus try to add the following line to Slack.php at line 268 (1.2.x branch) right before the post fields.

        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));

It then should look like this:

        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        $result = curl_exec($ch);
        if ($result !== 'ok') {
            trigger_error(curl_errno($ch) . ': ' . curl_error($ch), E_USER_WARNING);
            plugin_error('ERROR_CURL', E_USER_ERROR);
        }
        curl_close($ch);

This will tell mattermost how to exactly handle the request, this shouldn't be necessary, but its worth a try.

bafplus commented 7 years ago

but i use mantis 2.x?

secustor commented 7 years ago

For 2.x that would be line 295.

        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
pklooster commented 7 years ago

last fix for 2.x is working for me.

Thank you.

bafplus commented 7 years ago

confirmed, @secustor that worked

infojunkie commented 7 years ago

Sorry, I closed too soon - I will add the relevant lines to both branches.

dimitriacosta commented 7 years ago

I can't make it work on mattermost, I may configured mantis wrong, I don't know but I need some help here, can you guys give me a hand?

Here's my current settings, oh by the way the webhook url is not for slack it is for my private mattermost

screen shot 2017-11-14 at 10 56 49 am

secustor commented 7 years ago

@dimitriacosta Your default channel is not valid. For mattermost you have to use the channel name as provided in the URL and without the hashtag e.g. 'town-square' for the Vanilla default channel

dimitriacosta commented 7 years ago

Hi @secustor thanks for your quick answer.

I did what you said and here's my new settings

screen shot 2017-11-14 at 12 58 14 pm

It's still not working because every time I create a new issue I got this error

APPLICATION ERROR #plugin_Slack_ERROR_CURL

The request to Slack didn't go through. Check your webhook URL. Also make sure there are no unusual characters in your bot name or bot icon settings. Further details may be printed below this box.
Please use the "Back" button in your web browser to return to the previous page. There you can correct whatever problems were identified in this error or select another action. You can also click an option from the menu bar to go directly to a new section.
secustor commented 7 years ago

@dimitriacosta You have forgoten to mask the webhook on your second screenshot.

Activate the debug mode for webhooks in Mattermost and check what it is receiving.

dimitriacosta commented 7 years ago

@secustor I got something like this [2017/11/14 20:09:33 UTC] [EROR] /hooks/<key>:IncomingWebhookRequestFromJson code=400 rid=3gjnzmnrxb8qfkof7p5ncae36o uid= ip=187.189.17.225 Unable to parse incoming data [details: EOF]

dimitriacosta commented 7 years ago

Hey @secustor I found this in my mattermost instance

screen shot 2017-11-14 at 3 03 15 pm

I guess that's from you 😅 but I just can't make it work 😔

dimitriacosta commented 7 years ago

I am running mantis from a docker image so maybe there is something wrong with it, to be hones I have no idea.

It works perfectly fine with slack but not in mattermost.

By the way, notifications are sent only if the issue is created as public, if I make an issue as private I don't get anythinng

secustor commented 7 years ago

Do you have added the line above to the plugin? If yes, please share the ticket which you try to open, so I can try to reproduce the error on my local system.

That private issues are not sent is normal behaviour.

dimitriacosta commented 7 years ago

Oh I didn't noticed that line was removed when I recreated the docker image, I've just aded that line and its working fine now.

But now I have another question, what if I want mantis to send notifications even if issues are private? Considering that I have a private channel for the development team

secustor commented 7 years ago

In that case you have to modify the source code. Line 266 of Slack.php is a hot hint ;) . This will ignore the privacy setting of all issues and notes. BE WARNED!

On the mattermost side you need to create a webhook specific to the private channel and then let the plugin write on it too.

dimitriacosta commented 7 years ago

Great it worked, thank you very much for your help 👍

infojunkie commented 7 years ago

Thanks everyone. Will update the branches when I'm back at a computer one week from now.