This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.

⚠️ We've moved!

Hi there!

To reduce project dependency on 3rd party paid services the StackStorm TSC has decided to move the Q/A from this forum to Github Discussions. This will make user experience better integrated with the native Github flow, as well as the questions closer to the community where they can provide answers.

Use 🔗 Github Discussions to ask your questions.

Slack extra feature to get different colours

This useful tip was seen in the #community stackstorm channel by cygnetix. It allows extra.slack.color to hold a jinja templates but treated as a string by the StackStorm core. The template is processed by chatops.format_message's jinja engine.

Hey all. I’m trying to get an alias to show a different color in slack depending on the returned value. Slack looks like it’ll only work if the value is all one one line but I’m having some trouble getting my Jinja formatting to do this.

Here’s an example which fails because (I suspect) it introduces multiple lines in the color value:

    slack:
      color: |
        {%- if execution.result.positives > 0 -%}
        danger
        {%- else -%}
        good
        {%- endif -%}

This example results in a failure when I try to register the pack:

    slack:
      color: {%- if execution.result.positives > 0 -%} danger{%- else -%}good{%- endif -%}

Just FYI. I found a solution that works (use >-):

    slack:
      color: >-                                                                  
        {%- if execution.result.result.results.positives == 0 -%}                
        good                                                                     
        {%- else -%}                                                             
        danger                                                                   
        {%- endif -%}
1 Like

Thanks! That’s a great use of the “block chomping indicator” from YAML. Glad you got it to work!

1 Like