Recommended background

As the new generation of migrant workers, the daily allocation of brick time is basically divided into Bug writing, Debug, Battle, fishing, drinking water, going to the toilet… . In addition to these, migrant workers as the front line of the business will occasionally receive the data statistics demand of the product, operation sister and sister, she really want this number is useful, and only you have, some want every day, some want every week, some want irregularly. May also be a few SQL things, do not do background is not worth it, do not do background is not worth it. A brick can be moved once or twice, more can not, or not worthy of the new generation == = these three words.

Is there a tool that is easy to implement and easy to use? No? Then find a way to get one.

Demand characteristics

  • No technical barriers

  • A simple command

  • Certain autonomy

  • Permission control (operations for write types)

  • History (view lookup and action records)

  • A timely response

  • Active feedback

nailing

It seems that implementing a convenient tool is not that easy. After discovering that Nail nail has a group of robots this function, it is really crossing the river to meet the ferry boat — coincidentally, a little packaging can achieve all the requirements above. blinkbean/dingtalk

  • Conversational message interaction

  • Convention Command format

  • Parameters are passed by command

  • You can determine the identity of the message sender by the field in the message body

  • Chat record

  • Send multiple types of messages to robots over Http (see Blinkbean/DingTalk for details)

    • Text
    • Link
    • Markdown
    • ActionCard
    • FeedCard
  • The Http interface can be invoked in @ robot mode. The Outgoing mechanism == must be enabled

use

To obtain

  • go get github.com/blinkbean/dingtalk
    Copy the code

Initialize the

  • // key Key that needs to be set to create the pinning robot. The default is'. '
    func InitDingTalk(tokens []string, key string) *dingTalk
    
    // Create a pin robot with a checkmark
    // Access_token and secret correspond to each other in creating a robot
    func InitDingTalkWithSecret(tokens string, secret string) *DingTalk
    Copy the code
  • import "github.com/blinkbean/dingtalk"
    
    func main(a) {
        // A single robot has a limit on the number of messages per unit of time. If necessary, multiple tokens can be initialized and randomly sent to one of the robots.
        var dingToken = []string{"7bd675b664****dd6684fb1e0415"}
        cli := dingtalk.InitDingTalk(dingToken, ".")
        // Send a text message
        cli.SendTextMessage("content")}Copy the code

General message types

  • // Plain text message
    SendTextMessage(content string, opt ... atOption) error// Link the message
    SendLinkMessage(title, text, picUrl, msgUrl string) error
    // Markdown message format
    SendMarkDownMessage(title, text string, opts ... atOption) error// Ordered list of markdown messages
    SendMarkDownMessageBySlice(title string, textList []string, opt ... atOption) error// Action type message
    SendActionCardMessage(title, text string, opts ... actionCardOption) error// Send Action messages in batches
    SendActionCardMessageBySlice(title string, textList []string, opts ... actionCardOption) error// Feed type message
    SendFeedCardMessage(feedCard []FeedCardLinkModel) error
    // DTMD message (click the link to send the interaction content)
    SendDTMDMessage(title string, dtmdMap *dingMap, opt ... atOption) errorCopy the code
The message preview

OutGoing message

  • With all kinds of tools that can be integrated into the pinning robot, administration and finding became complicated, and so in the form of registries,

  • // Custom methods
    outgoingFunc := func(args []string) []byte {
        // do what you want to
        return NewTextMsg("hello").Marshaler()
    }
    
    // Custom methods are registered with handler
    // Hello keyword, outgoingFunc main method, 2 arguments, true requires identity
    RegisterCommand("hello", outgoingFunc, 2.true)
    
    // Start the HTTP service
    http.Handle("/outgoing", &OutGoingHandler{})
    _ = http.ListenAndServe(": 8000".nil)
    Copy the code
Message preview (Quick access to user information via commands)

To learn more

conclusion

The stitching robot interface is encapsulated, and different message types can be selected according to the application scenario. Achieve low development costs while meeting the diverse reading and writing needs of teammates.

Add pin message test group: 35451012, execute dingtalk_test.go test method to directly view the current supported message content.

The resources

  1. github.com/blinkbean
  2. Ding-doc.dingtalk.com/doc#/server…