Skip to content

Commit

Permalink
Use port in Mattermost only if defined
Browse files Browse the repository at this point in the history
When we generate a MM notification URL with default port:
>>> NotifyMattermost(token="secret", host="chat.example.com", port=443, secure=True).url()
'mmosts://chat.example.com/secret/?image=no&format=text&overflow=upstream'

And then try to send it:

```
ac=Apprise()
ac.add(NotifyMattermost(token="secret",
                        host="chat.example.com", port=443, secure=True).url())

ac.notify("testing")
```

It fails. In debug logs we can see:
`DEBUG:apprise:Mattermost POST URL:
https://chat.example.com:None/hooks/secret (cert_verify=True)`

Port is always included in the POST url, but if port matches default
value for given "secret" we might not have it defined.

So let's only include port in Mattermost URL if not None
  • Loading branch information
Stanislav Ochotnický committed Feb 22, 2025
1 parent 9bd20a2 commit 786f8a8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions apprise/plugins/mattermost.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
# Set our user
payload['username'] = self.user if self.user else self.app_id

port = ''
if self.port is not None:
port = ':{}'.format(self.port)

# For error tracking
has_error = False

Expand All @@ -215,8 +219,8 @@ def send(self, body, title='', notify_type=NotifyType.INFO, **kwargs):
if channel:
payload['channel'] = channel

url = '{}://{}:{}{}/hooks/{}'.format(
self.schema, self.host, self.port,
url = '{}://{}{}{}/hooks/{}'.format(
self.schema, self.host, port,
self.fullpath.rstrip('/'), self.token)

self.logger.debug('Mattermost POST URL: %s (cert_verify=%r)' % (
Expand Down

0 comments on commit 786f8a8

Please sign in to comment.