WeCom
This document describes how to create a WeCom self-built app, receive one-on-one and group text messages from enterprise members, call an Agent in Tencent Cloud EdgeOne Makers, and return the result to the member as an app message.
Prerequisites and Scope of Application
1. You have signed up for WeCom, and the test members have joined your enterprise.
2. The operating account has permissions to manage self-built apps.
3. Makers has been activated.
4. You have prepared a public HTTPS callback domain that meets the domain verification requirements of the WeCom admin console. If the admin console requires a filed domain associated with the entity, use a custom domain that meets the requirements.
5. The actual egress IP address used by the Makers service to call WeCom APIs has been obtained. You can configure it in Trusted Enterprise IP for the app.
6. This document covers only one-on-one text chats between internal enterprise members and self-built apps. It does not cover group chats, customer contacts, or external enterprise members.
Creating a Custom Enterprise App
1. Log in to the WeCom admin console.
2. Go to Apps > Apps, and click Create App in the Self-built section.
3. Upload an app icon, and enter the app name and description, such as Makers Assistant.
4. Add test members or a test department to Visible Range to complete the creation.
5. Copy the AgentId from the app details. Click View next to Secret, and copy the app Secret after completing identity verification.
6. Go to My Enterprise > Enterprise Info, and copy the Enterprise ID, which is the `CorpID`.

Preparing Message Receiving Credentials
1. Return to the current self-built app details, and go to Receive Messages > Set API Reception.
2. In the receiving message server configuration, set the Token and generate the EncodingAESKey. Copy and save them separately.
3. Keep the page open for now. After the Makers deployment is complete, enter the URL and save it. Do not repeatedly submit the URL for verification before a callback service is available.

After completing the preceding steps, you can obtain the following configuration.
Credential | Source | Purpose |
CorpID | Enterprise ID in enterprise information | Obtain application access credentials and verify the decrypted receiver. |
AgentId | Current self-built app details | Specify the application for sending replies. |
Secret | Current self-built app details | Obtain the application access_token. |
Token | Message receiving server configuration | Verify callback signatures. |
EncodingAESKey | Message receiving server configuration | Decrypt messages and verify URL strings. |
Note: The five values must belong to the same enterprise and app. `Token` is not the API `access_token`, and the app Secret cannot be replaced with the contacts sync Secret. The `access_token` is obtained by the template, so you do not need to manually create an environment variable. For protocol fields, see WeCom Callback Configuration.
Deploying the Makers Template
1. Open the Makers Agent for IM template.
2. In the project environment variable settings, fill in the following variables (copy .env.example to .env).
Environment Variable | Required | Description |
WECOM_CORP_ID | Yes | Enterprise ID |
WECOM_AGENT_ID | Yes | AgentId |
WECOM_APP_SECRET | Yes | Secret |
WECOM_TOKEN | Yes | Token |
WECOM_ENCODING_AES_KEY | Yes | EncodingAESKey |
3. Save the configuration and deploy it.
4. Copy the production HTTPS domain name, and append /wecom to the end.
5. Note that the service should be deployed in a mainland China AZ so that WeCom services can be accessed correctly.
Saving the Callback URL
1. Return to the Server Configuration page for receiving messages.
2. Enter the complete address in the URL field.
3. Verify that the Token and EncodingAESKey match the values configured in Makers, and click Save.
4. Confirm that the URL verification is successful and that the receiving message configuration is enabled.

Sending a Message and Verifying It
1. Log in to WeCom with a member account within the visible range.
2. In Workbench, find the app you created and enter its messaging session. Do not stay on the app's home page.
3. Send a message such as: "Please introduce Tencent Cloud EdgeOne Makers in one sentence."
4. Check the Makers logs and confirm that the app session of the same member receives a new Markdown reply.
5. Send the message `Please shorten the previous answer to no more than ten words.` again, and confirm that a reply is still received in the second round.
6. For more complex AI requirements, you can modify the template code as needed to implement them.

