- For an internal app, we recommend subscribing to callback events directly from the Developer Console. For details, see Configure Event Subscription.
- For a third-party enterprise app, we recommend subscribing to callback events through SyncHTTP push or RDS push. Both methods let you use the pushed data directly and are simpler to configure. For details, see Callback Overview.
- The outbound IP addresses for HTTP push are 203.119.0.0/16, 140.205.0.0/16, 106.11.0.0/16, and 198.11.0.0/16.
Use Cases
- When your business requires high data timeliness. For example, when an employee joins or leaves, the app must update user data immediately. In this case, subscribe to Contacts events.
- When your app needs to respond promptly to user actions. For example, when a user joins a group chat, the app can subscribe to group chat events and send a welcome message when the user enters the group chat.
- When an Admin activates a third-party enterprise app, DingTalk pushes the enterprise authorized app activation event. Developers can activate the organization and enable the app based on the pushed corpid.
HTTP Event Callback Process
The HTTP event callback process is shown below:- Configure an HTTP request endpoint on the DingTalk Open Platform to receive pushed callback events.
- DingTalk pushes callback event data packages to the HTTP endpoint configured for the app. The data is encrypted with the encryption/decryption key entered in the Developer Console when the app was created, and signed with the app Token you provided. For details, see Test the Callback URL Event.
- After receiving the push, the app must verify the signature, decrypt the data, and return JSON data that contains the encrypted string.
- Call the Register Event Callback API to receive callback events.
Configure the Request Endpoint and Events
To receive DingTalk’s pushed subscription events over HTTP callbacks, first configure the HTTP callback URL. When a subscribed event is triggered, DingTalk sends a corresponding HTTP POST request to this URL.- Sign in to the Developer Console. Find the app you created and open its details page.
- Click Development Management, then click Edit, and set the push type to HTTP Push.
-
Configure the HTTP endpoint used to receive requests.
-
token: Each time DingTalk pushes event data to your endpoint, it includes a
tokenthat is used to generate the signature and verify the legitimacy of the callback request. It must contain only English letters or digits and be 3 to 32 characters long. - Data Encryption Key: Click Auto Generate to generate an AES key. This is the parameter used to encrypt and decrypt callback message content, and it is the Base64-encoded AES key. For usage, see Message Encryption and Decryption.
- Callback URL: The URL used to receive subscription event requests. When a subscribed event is triggered, DingTalk sends a corresponding HTTP POST request to this URL. Note Each app can configure only one callback URL. All event notifications for the app’s subscribed events are sent to this request URL.
-
token: Each time DingTalk pushes event data to your endpoint, it includes a
-
After completing the configuration, when you click the Validate button, the Open Platform pushes an
application/jsonPOST request to the URL you configured to verify its legitimacy. The request is as follows:When you receive the POST validation request from the Open Platform, decrypt it and return an encrypted string containing success (in JSON format) within 1500 ms. After the DingTalk Open Platform receives the returned JSON, it decrypts it. If it obtains the expected success string, the callback push is verified as normal; otherwise, the callback is judged as failed. - After successfully configuring the request endpoint, click Save in the upper-right corner.
Receive and Respond to Events
-
Receiving Event Information
When an event occurs, DingTalk proactively sends a POST request to the configured HTTP endpoint, pushing the corresponding event information. For example, after you subscribe to Contacts events, when the Contacts change, DingTalk pushes the event information to the registered HTTP endpoint in the following format.
-
The request URL format is as follows:
-
The JSON data included is as follows:
- signature is the message body signature.
- timestamp is the timestamp.
- nonce is a random string.
- encrypt is the encrypted pushed event information.
-
The request URL format is as follows:
-
Responding to Event Information
For all callback events, after you receive an event push, you must return an encrypted string containing success to DingTalk. Only when this data is returned does DingTalk consider the event push successful.
The specific data format returned to DingTalk is as follows:
Where:
- msg_signature is the message body signature.
- timeStamp is the timestamp.
- nonce is a random string.
- encrypt is the encrypted success string.
Message Encryption and Decryption
To ensure the security of data transmission, when DingTalk pushes subscription events to the callback URL, it includes the configured token to verify the event source. It also uses the key to symmetrically encrypt the message content. Click here to get the callback encryption/decryption library and the corresponding demo. The DingTalk server encodes the plaintext message body (msg) intoencrypt. encrypt = Base64_Encode(AES_Encrypt[random(16B) + msg_len(4B) + msg + $key]) is the Base64 encoding after encrypting the plaintext message msg. Where:
- random is a 16-byte random string.
- msg_len is the 4-byte length of msg, in network byte order.
- msg is the plaintext message body.
- key is the app’s suiteKey.
- Base64-decode the ciphertext: aes_msg=Base64_Decode(encrypt);
- Use AESKey to perform AES decryption: rand_msg=AES_Decrypt(aes_msg);
Related Links
- Event List