WeCom App Access Statistics and Push
WeChat Work supports apps directly pushing messages to users. Leveraging this capability, we can collect various app data and through scheduled pushes, obtain usage statistics of the apps. This case uses the user access records collected in the previous case to gather statistics on daily application access and pushes the statistical information via message push.
API Configuration
In the WeDa Data Source - APIs, create new WeCom APIs and configure the WeCom integration information as needed. For custom configurations, prepare the following:
- WeCom Enterprise ID
- Application ID
- Application Secret
Relevant configurations can all be obtained from the WeCom admin console.
Also copy the trusted IPs prompted during creation for subsequent configuration of trusted IPs for receiving messages on the application side.
WeCom Application Configuration
For the application receiving messages, trusted IPs must be configured. Add the trusted IPs from the previous step to the WeCom app - Developer Interface - Corporate Trusted IPs.
Workflow creation and configuration
Create Scheduled Trigger Workflow
Create a new workflow and select Timer Trigger. Configure the execution time as needed, for example, at 9:00 AM every morning.
Configure Data Query Node
Add a data query node after the timer trigger, set the type to Data Model, and select the specific model: WeCom application access logs created in the previous case.
Fill in the input parameters as follows to query today's access records and count statistics. The filter fields include the access time of the data model, filtered based on 00:00 of the current day.
({
"filter": {
"where": {
"_id": {
"$nempty": 1
},
"fwsj":{
"$gte":new Date().setHours(0, 0, 0, 0)
}
}
},
"select": {
"$master": true
},
"getCount": true
})
If the corresponding data model has development environment data, you can debug this node to view the output. If the development environment data is empty, you can also manually add data for testing.
Configure Message Push Node
Add another data query node after the data query node, set the type to APIs method invocation, select the APIs created in the first step, and choose the 'Send Application Message' method.
Configure the input parameters as follows to push text messages to the WeCom app. You can also modify them as needed to use more styles for message delivery; the total data from the previous node's output is currently attached.
({
"touser":"@all",
"msgtype": "text",
"agentid": 1000097,
"text": {
"content": "Today's application access count: " + query1.output.Response.Data.total
}
})
Workflow Publishing
After completing the configuration and saving, publish the workflow.
Message Push Verification
You can shorten the trigger interval, for example to 15 minutes, then after saving and publishing, wait for the workflow to run.
Through operation logs, you can monitor the runtime status of the workflow.
Simultaneously verify whether messages are being pushed from the enterprise application.