The premise

First you have to have a server

Next you nail ten users

That’s enough!

So let’s get started

Nailing building group

  1. Click the ‘+’ sign in the upper right corner to initiate a group chat. Set up a group chat
  2. Open group Settings and click smart Group Assistant
  3. Click Add Robot

Don’t choose Github, which is optional. But the message cannot be customized

The default Github message looks like this

  1. We chose custom

All right! The nail configuration is complete!

Making configuration

  1. Let’s start by creating a script project
  2. Configuration items

  1. Create a WebHooks

Project example

Class libraries are used

  • express
  • nodemon
  • dingtalk-robot-sender

Dingtalk-robotsender is a node wrapper library that allows you to configure push messages more easily

const express = require('express');
const ChatBot = require('dingtalk-robot-sender');
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

// The robot is initialized
const robot = new ChatBot({
  baseUrl: 'https://oapi.dingtalk.com/robot/send'.// Here is a pin generated in webhook? The token after the
  accessToken: '23fc2e7dce780xxxxxx7358b11'.// Here is the signature
  secret: 'SECb71f7754xxxxxxbb915613f04'}); app.post('/notice'.async (req, res) => {
    // The received message is processed here
    /** Get the user name */
    const { name } = req.body.pusher;
    /** Get the submission information */
    const { message, timestamp, url } = req.body.head_commit;
    /** Get the avatar */
    const { avatar_url, html_url } = req.body.sender;
    /** Project name */
    const projectName = req.body.repository.name;
    /** Project home page */
    const projectHtml = req.body.repository.html_url;
    
    /** Push text message */
    const content = 'And take the misgible eyes of others as a beacon of fire, and walk boldly in the night. ';
    const at = {
        // user@specific user
        atMobiles: ['177xxxx9889'].isAtAll: false};// text - Send messages quickly
    await robot.text(content, at);
    
    /** card - Code submission information */
    const title = 'Code Submission';
    const text =
        '## Code submission information @177XXXX9889 \n' +
        '> Project: [${projectName}] (${projectHtml}) \n\n` +
        ` >${message} \n\n` +
        '> Submitted by: @${name} \n` +
        ` >! [screenshot](http://cdn.wangdaoo.com/github.jpeg)\n` +
        ` > time:${timestamp}[View details](${url}) \n`;

    const at2 = {
        atMobiles: ['177xxxx9889'].isAtAll: false};await robot.markdown(title, text, at2);
    
    res.send({ data: 'Success' });
})

app.listen(8009.() = > {
  console.log('listening on 8009... ');
});
Copy the code

Server Deployment

  1. Push the finished code to the server
  2. Build with Docker (or run the project directly) and run
// Docker is not used
nodemon index.js

/ / use the docker
docker build -t ddnotice .

// Run the image
docker run -d --name notice -p 8009:8009[the mirror id]Copy the code

We ended up getting push messages every time we submitted code Spikes

Wangdaoo/dingtalk-notice: (github.com)

Group experience/questions