mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-27 04:41:26 -07:00
callbacks/slack: Explicitly set Content-Type header (#51824)
There are other chat systems with hook implementations more or less compatible with Slack, such as Rocket.Chat. The latter requires the Content-Type header to be set to "application/json" (the body is JSON). Signed-off-by: Michael Hanselmann <public@hansmi.ch>
This commit is contained in:
parent
7fbacf920d
commit
76ab88c9f5
2 changed files with 10 additions and 1 deletions
4
changelogs/fragments/51824-slack-req-content-type.yaml
Normal file
4
changelogs/fragments/51824-slack-req-content-type.yaml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
minor_changes:
|
||||||
|
- >-
|
||||||
|
slack: Explicitly set Content-Type header to "application/json" for
|
||||||
|
improved compatibility with non-Slack chat systems
|
|
@ -114,6 +114,10 @@ class CallbackModule(CallbackBase):
|
||||||
'variable.')
|
'variable.')
|
||||||
|
|
||||||
def send_msg(self, attachments):
|
def send_msg(self, attachments):
|
||||||
|
headers = {
|
||||||
|
'Content-type': 'application/json',
|
||||||
|
}
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'channel': self.channel,
|
'channel': self.channel,
|
||||||
'username': self.username,
|
'username': self.username,
|
||||||
|
@ -127,7 +131,8 @@ class CallbackModule(CallbackBase):
|
||||||
self._display.debug(data)
|
self._display.debug(data)
|
||||||
self._display.debug(self.webhook_url)
|
self._display.debug(self.webhook_url)
|
||||||
try:
|
try:
|
||||||
response = open_url(self.webhook_url, data=data, validate_certs=self.validate_certs)
|
response = open_url(self.webhook_url, data=data, validate_certs=self.validate_certs,
|
||||||
|
headers=headers)
|
||||||
return response.read()
|
return response.read()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._display.warning(u'Could not submit message to Slack: %s' %
|
self._display.warning(u'Could not submit message to Slack: %s' %
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue