Bulk Update Slack Notifications

Hello,

Is it possible not to send a Slack notification if we bulk update more than 10 tickets?

0
3 comments
Official comment

Hi,

I'm Sergey from the YouTrack team.

Yes, you can prevent Slack notifications when bulk updating issues! If you're using the YouTrack App for Slack, simply use the command dialog for your bulk update and select the Apply without notifications option. This will suppress all notifications for that update, including any Slack notifications.

Let me know if you have any questions!

Hello Sergey,

At the moment, choosing not to send a notification only prevents emails from being sent, but Slack notifications are still triggered.

Below is the script we’re currently using to send notifications to Slack:

// Thanks to Michael Rush for the original version of this rule (https://software-development.dfstudio.com/youtracks-new-javascript-workflows-make-slack-integration-a-breeze-d3275605d565)

// IMPORTANT #1: Get a Slack webhook from https://my.slack.com/services/new/incoming-webhook/
// IMPORTANT #2: Don't forget to add the worfklow to the YouTrack project as well

var WEBHOOKS = {
  ACIBS : "https://hooks.slack.com/services/...",
};

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var http = require('@jetbrains/youtrack-scripting-api/http');

exports.rule = entities.Issue.onChange({
  title: 'Send notifications to Slack whenever an issue is reported, resolved, or reopened',
  guard: function(ctx) {
    return ctx.issue.becomesReported || ctx.issue.becomesResolved || ctx.issue.becomesUnresolved;
  },
  action: function(ctx) {
    var issue = ctx.issue;

    var issueLink = '<' + issue.url + "|" + issue.id + '>';
    var message, isNew;
    var projectKey = issue.project.key;


    if (issue.becomesReported) {
      message = "Created: ";
      isNew = true;
    } else if (issue.becomesResolved) {
      message = "Resolved: ";
      isNew = false;
    } else if (issue.becomesUnresolved) {
      message = "Reopened: ";
      isNew = false;
    }
    message += issue.summary;
    
    message = message + " (" + issueLink + ")";
    
    if (projectKey === 'KLS') {
      message = ':warning: ' + message + ' :warning:';
    }

    var changedByTitle = '',
      changedByName = '';

    if (isNew) {
      changedByTitle = "Created By";
      changedByName = issue.reporter.fullName;
    } else {
      changedByTitle = "Updated By";
      changedByName = issue.updatedBy.fullName;
    }

    var payload = {
      "attachments": [{
        "fallback": message,
        "pretext": message,
        "color": issue.fields.Priority ? issue.fields.Priority.backgroundColor : "#edb431",
        "fields": [{
          "title": "State",
          "value": issue.fields.State ? issue.fields.State.name : "Unknown",
          "short": true
        },
          {
            "title": "Priority",
            "value": issue.fields.Priority ? issue.fields.Priority.name : "Unknown",
            "short": true
          },
          {
            "title": "Assignee",
            "value": issue.fields.Assignee ? issue.fields.Assignee.fullName : '',
            "short": true
          },
          {
            "title": changedByTitle,
            "value": changedByName,
            "short": true
          }
        ]
      }]
    };
    
    var connection = null;
    
    /** special scenario for KLW and KLERP */
    if (projectKey === 'KLS') {
      switch (issue.fields.WebOrErp.name) {
        case 'WEB': projectKey = 'KLW';
          break;
        case 'ERP': projectKey = 'KLERP';
          break;
        default:
          projectKey = 'KLERP';
      }
    }
    
    if (WEBHOOKS[projectKey] !== undefined) {
      connection = new http.Connection(WEBHOOKS[projectKey], null, 2000);
    } else {
      console.warn('Notifications for this project are disabled: ' + projectKey + ' - feel free to add it to WEBHOOKS');
      return false;
    }

    var response = connection.postSync('', null, JSON.stringify(payload));
    if (!response.isSuccess) {
      console.warn('Failed to post notification to Slack. Details: ' + response.toString());
    }
  },
  requirements: {
    Priority: {
      type: entities.EnumField.fieldType
    },
    State: {
      type: entities.State.fieldType
    },
    Assignee: {
      type: entities.User.fieldType
    }
  }
});

 

0

Hi there,

Thanks for your response!

At the moment, choosing not to send a notification only prevents emails from being sent, but Slack notifications are still triggered.

As I mentioned, this behavior applies specifically when using the default YouTrack app for Slack. Since you're using a custom script, the "Apply without notifications" option has no effect on the script. 

Hence, you need to design this logic within your custom solution. For example, you can silently add a tag to these issues that you want to update, then include logic in your script to check for this tag and skip sending notifications for issues that have it.

 If you have any questions, please let me know. 

0

Please sign in to leave a comment.