Turn Your WeChat Official Account into an AI Customer Service Agent in 10 Minutes

Updated at:

On Alibaba Cloud, convert your WeChat Official Account (subscription account) into a 24/7 AI customer service agent in just 10 minutes. Respond to customer inquiries around the clock, improve user experience, and strengthen your business competitiveness.

Solution Overview

Turn your WeChat Official Account (subscription account) into an AI customer service agent in four steps:

  1. Create a Large Language Model (LLM) Q&A application: First, create an LLM application in Alibaba Cloud Model Studio. Then get the credentials you need to call the application's API.

  2. Build a connection flow between your WeChat Official Account and Model Studio: Use Alibaba Cloud AppFlow to connect your WeChat Official Account to your Model Studio RAG application. No code is required. Users can then chat with your RAG application directly from your WeChat Official Account.

  3. Test the AI customer service agent: Chat with your WeChat Official Account to verify that the configuration works.

  4. Add private knowledge: Add your own knowledge to help the AI assistant answer questions it could not answer before. This helps you respond to customer inquiries more effectively.

image

7b29f72d-3b9d-4fb1-867f-fc19aa575644

1. Create an LLM Q&A Application

First, create a Model Studio application to access the LLM inference API service.

1.1 Create the Application

  1. Open the legacy agent creation form, enter an Application Name, keep the other defaults, and click Create Now.

    image

  2. In the Application Settings page, select Qwen-Plus as the model. This model balances capability, inference quality, cost, and speed between Qwen-Max and Qwen-Flash and meets the requirements of this scenario. Keep all other parameters at their defaults.

    You can also add a prompt. For example, define a persona to guide the LLM to better handle customer inquiries.

You are Xiao Zhu, our company's AI assistant. You help customers with product selection and usage questions.
Always give short answers. Do not explain too much.
image
  1. Use the test box on the right side of the page to ask questions and review the model’s responses. You will notice that it cannot yet answer questions about your company’s products. Click Publish in the upper-right corner. You will resolve this in later steps. image.png

1.2 Get the application ID and API key for API calls

To call the LLM application's API later, you need to obtain the Model Studio API key and the application ID.

  1. On the Application Management page, you can view all Model Studio application IDs. Save the application ID locally for later configuration.

    image
  2. Go to the Key Management page and click Create API Key. In the pop-up window, create a new API key. Save the API key locally for later configuration.

2. Create a Connection Flow for Your WeChat Official Account

AppFlow lets you connect your Model Studio RAG application to your WeChat Official Account without writing any code. Configure everything in the console using a prebuilt AppFlow template.

If your WeChat Official Account is verified, use the WeChat Customer Service Messages API to reply to customer messages. If your account is not verified, use the Passive Reply Messages API. With passive replies, you have only 5 seconds to respond. If you miss the deadline, no reply is sent.

To check whether your account is verified, go to the WeChat Official Account backend. In the navigation pane on the left, choose Settings & DevelopmentAccount Settings. Check the verification status on the Account Settings page. Choose one of the two setup options below based on your verification status. bcc603653c5d4b75efee061b67274081

Verified WeChat Official Accounts

  1. Create a connection flow using the AppFlow template. Click Use Now to start the setup process. 2024-11-07_16-57-05

  2. Go to the WeChat Official Account backend. In the navigation pane on the left, choose Settings & DevelopmentDevelopment Interface Management. On the Basic Configuration tab, retrieve your AppID. 2024-11-07_16-27-30

  3. In the Account Authorization wizard, click Add New Credential and select Add New Credential. Enter your AppID on the authorization page. Click Authorize. Then scan the QR code with WeChat on the new page to complete authorization. After authorization, AppFlow configures your WeChat Official Account automatically. You do not need to take any further action. After authorization completes, return to the Account Authorization wizard and select the WeChat Official Account you just authorized.

    NoteWhen scanning the QR code on the new page, use the main administrator account for your WeChat Official Account. Otherwise, authorization fails.

    image 2024-11-07_16-24-15
  4. In the Account Authorization wizard, click Authorize Now. In the Create Credential dialog box, enter the API key you retrieved earlier. Set a custom credential name.

    image
  5. In the Action Execution wizard, enter the Model Studio Application ID you retrieved earlier (1.2 Get the Application ID and API Key). Click Next Step. 2024-08-15_15-13-51

  6. In the Basic Information wizard, enter a Flow Name and Flow Description (keep the defaults). Click Next Step.

  7. The console displays a success message indicating that the flow is configured. Click Publish. 2024-11-07_17-04-51

Unverified WeChat Official Accounts

  1. Create a connection flow using the AppFlow template. Click Use Now to start the setup process. 2024-11-07_17-07-32

  2. Go to the WeChat Official Account backend. In the navigation pane on the left, choose Settings & DevelopmentDevelopment Interface Management. On the Basic Configuration tab, retrieve your AppID. 2024-11-07_16-27-30

  3. In the Account Authorization wizard, click Select New Credential and choose Add New Credential. Enter your AppID on the authorization page. Click Authorize. Then scan the QR code with WeChat on the new page to complete authorization. After authorization, AppFlow configures your WeChat Official Account automatically. You do not need to take any further action. After authorization completes, return to the Account Authorization wizard and select the WeChat Official Account you just authorized.

    NoteWhen scanning the QR code on the new page, use the main administrator account for your WeChat Official Account. Otherwise, authorization fails.

    image 2024-11-07_16-24-15 2024-11-07_16-50-48 2024-11-07_16-24-15 2024-11-07_16-50-48
  4. In the Account Authorization wizard, click Authorize Now. In the Create Credential dialog box, enter the API key you retrieved earlier. Set a custom credential name. 2024-08-13_09-33-07

  5. In the Action Execution wizard, enter the Model Studio Application ID you retrieved earlier (1.2 Get the Application ID and API Key). Click Next Step. 2024-08-13_09-36-39

  6. In the Basic Information wizard, enter a Flow Name and Flow Description (keep the defaults). Click Next Step.

  7. The console displays a success message indicating that the flow is configured. Click Publish. 2024-11-07_16-53-08

3. Test the AI Customer Service Agent on Your WeChat Official Account

Send a message to your WeChat Official Account. You will receive a reply from the AI customer service agent.

image

4. Add Private Knowledge to the AI Customer Service Agent

You now have an AI customer service agent that can interact with customers. To make it answer product-related questions as accurately and professionally as your staff, configure a knowledge base for the LLM application.

Assume you sell smartphones. Your website contains extensive smartphone information, such as support for Dual SIM Dual Standby, screen size, battery capacity, and memory. See the full specifications list for different models in: Alibaba Cloud Model Studio Smartphone Product Introduction.docx.

4.1 Configure the knowledge base

Next, you can configure the LLM to reference this document when answering customer questions to produce more accurate answers and suggestions.

  1. Data connection: Go to the Data Connection tab in the Alibaba Cloud Model Studio console and click the Details button for the Default File Connector.

    image
  2. Upload the file: In the upper-right corner of the connector details, click Import Data. Follow the on-screen instructions to upload the fictional Alibaba Cloud Model Studio series smartphone product introduction document.

    Depending on the size of the document you upload, Alibaba Cloud Model Studio needs some time to parse it. This process usually takes 1 to 6 minutes. Please wait patiently.

    image

  3. 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. Fill in the Name and Knowledge Base Description, keep the default values for other settings, and click Next Step. Select the document that you just uploaded and keep the default settings for other parameters and the Index Settings. The LLM can then retrieve and reference documents from the knowledge base when it answers questions.

    When selecting a vector storage class, if you want to centralize storage and flexibly manage vector data for multiple applications, you can select ADB-PG.

    image
  4. Reference knowledge: After you create the knowledge base, go to the Application Management page and select the application you created earlier. In the Document section, add the target knowledge base. For the call method, select Always Call. After you test and verify that the results meet your expectations, click Publish.

    image

4.2 Verify the Results

With this knowledge, the AI customer service agent can now answer questions about your company’s products accurately.

image

Summary

You have now built an LLM RAG application and added it as an AI customer service agent to your WeChat Official Account. You can handle customer inquiries at zero cost (within the free trial quota) in just 10 minutes.

Going Live

Before you deploy the AI customer service agent to production, review the following information:

Evaluation

Before going live, run a manual evaluation with your business team. For more information, see manual evaluation.

Continuous improvement

LLM course

Improving and optimizing the system is an ongoing process. You can study for and pass the Alibaba Cloud LLM ACA Certification. The free courses that accompany this certification can help you better understand the capabilities and application scenarios of LLMs, and how to optimize their performance.

FAQ

My custom menu stopped working after I enabled server configuration. What should I do?

After you enable server configuration in the WeChat Official Account backend, your existing custom menu stops working due to a conflict. If your account is not verified, you cannot use both server configuration and custom menus simultaneously. If you have a verified service account or subscription account, follow these steps to configure your custom menu through the API:

  1. Retrieve an access_token. For more information, see the Get access_token documentation. Call the WeChat API below to retrieve your access_token. Go to the WeChat Official Account backend. In the navigation pane on the left, choose Settings & DevelopmentBasic Configuration. Retrieve your AppID and AppSecret. Replace YourAppID and YourAppSecret in the command below.
curl "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=YourAppID&secret=YourAppSecret"
  1. Call the menu API. For more information, see the Create Menu documentation. Run the command below. Replace ACCESS_TOKEN in the command. Set your menu data to create a custom menu.
curl "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data '{
     "button":[
     {
          "type":"click",
          "name":"Home",
          "key":"home"
      },
      {
           "name":"Menu",
           "sub_button":[
           {
               "type":"view",
               "name":"Documentation",
               "url":"https://help.aliyun.com/en/model-studio/what-is-model-studio"
            }]
       }]
 }'

After configuration, my WeChat Official Account does not reply to messages. How do I troubleshoot?

If you click Run Once in the AppFlow console and get no response, this is expected. The Run Once feature does not accept input, so it returns an error. If you send a message to your WeChat Official Account and get no reply, follow these steps:

  1. Go to the AppFlow console and click Operational Log in the Actions column of the table to open the Execution Log page and view the logs.2024-08-29_16-54-56

  2. On the execution logs page, click Details to view the error log. Identify the failed step and analyze the error message.

    2024-08-29_16-56-46 image

Common causes include the following:

  • The Model Studio application ID is incorrect. Check for extra spaces before or after the ID. You can find the correct ID in the My Applications page in the Model Studio console.
  • Your WeChat Official Account is not verified, but you used the workflow for verified accounts. Reconfigure the workflow and select the one for unverified accounts.
  • Your WeChat Official Account credentials are incorrect. Go to the AppFlow console connector credentials page. Compare your WeChat credentials with those in the WeChat Official Account backend.
  • Your WeChat Official Account does not have a whitelist IP. Go to the AppFlow console connector credentials page. Retrieve the whitelist IP from your WeChat configuration.
  • Your WeChat Official Account is not verified, and the Model Studio application took longer than 5 seconds to reply. This triggers WeChat’s timeout limit. Complete WeChat verification and use the verified workflow. If you cannot verify, add the prompt “Always give short answers. Do not explain too much.” to your Model Studio application. Or switch to Qwen-Turbo to improve response speed. Note that this may reduce answer quality.

Log AI assistant conversations

If you want to log and analyze AI assistant conversations, you can add a log node in AppFlow to write conversations to Alibaba Cloud Log Service (SLS).

  1. Go to the AppFlow console. In the Actions column of the table, click Details. On the details page, click Create New Version in the upper-right corner.

  2. On the edit page, after the Model Studio step, click + to add a new step. For Industry Type, select Alibaba Cloud. For Public Connector, select Log Service (SLS).

  3. Select the Write Log action and click Save and Next.

  4. Click Add New Credential. In the dialog box that appears, fill in the form to create and authorize a role. After the credential is created, select it and click Save and Next.

  5. Select the region, Project, and Logstore. Enter the required log information. The left input box is for the log key, which you can enter directly. The right input box is for the log value, where you can insert variables to get contextual information.

    1. If you have already created a Project and Logstore in Alibaba Cloud Log Service (SLS) to store AI assistant logs, you can use them directly. If not, create them by following the instructions in Create Project and Logstore. After creation, you do not need to ingest logs. Go to the Logstore details page and enable indexing in the upper-right corner. Use the default full-text index. You can query and analyze logs online in Log Service only after indexing is enabled.
  6. Save and publish the connection flow version.

  7. Test the conversation and view the logs.

How do I fix the WeChat error “The URL you entered poses a serious security risk and cannot be set”?

If you see this error when configuring server settings in the WeChat Official Account backend, create a new WeChat Official Account connection flow using the latest service provider authorization method. For more information, see create a WeChat Official Account connection flow. If you prefer not to use the service provider method, bind your custom domain name instead.

If your domain name has an ICP filing with Alibaba Cloud, submit a ticket. Contact our customer service representatives. Provide your connection flow ID and custom domain name. They will help you configure and use your company’s custom domain name. Then set up a CNAME record for your custom domain name to point to the connection flow’s WebhookUrl.

If your domain name does not have an ICP filing with Alibaba Cloud, set the URL in the server configuration to your custom domain name. Then configure a forwarding rule in the Nginx server where your custom domain name is hosted. Forward requests to the connection flow’s WebhookUrl.