WeCom App Access Event Collection
WeChat Work supports active event and message push, enabling the delivery of message interactions between users and the app, as well as events triggered during user operations, to the customer-specified server. Currently, the workflow capabilities in Tencent WeDa have added a WeCom message trigger, which supports receiving WeCom pushes and triggering workflows to process the received content.
The following sections will describe how to use workflows to receive WeCom message pushes, filter out user entry events, and log these events to the database via a data model.
Data Model Establishment
The event structure for user entry is as follows:
The key information includes:
- WeCom Company ID
- Application ID
- User accessing the application
- Entry time
Based on the above information, we create a custom data model in WeDa and add the specified fields. The field identifiers need to be recorded for use in subsequent workflow configurations.
Among them:
- Access time: is of date-time type
- Access user: is of text type
- Application ID: is of numeric type
- CorpID: is of text type
After configuring the data model, publish it to facilitate subsequent workflow usage.
Workflow creation and configuration
Create new workflow and configure trigger
Create a new workflow and select "When receiving a WeCom message event push" as the trigger method.
Configure Trigger
- Push URL: Copy and record this for filling into the push address of the WeCom app
- CorpID: Obtain from the WeCom backend
- Token: Randomly generate and copy it for configuration in the WeCom app's push settings.
- EncodingAESKey: Randomly generate and copy it for configuration in the WeCom app's push settings.
Final configuration is as shown in the figure below.
Configure Branch Filtering
Connect a branch node after the trigger node to filter events, configuring two branches:
- Enter Application Event: Condition details are as follows, used to filter out enter application events.
wecomTrigger.output.DecryptJson.Event == 'enter_agent'
- Other Events: Condition is true
Configure Data Model Write Operations
Add a data query node after the branch node, configuring the condition from the branch to the data query node as "enter application event".
The data query node is configured as the "WeDa data model" type, with the data model selected as the "WeCom App Access Log" created in the previous step, and the method set to "Create Single Record".
Modify the input parameters as follows: each key must correspond to the field identifier defined during the data model creation. Adjust and fill in according to the actual creation context for: access user, app id, access time, and WeCom company id.
({
"data": {
"fwyh": wecomTrigger.output.DecryptJson.FromUserName,
"yyID": wecomTrigger.output.DecryptJson.AgentID,
"fwsj": wecomTrigger.output.DecryptJson.CreateTime*1000,
"qwgsID": wecomTrigger.output.DecryptJson.ToUserName
}
})
Workflow Publishing
After the workflow configuration is completed and saved, proceed to publish it and confirm that it has been successfully published.
Whether it is running properly subsequently can be viewed through the log interface within the workflow to check the operation status of the published version.
WeCom Application Configuration
To normally send events or messages, the WeCom application needs to configure push settings by entering WeCom application management and setting up the message reception configuration, enabling the connection of application messages and events to the workflow.
Through the application management in the WeCom admin console, access the application that requires push configuration.
Configure the message reception API
Fill in the URL for the workflow trigger and configure the Token and EncodingAESKey from the trigger settings here Message and event types should be selected as required. Here, we need to ensure that "Report Entry Application Event" is checked.
After the configuration is completed, you can save and exit.
Event Collection Verification
After configuration is completed, access the application via the workbench in WeCom.
View the operation logs of the workflow to check for similar logs indicating the execution of branch nodes and subsequent query nodes.
Access the data management page of the data model, switch to production data, and check if any data has been recorded.