Server.Notification.Mattermost

Send notification via Mattermost webhook as described in https://developers.mattermost.com/integrate/webhooks/incoming/


name: Server.Notification.Mattermost
author: Hilko Bengen <bengen@hilluzination.de>
description: |
    Send notification via Mattermost webhook as described in <https://developers.mattermost.com/integrate/webhooks/incoming/>

type: SERVER
parameters:
    - name: url
      description: Webhook URL
        
    - name: text
      description: Markdown-formatted message to display in the post.
            
    - name: channel
      description: Overrides the channel the message posts in.

    - name: username
      description: Overrides the username the message posts as.

    - name: icon_url
      description: Overrides the profile picture the message posts with.
  
    - name: icon_emoji
      description: Overrides the profile picture and icon_url parameter.

sources:
    - query: |
          LET url <= if(
              condition=url,
              then=url,
              else=server_metadata().MattermostWebhookURL)
          LET post_body <= dict(
              text=text,
              format="json")
          LET _ <= if(
              condition=channel,
              then=set(item=post_body, field="channel", value=channel))
          LET _ <= if(
              condition=username,
              then=set(item=post_body, field="username", value=username))
          LET _ <= if(
              condition=icon_url,
              then=set(item=post_body, field="icon_url", value=icon_url))
          LET _ <= if(
              condition=icon_emoji,
              then=set(item=post_body, field="icon_emoji", value=icon_emoji))
          SELECT * from http_client(
              data=serialize(item=post_body),
              headers=dict(`Content-Type`="application/json"),
              method="POST",
              url=url)