Automate DingTalk Alerts for Azure DevOps Pull Requests with n8n

This workflow solves the challenge of timely notifying teams on DingTalk about new Azure DevOps Pull Requests by automatically mapping users from Azure to DingTalk via MySQL, then sending formatted messages through a webhook. It streamlines review processes and cuts down on missed notifications.
mySql
webhook
code
+2
Workflow Identifier: 2447
NODES in Use: MySQL, Webhook, Code, HTTP Request, Sticky Note
Automate alerts with n8n and MySQL

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What This Workflow Does

This workflow sends a message to DingTalk group chat every time a new Azure DevOps Pull Request (PR) is created. It uses a MySQL table to match Azure DevOps users with DingTalk contacts, so the correct people get mentioned automatically. This removes manual work and makes sure PR reviews happen faster.

The workflow listens for PR creation events from Azure DevOps via a webhook. It then loads user mappings from MySQL. A Code node builds a DingTalk markdown message, replacing Azure usernames with DingTalk names and adding @ mentions. The message posts to DingTalk using an HTTP request. If a reviewer group means “team,” the workflow mentions all members instead of individuals.


Who Should Use This Workflow

This is for teams managing software development in Azure DevOps who want faster and accurate review notifications in DingTalk. It suits team leads or DevOps engineers who need to cut down manual messaging delays and errors. Users must have access to Azure DevOps with service hooks, a MySQL database for user maps, and DingTalk robot access.


Tools / Services Used

  • Azure DevOps: Sends Pull Request Created webhook events.
  • MySQL database: Stores mappings of Azure DevOps usernames to DingTalk usernames and mobile numbers.
  • n8n: Runs the automation workflow to receive, process, and send messages.
  • DingTalk robot webhook: Used to post markdown messages with user mentions to group chats.

Inputs, Processing Steps, and Output

Inputs

  • Webhook event JSON from Azure DevOps when a new Pull Request is created.
  • User mapping data from tfs_dingtalk_account_map MySQL table.

Processing Steps

  • Receive webhook: The ReceiveTfsPullRequestCreatedMessage gets the PR data.
  • Load user map: The LoadDingTalkAccountMap MySQL node fetches mappings.
  • Build message: The BuildDingTalkWebHookData Code node replaces Azure DevOps usernames with DingTalk names, finds reviewers’ mobile numbers, and prepares @ mentions. It checks if the reviewers include a “team” group to mention all instead.
  • Send message: The SendDingTalkMessageViaWebHook node posts a markdown message with mentions to DingTalk using the robot webhook URL.

Output

A DingTalk group chat message that alerts the right people about the new Pull Request with correct @ mentions. If “team” is included, all members of the group are notified.


Beginner Step-by-Step: How to Use This Workflow in n8n

Import the Workflow

  1. Download the provided workflow file using the Download button on this page.
  2. Open the n8n editor where you want to run the automation.
  3. Import the workflow by clicking “Import from File” and select the downloaded file.

Configure Credentials and Settings

  1. Set up the MySQL credentials in the LoadDingTalkAccountMap node to connect to the database containing user mappings.
  2. Enter the DingTalk robot webhook URL into the SendDingTalkMessageViaWebHook node HTTP request settings.
  3. Check the webhook address of the ReceiveTfsPullRequestCreatedMessage. Make sure it matches the Azure DevOps service hook URL and path (pr-notify-template).
  4. If needed, update any user account identifiers or table names in MySQL matching your environment.

Test and Activate

  1. Run a test from Azure DevOps by creating a new Pull Request. Confirm the workflow triggers and the message posts to DingTalk with correct user mentions.
  2. Once tested, activate the workflow in n8n by switching it on for continuous listening.
  3. Optional: Monitor executions in n8n UI and logs for failures or mapping issues.

For teams running self-host n8n, make sure your server is reachable by Azure DevOps, and endpoints are secured.


Code Explanation for Message Building

The Code node matches Azure DevOps usernames to DingTalk mobile numbers and usernames using data fetched from MySQL:

  • Functions scan mappings and return matched DingTalk mobile or user name.
  • The PR creator display name is replaced with the DingTalk name in the message.
  • All reviewers’ usernames are checked: if “team” is detected, a flag to mention all (@all) is set.
  • Otherwise, mobiles and names for mentions collect into arrays.
  • The final markdown text adds @ mentions of correct DingTalk users or @all if flagged.

This ensures precise mention and highlighting for timely reviews.

Below is the core JavaScript for this mapping and message composition:

// Map Azure DevOps accounts to DingTalk mobile numbers and names
var mapUserMobile = function (tfsAccount) {
  for(var i = 0; i < items.length; i++) {
    var map = items[i].json;
    if(tfsAccount.lastIndexOf(map.TfsAccount) != -1) {
      return map.DingTalkMobile;
    }
  }
  return null;
}

var mapUserName = function (tfsAccount) {
  for(var i = 0; i < items.length; i++) {
    var map = items[i].json;
    if(tfsAccount.lastIndexOf(map.TfsAccount) != -1) {
      return map.UserName;
    }
  }
  return null;
}

// Build message content with @ mentions and replacements
var tfsMessage = $node["ReceiveTfsPullRequestCreatedMessage"].json.body;

// Replace PR creator display name with DingTalk name
var prCreatorTfsDomainName = tfsMessage.resource.createdBy.uniqueName;
var prCreatorTfsDisplayName = tfsMessage.resource.createdBy.displayName;
var prCreatorDingTalkName = mapUserName(prCreatorTfsDomainName);

if (prCreatorDingTalkName !== null) {
  messageText = messageText.replace(prCreatorTfsDisplayName, prCreatorDingTalkName);
}

// Collect DingTalk mobiles to @ for reviewers
for (reviewer of tfsMessage.resource.reviewers) {
  if(reviewer.uniqueName.lastIndexOf("团队") != -1) {
    isAtAll = true;
    continue;
  }
  var mobile = mapUserMobile(reviewer.uniqueName);
  if(mobile !== null) {
    atMobiles.push(mobile);
  }
  var userName = mapUserName(reviewer.uniqueName);
  if(userName !== null) {
    atUsers.push(userName);
  }
}

// Compose final message with @ mentions
if(isAtAll) {
  atUsers.unshift("所有人");
  atMobiles = [];
} else {
  atUsers = atMobiles;
}

if (atUsers.length > 0) {
  messageText = messageText + "
请 @" + atUsers.join(" @") + " 评审"; } return [{json: {isAtAll, text: messageText, atMobiles: atMobiles.join(", ")}}];

Common Problems and How to Fix

  • No data from MySQL node: Check database credentials and table name. Fix any typos or access issues.
  • Webhook does not trigger: Recheck the Azure DevOps service hook URL, HTTP method must be POST, and the event should be Pull Request Created.
  • DingTalk messages missing mentions: Update MySQL user mapping table to cover all usernames. Use workflow logs to find missing mappings.

Customization Ideas

  • Edit the Code node to change message text, formatting, or add project links.
  • Add extra fields in MySQL and update the Code node to support email or display names.
  • Duplicate DingTalk HTTP nodes to send messages to multiple groups based on project criteria.
  • Add triggers for Pull Request updates by configuring additional Azure DevOps service hooks and workflow branches.
  • Control when to mention all users via conditions in the Code node for specific reviewer groups.

Summary of Results

✓ Complete automation of PR notifications from Azure DevOps to DingTalk with accurate user mentions.
✓ Saves several hours weekly by removing manual messaging.
✓ Ensures no Pull Request is missed or delayed in review.
✓ Allows easy customization of message content and notification scope.
✓ Works within n8n with simple setup and clear monitoring options.


Automate alerts with n8n and MySQL

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

The webhook may not trigger if the webhook URL or path is incorrect, the HTTP method is not POST, or the service hook event is not set to Pull Request Created.
The workflow uses a MySQL table to map Azure DevOps usernames to DingTalk usernames and mobile numbers, matching them in a Code node to insert correct @ mentions.
Yes, by duplicating the HTTP Request nodes and adding logic in the Code node, the workflow can send messages to different DingTalk group webhooks based on project or branch.
Yes, the JavaScript in the Code node can be edited to change markdown content, add links, or adjust how user mentions display.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.