Fix payload to match Rocket Chat 7.4.1 API (#9882)

* Fix payload to match Rocket Chat 7.4 API

* Add a fallback to send payload argument in case the user still interacts with a Rocket Chat version < 7.4.0

* Fix sanity checks

* Add changelog fragment of PR #9882

* Add argument option_is_pre740 to keep backward compatibility of the payload

* Add new argument doc

* Rename new parameter, add missing pieces of information in parameter doc

* Use appropriate change label and fix change description. Description about future plans for the parameter is now set at the parameter doc level

* Fix missing punctuation in the new parameter doc block

* Improve documentation.

* Fix line length.

---------

Co-authored-by: ludovic <ludovic.petetin@aleph-networks.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
X 2025-03-24 05:45:01 +01:00 committed by GitHub
parent ec38a82ef1
commit c3b0354da0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 4 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- rocketchat - option ``is_pre740`` has been added to control the format of the payload. For Rocket.Chat 7.4.0 or newer, it must be set to ``false`` (https://github.com/ansible-collections/community.general/pull/9882).

View file

@ -100,6 +100,15 @@ options:
elements: dict
description:
- Define a list of attachments.
is_pre740:
description:
- If V(true), the payload matches Rocket.Chat prior to 7.4.0 format.
This format has been used by the module since its inception, but is no longer supported by Rocket.Chat 7.4.0.
- The default value of the option will change to V(false) eventually.
- This parameter will be removed in a future release when Rocket.Chat 7.4.0 becomes the minimum supported version.
type: bool
default: true
version_added: 10.5.0
"""
EXAMPLES = r"""
@ -165,7 +174,7 @@ from ansible.module_utils.urls import fetch_url
ROCKETCHAT_INCOMING_WEBHOOK = '%s://%s/hooks/%s'
def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments):
def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, is_pre740):
payload = {}
if color == "normal" and text is not None:
payload = dict(text=text)
@ -195,7 +204,9 @@ def build_payload_for_rocketchat(module, text, channel, username, icon_url, icon
attachment['fallback'] = attachment['text']
payload['attachments'].append(attachment)
payload = "payload=" + module.jsonify(payload)
payload = module.jsonify(payload)
if is_pre740:
payload = "payload=" + module.jsonify(payload)
return payload
@ -225,7 +236,8 @@ def main():
link_names=dict(type='int', default=1, choices=[0, 1]),
validate_certs=dict(default=True, type='bool'),
color=dict(type='str', default='normal', choices=['normal', 'good', 'warning', 'danger']),
attachments=dict(type='list', elements='dict', required=False)
attachments=dict(type='list', elements='dict', required=False),
is_pre740=dict(default=True, type='bool')
)
)
@ -240,8 +252,9 @@ def main():
link_names = module.params['link_names']
color = module.params['color']
attachments = module.params['attachments']
is_pre740 = module.params['is_pre740']
payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments)
payload = build_payload_for_rocketchat(module, text, channel, username, icon_url, icon_emoji, link_names, color, attachments, is_pre740)
do_notify_rocketchat(module, domain, token, protocol, payload)
module.exit_json(msg="OK")