Integrate an AI assistant into WeCom
On Alibaba Cloud, you can integrate an AI assistant powered by a large model into WeCom for your organization without writing any code. This assistant can respond to user inquiries 24/7 and answer domain-specific questions, improving the user experience and giving your business a competitive edge.
Solution overview
Integrating an AI assistant into WeCom involves a few steps:
|
|
1. Create a large model Q&A application
First, create a Model Studio application to obtain a large model inference API service.
The free trial for new users of Alibaba Cloud Model Studio covers all resources required for this tutorial. After the free trial quota is used up, you are billed based on token usage, which significantly reduces initial investment costs compared to deploying a large model yourself.
1.1 Create an application
-
Open the legacy agent creation form, enter an Application Name, and click Create Now.
-
On the Application Configuration page, select Qwen-Plus as the model and leave the other parameters at their default settings.
You can enter a prompt to define a role for the model, guiding it on how to handle customer inquiries.
Your name is "Assistant". You help users with questions about product selection, usage, and other related topics.
In the Debug area on the right, enter a question to test the application. The agent will respond according to the prompt. For example, if you ask its name, it will reply, "My name is Assistant." 3. On the right side of the page, you can ask questions to test the model's performance. However, it cannot yet accurately answer questions about your company's product information. Click Publish in the upper-right corner. We will address this limitation later.
1.2 Get the application ID and API key
To call the large model application's API later, you need to obtain the Model Studio API key and application ID.
-
On the Application Management page, you can view all Model Studio application IDs. Save the application ID locally for later configuration.
On the application overview page, click the copy icon next to Application ID to copy it.
-
Go to the API Key page and click Create API Key to create a new API key in the pop-up window. Save the API key locally for later configuration.
2. Create a WeCom application
Next, create an application in your organization to act as the AI assistant.
2.1 Create an application
- Visit the WeCom Developer Center, scan the QR code to log in, and click Create Now. Follow the prompts to select Create as an enterprise and Internal enterprise application.
- In the top navigation bar, select My Applications. On the Application page, click Create Application in the lower part of the page.
- On the Create Application page, fill in the Application Name and Application Description, upload an application logo, select the visible scope, and then click Create Application.
2.2 Get the Enterprise ID, AgentId, and Secret
- On the application details page, copy the AgentId and Secret. You will use these to create the connection flow in the next step.
- In the top navigation bar, select My Enterprise. On the Enterprise Information page, copy the Enterprise ID. You will use this to create the connection flow in the next step.
3. Create a WeCom connection flow
AppFlow allows you to connect your Model Studio RAG application with WeCom without writing any code. You can create a WeCom connection flow from a prebuilt AppFlow template.
-
Create a connection flow from an AppFlow template. Click Use Now to start the creation process. In AppFlow, find the WeCom self-built app large model auto-reply template and click Use Now.
-
On the WeCom Account Authorization configuration page, click the
button, then click Add New Credential.If you do not have a credential, click Add New Credential. If you do, select it from the Select Credential dropdown list. You can click the refresh icon to update the list.
-
In the Create Credential dialog box, set a custom credential name and enter the Enterprise ID, AgentId, and Secret you obtained from WeCom. Save the Token and EncodingAESKey generated by AppFlow locally (required for 4.1 Configure API message receiving) and save the IP address whitelist for 4.2 Configure enterprise trusted IP addresses. Click Next Step.
-
Click Save to complete the configuration.
-
On the Model Studio Account Authorization configuration page, click the
button, then click Add New Credential. In the Create Credential dialog box, set a custom credential name and enter the API key you obtained earlier. -
On the Execute Action configuration page, enter the application ID. You can get the application ID from the Application Management page in the Alibaba Cloud Model Studio console. When you are finished, click Next Step.
-
On the Basic Information configuration page, enter a Connection Flow Name and Connection Flow Description (we recommend keeping the default values). When you are finished, click Next Step.
-
A success message is displayed. Copy and save the webhook URL (required for 4.1 Configure API message receiving) and click Publish.
4. Configure the WeCom application
Now that you have the webhook URL, you can configure your WeCom application to receive messages and answer user questions.
4.1 Configure API message receiving
-
Go to your WeCom application list. Find the application you just created and click its name to go to the details page.
-
On the application details page, find the Receive messages card and click Set up API to Receive Messages.
-
On the API Message Receiving page, complete the configuration as described below, then click Save.
In the Select message event types to receive area, select the following events: Regular messages from users, Custom menu action, Approval status notification event, External contact change callback, WeChat customer service messages and events, Payment and refund notifications, Upstream/downstream change callback, Live stream status change callback, Meeting room booking status change callback, and Member application for advanced features status notification. Do not select Report geographic location or Report application entry event.
-
For URL, enter the webhook URL you copied in the previous step.
If you did not save the webhook URL, go to the AppFlow connection flow page and click webhookUrl in the Actions column to view it.
-
For Token and EncodingAESKey, enter the values you copied in the previous step.
If you did not save them, go to the AppFlow Connection Credentials page. In the Public Connector > WeCom section, find the credential you just configured and click Modify in the Actions column to retrieve the values.
If domain ownership verification fails, see What do I do if domain ownership verification fails? for instructions.
-
4.2 Configure enterprise trusted IP addresses
- On the application details page, find the Enterprise Trusted IP card in the developer interface section at the bottom of the page and click Configure.
- In the Enterprise Trusted IP dialog box, paste the copied IP addresses and click OK.
4.3 Test the application
You can now search for your application in WeCom and send it a message to see it in action.
- In the top search bar of WeCom, search for your application name and click it to open the chat. In the search bar, enter AI assistant. Under the Application category in the search results, find and click AI assistant.
- Start a conversation with the application. Once in the chat, send a question to test it. The AI assistant will automatically generate a reply.
5. Add private knowledge
5.1 Configure a knowledge base
Next, configure the large model to reference a document to produce more accurate answers and recommendations.
Imagine you work for a company that sells smartphones. Your WeCom users have many questions about smartphones, such as dual-SIM support, screen size, battery capacity, and memory. For a detailed configuration list of different models, see: Alibaba Cloud Model Studio Series Phone Product Introduction.docx.
-
Open Collections and click Details for the target file dataset. Select a category, click Import Data, and upload the following sample phone product document:
Depending on the size of your uploaded document, Model Studio may need some time to process it, typically 1 to 6 minutes. Please be patient.
On the import data page, select Local Upload for the Import Method. Supported formats are .pdf, .doc, .docx, .txt, .md, .pptx, .ppt, .png, .jpg, .jpeg, .bmp, .gif, .xls, and .xlsx. Upload limits are as follows: 100 MB or 1,000 pages per document, 20 MB per image, and a maximum of 200 files. Files will be stored in the Singapore region. For Document Recognition, select Smart Document Parsing. You can add tags as needed in the Add Tag area.
-
If this is your first knowledge base, open Knowledge and click Activate and Create Now. If the service is already active, create a Standard Edition knowledge base. Enter a Name, leave the rest of the settings at their defaults, and click Next Step. Select the document you just uploaded and leave the other parameters at their defaults. This allows the large model to retrieve and reference the documents in this knowledge base when answering questions.
When selecting a vector storage type, if you want to centrally store and flexibly manage vector data for multiple applications, you can select ADB-PG.
Under data source, select Select Files. Under the Default Category on the left, check the target document and click Next.
-
Reference the knowledge: After creating the knowledge base, return to Application Management and go to the configuration screen of the application you created earlier. Turn on the Knowledge Base switch, click + Knowledge Base to select the target knowledge base. After testing to ensure it meets expectations, click Publish. Information is automatically added to the prompt, allowing the large model to reference the retrieved information in its answers.
On the application configuration page, you can select one of three processing methods in the File Processing area: Full-text Reference, sliced retrieval, or Custom Processing. In the knowledge area, you can set the Invocation Method (such as Always Invoke). For added knowledge documents, you can configure the Similarity Threshold and Weight.
5.2 Verify the results
With the reference knowledge, your AI application can now accurately answer questions about Alibaba Cloud Model Studio phones.
Summary
By following this tutorial, you have learned how to build a large model RAG application and integrate it into WeCom to handle customer inquiries, at no extra cost within the free trial quota.
Application evaluation
Before launching your AI application, we recommend having business personnel conduct an Application Evaluation to ensure the large model's responses meet expectations. If the responses are not satisfactory, you can improve them by optimizing prompts, supplementing private knowledge, or adjusting the document chunking strategy.
Continuous improvement
Large model course
Improving the user experience is a continuous process. You can consider studying for and passing the Alibaba Cloud Certified Associate (ACA) - Large Models certification. The free course accompanying this certification will help you further understand the capabilities and use cases of large models, as well as how to optimize their performance.
FAQ
Handle domain ownership verification failure
When you configure API message receiving in the WeCom console, you may see an error: "Domain ownership verification failed. The domain’s filing entity must be the same as the current enterprise entity or have an affiliated relationship." This is typically caused by WeCom's restrictions. To resolve this, you need to configure an enterprise-owned domain.
-
If your domain is filed with Alibaba Cloud, you can follow these steps to create a subdomain as your enterprise-owned domain.
-
Navigate to the AppFlow Domain Management page and click Add Domain Name to open the Add Domain Name page. Enter an available subdomain, such as
airobot.example.com.In the Configure HTTPS step, select Disable. The system will then generate a CNAME record value in the Add DNS record step (in the format
xxx.appflow.aliyunnest.com). You need to configure this record in your domain's DNS settings. -
Follow the instructions for creating a CNAME record to point the subdomain to the Record Value from the previous step.
-
After the DNS configuration is complete, return to the Add Domain Name page and click Submit.
-
Replace the hostname in the URL for API message receiving (the webhook URL you already entered) with this new subdomain.
-
-
If your domain is not filed with Alibaba Cloud, you can configure the URL for API message receiving to be your enterprise-owned domain. Then, on the Nginx server that serves your domain, configure a forwarding rule to route requests to the connection flow's webhook URL.
-
On the Connection Credentials page in AppFlow, edit the WeCom connection credential.
-
Click Next Step and select internal proxy.
-
When you select internal proxy for the first time, a page for creating and authorizing an AppFlow service-linked role will appear. Confirm and grant the authorization.
The role name in the pop-up window is
AliyunServiceRoleForAppFlow, and the permission policy isAliyunServiceRolePolicyForAppFlow. After confirming, click Authorize. -
Configure the trusted domain.
Compute Nest Nginx proxy
If you do not have a trusted domain filed with Alibaba Cloud and do not have an Nginx proxy, you can click Deploy Nginx Proxy Instance to automatically deploy and configure an Nginx proxy. Confirm the order directly or change the configuration as desired, then wait for the deployment to complete. The deployment process typically takes 1-3 minutes. Refresh the list and wait for the deployment to finish.
After the deployment is complete, select the Compute Nest instance from the dropdown list. Replace the hostname in the URL for API message receiving (the webhook URL you already entered) with the Compute Nest instance host. Copy the IP address whitelist and add it to the Enterprise Trusted IP list. Click Save to complete the configuration.
Own Nginx proxy
You can use your own Nginx for proxying, which also requires an ECS or managed instance for message forwarding.
-
Select an ECS instance or managed instance and add its IP to the Enterprise Trusted IP list.
-
If you do not have an instance, you can click Add Instance to go to the ECS purchase page and buy a new one, or create a managed instance.
To create a managed instance, you need a non-Alibaba Cloud machine with public network access. Then, install Cloud Assistant on it according to the Alibaba Cloud managed instances documentation.
-
Click Save to complete the configuration.
-
Replace the hostname in the URL for API message receiving (the webhook URL you already entered) with the IP address of your Nginx server.
-
-
Handle the third-party IP error
Reason for the error: For security reasons, WeCom requires verification of trusted domains and IPs when calling address book and identity verification APIs. A single trusted IP can only be used for one enterprise in WeCom. If it is used for multiple enterprises, it will be identified as a service provider, which makes interfaces like the address book and identity verification unavailable.
If you have an Alibaba Cloud ECS server, you can use it for request forwarding to solve the trusted IP issue:
-
Modify the WeCom connection credential configured in AppFlow. In the AppFlow console, click Connection Credentials in the left navigation pane. In the connector list, select WeCom, find the target credential, and click Edit in the Actions column.
-
Modification: On the Internal Proxy Configuration page, select Use trusted domain > ECS instance or Use your own Nginx proxy > ECS instance, select the corresponding region and instance, and click Save.
The IP address whitelist area at the bottom of the page displays the whitelisted IP addresses. Click Copy IP to copy them.
-
Add the proxy machine's IP to the WeCom trusted IP list. Go to the WeCom application list, enter the application details page, find the Enterprise Trusted IP card in the developer interface section at the bottom of the page, and click Configure.
If you have your own non-Alibaba Cloud machine, you can register it as a managed instance with Alibaba Cloud and use it for request forwarding to solve the trusted IP issue:
-
On your non-Alibaba Cloud server that has public network access, install Cloud Assistant by following the documentation.
-
Modify the WeCom connection credential configured in AppFlow. In the AppFlow console, click Connection Credentials in the left navigation pane. In the connector list, select WeCom, find the target credential, and click Edit in the Actions column.
-
Modification: On the Intranet Proxy Configuration page, select Use trusted domain > ECS instance or Use your own Nginx proxy > ECS instance, select the corresponding managed region and managed instance, and click Save.
After selecting managed instance, you need to configure the IP address whitelist. If the page prompts "Unable to obtain the public IP of your proxy forwarding machine," you need to find the egress IP yourself and add it to the whitelist.
Add the proxy machine's IP to the WeCom trusted IP list. Go to the WeCom application list, enter the application details page, find the Enterprise Trusted IP card in the developer interface section at the bottom of the page, and click Configure.
Log AI assistant conversations
To log and analyze AI assistant conversations, add a log node in AppFlow to store conversation content in Simple Log Service (SLS).
-
Go to the AppFlow console. In the table’s Actions column, click Details. In the details page, click Create New Version in the upper-right corner.

-
After you edit the Alibaba Cloud Model Studio step on the Edit page, click + to add a new step. For Industry Type, select Alibaba Cloud. For Public Connector, select SLS Log Service.


-
Select the action Write Log. Click Save and Continue.

-
Click Add New Credential. In the credential creation dialog, fill in the form to create and authorize a role. After creation, select the credential and click Save and Continue.


-
Select a region, Project, and Logstore. Enter the required log information. In the left input box, enter the log key. In the right input box, use variables to pull context information.
- If you have already created a Project and Logstore in Simple Log Service (SLS) for storing AI assistant logs, use them directly. If not, create them by following Create a Project and Logstore. After creation, no log ingestion setup is required. Go to the Logstore details page and click Enable Index in the upper-right corner. Use the default full-text index. You can query and analyze logs online in SLS only after enabling indexing.


- Select a region, Project, and Logstore. Enter the required log information. In the left input box, enter the log key. In the right input box, use variables to pull context information.

- If you have already created a Project and Logstore in Simple Log Service (SLS) for storing AI assistant logs, use them directly. If not, create them by following Create a Project and Logstore. After creation, no log ingestion setup is required. Go to the Logstore details page and click Enable Index in the upper-right corner. Use the default full-text index. You can query and analyze logs online in SLS only after enabling indexing.
-
Save and publish the connector flow version.

-
Test the conversation and check the logs.

View a connection flow's webhook URL
- Go to the Connection Flow page in the AppFlow console.
- In the Actions column, click webhookUrl to view the URL.












