Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack: assume any non-JSON response is an incoming webhook #67

Merged
merged 3 commits into from
Mar 28, 2023
Merged

Slack: assume any non-JSON response is an incoming webhook #67

merged 3 commits into from
Mar 28, 2023

Conversation

bfontaine
Copy link
Contributor

@bfontaine bfontaine commented Mar 15, 2023

Slack returns these responses as text/html while Mattermost returns them as text/plain (see grafana/grafana#64079 (comment)). To support both, we need to either add another clause to the if (|| strings.HasPrefix(content, "text/plain")), either reverse the current logic, as does this PR.

I also added tests on the Content-Type header as they were missing. This fixes grafana/grafana#64079.

Slack returns these responses as text/html while Mattermost returns them
as text/plain. To support both, we need to either add another clause to
the if:

    || strings.HasPrefix(content, "text/plain")

either reverse the current logic, as does this commit.
@CLAassistant
Copy link

CLAassistant commented Mar 15, 2023

CLA assistant check
All committers have signed the CLA.

@leitmori
Copy link

@yuri-tceretian @grobinson-grafana Can you please take a look into this pull request to get notifications working again correctly in Mattermost?

Copy link
Contributor

@yuri-tceretian yuri-tceretian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will leave to @grobinson-grafana to give a formal approval as we apply the practice of two reviewers per PR. Thanks for contribution!

@yuri-tceretian
Copy link
Contributor

I think this will need to be backported to 9.4.x branch after this one is merged. I can take care of it.

Copy link
Contributor

@grobinson-grafana grobinson-grafana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I also checked chat.postMessage and it returns application/json so this should work as expected!

@yuri-tceretian yuri-tceretian merged commit c151a6d into grafana:main Mar 28, 2023
yuri-tceretian pushed a commit that referenced this pull request Mar 28, 2023
* Fix typo in test name
* TestSendSlackRequest: test with content-type header
* Slack: assume any non-JSON response is an incoming webhook. Slack returns these responses as text/html while Mattermost returns them as text/plain.
# Conflicts:
#	alerting/notifier/channels/slack_test.go
@bfontaine bfontaine deleted the fix-textplain-slack-response branch March 29, 2023 07:28
yuri-tceretian pushed a commit that referenced this pull request Apr 28, 2023
* Fix typo in test name
* TestSendSlackRequest: test with content-type header
* Slack: assume any non-JSON response is an incoming webhook. Slack returns these responses as text/html while Mattermost returns them as text/plain.
yuri-tceretian added a commit that referenced this pull request Apr 28, 2023
…) (#84)

Co-authored-by: Baptiste Fontaine <b@ptistefontaine.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Slack notifications are repeated in Mattermost
5 participants