Implement OutGoing robot functionality
masterDingTalk OutGoing allows you to bind an HTTP POST endpoint to your robot. When a user @mentions the robot in a group, DingTalk sends a JSON payload to your endpoint, and your service can respond with a message.
- Enable
Outgoingmechanism in DingTalk robot settings. - Configure a public POST URL.
- Use
RegisterCommandto map commands to logic andOutGoingHandlerto serve the requests.
Command Registration:
RegisterCommand(name string, execFunc ExecFunc, arity int, isAdmin bool)name: The command trigger.execFunc: A functionfunc(args []string) []bytethat processes the command and returns the response bytes.arity: Number of arguments expected.isAdmin: Whether the command is restricted to admins.
// Define the command logic
outgoingFunc := func(args []string) []byte {
// Return a message using the library's marshaler
return NewTextMsg("hello").Marshaler()
}
// Register the command
RegisterCommand("hello", outgoingFunc, 2, true)
// Start the HTTP server to handle incoming DingTalk requests
http.Handle("/outgoing", &OutGoingHandler{})
_ = http.ListenAndServe(":8000", nil)