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

Rocketchat webhook payload without "payload=" #9869

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

joconcepts
Copy link

SUMMARY

Rocketchat webhook does not need to have payload={{data}} as payload but only data directly as payload.

bugfixes:
  - rocketchat: fix webhook payload
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

rocketchat

ADDITIONAL INFORMATION
# before the payload was like this:
"payload={\"text\": \"Test\", \"channel\": \"#test\", \"username\": \"me\", \"icon_url\": \"https://docs.ansible.com/favicon.ico\", \"link_names\": 1}"}

# but this results in a 400 bad request
"body": "{\"success\":false,\"error\":\"Unexpected token 'p', \\\"payload{\\\"t\\\"... is not valid JSON\"}"

# after this change the payload is like that
"{\"text\": \"Test\", \"channel\": \"#test\", \"username\": \"me\", \"icon_url\": \"https://docs.ansible.com/favicon.ico\", \"link_names\": 1}"

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module new_contributor Help guide this first time contributor plugins plugin (any type) small_patch Hopefully easy to review labels Mar 11, 2025
@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch labels Mar 11, 2025
@felixfontein
Copy link
Collaborator

Since this has been part of the module for many years (basically since its inception in 2016: ansible/ansible@20ea765), I guess that RocketChat's behavior changed over time.

Since RocketChat can be self-hosted, this looks like a breaking change to me that needs some mechanism so it also works with older versions of RocketChat.

Pinging the last person to contribute (a64df65) to this module, @mmslkr, who might be still using it as well.

@felixfontein
Copy link
Collaborator

Another PR with the same change came up: #9882

I looked a bit at Rocket.Chat, and my guess is that RocketChat/Rocket.Chat@263a7cb caused this change. That commit ended up in Rocket.Chat 7.4.0 (and all its release candidates).

Looking at https://github.com/RocketChat/Rocket.Chat/pull/34999/files#diff-ed9bdef3b65986a40ddc3a005e5b490e513df772ca3398c8f55f8e0460d90760R245, I think the current syntax is still fine once the content-type header is set to application/x-www-form-urlencoded. (My guess is that before the content-type header would have to be set to JSON without the payload=, but 🤷)

Can someone try to change the module to instead send the content-type header with value application/x-www-form-urlencoded and see whether that works? I think that would be the less dangerous patch.

For that, the line response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload) needs to be changed to response, info = fetch_url(module, rocketchat_incoming_webhook, data=payload, headers={'content-type': 'application/x-www-form-urlencoded'}) or something like that.

@broferek
Copy link

@felixfontein I tried making it work with your suggestions around adding the header. But I couldn't end up with a working solution.

Instead, I made a new commit in my branch which basically uses the new syntax by default and falls back to the old one if it failed.

I assume that it doubles the number of queries but we can assume the majority of Rocket Chat users will upgrade to at least Rocket Chat 7.4.0 in the coming year as per Rocket Chat deprecating version policy, therefore the fallback should not be used anymore or by very few people by then.

@felixfontein
Copy link
Collaborator

It looks like they removed the code that handles that in RocketChat/Rocket.Chat#35183. I have no idea why it's called a regression; it should rather be called a breaking change and mentioned in the changelog.

@russoz
Copy link
Collaborator

russoz commented Mar 18, 2025

#9882 is kinda moving faster. May I suggest we consolidate our efforts in that PR? (And close this one)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch backport-10 Automatically create a backport for the stable-10 branch bug This issue/PR relates to a bug check-before-release PR will be looked at again shortly before release and merged if possible. module module new_contributor Help guide this first time contributor plugins plugin (any type) small_patch Hopefully easy to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants