Integrating with WeChat

Your A.I. brain works with WeChat out of box. You can turn your WeChat public account into a virtual robot in a few minutes by the steps below.

IMPORTANT: If your WeChat public account has a custom menu, be sure to read section 3 Working with Custom Menu firstly.

1. Copying API URL

Log in to http://acobot.net, choose the brain and

  1. Click Settings tab.
  2. Ensure the Application field is set as "WeChat".
  3. Copy the API URL.

If the "Application" field is not "WeChat", set it up as below.

  1. Click wrench icon.
  2. Choose "WeChat" for Application.
  3. Click Save button.

You can now copy the API URL.

2. Setting Up WeChat Public Account

Log in to https://mp.weixin.qq.com.

  1. Choose Basic Configuration under Development in left side bar. You might need to scroll down to the page bottom for it.
  2. Click Modify Settings button.
  3. Complete the settings as below.
    • URL: Paste the API URL you copied above.
    • Token: Enter "brainshop" (or any text you choose) for.
    • EncodingAESKey: Click 随机生成 button.
    • 消息加解密方式: Choose"明文模式".
  4. Click Submit button.
  5. Click Enable button if the server configuration is not enabled yet.


3. Enabling Speech Recognition

You need to enable speech recognition for your WeChat public account or else the robot cannot "hear" it users speak instead of typing a message.

Log in to https://mp.weixin.qq.com.

  1. Choose 接口权限 under 开发 in left side bar, at the bottom of page.
  2. Click 开启 for 接收语音识别结果.
  3. Click OK.

Well done! You can now notify the followers to chat with your smart virtual robot!

4. Working with Custom Menu

Read this section if you have added or plan to add a custom menu for the WeChat public account. Otherwise you may safely skip this section.

As you might have known, a custom menu can be created through either of the below two methods.

  • The management console provided by WeChat.
  • A 3rd party WeChat development platform or service.

For either situation, the menu will disappear when you connect the public account to your A.I. brain as described in section 2 above. Don't worry. With BrainShop, you can have the virtual robot and custom menu work together.

Known Limitation: currently the custom menu created with BrainShop supports only two types as below.

  • click
  • view

To create a custom menu for your WeChat public account,

  1. Log in to http://acobot.net
  2. Choose the brain, and click Settings tab.
  3. Click WeChat custom menu
  4. Provide the AppID and AppSecret of your WeChat Public Account.
  5. Define the menu and save.

To get the AppID and AppSecret of your WeChat Public Account,

  1. Log in to https://mp.weixin.qq.com.
  2. Choose Basic Configuration under Development in left side bar. You might need to scroll down to the page bottom for it.
  3. You may find AppID and AppSecret under 开发者ID, in the top of page.

You might need to click 显示密钥 to view AppSecret.

The menu is created/updated in real-time when you save the menu entry at BrainShop.

Tips

If you cannot see the updated menu for your WeChat public account, try unfollowing and refollowing the account. The WeChat server updates the menu in real-time but the client on your mobile phone doesn't.

5. Working with Cells for WeChat

Customizing welcome message

When a user follows your WeChat Public account, BrainShop will automatically send a welcome message to him or her. To customize the message, create a new cell as below.

  • Cell
    • Input: WeChatEvent subscribe
    • Output: [Your welcome message]

Defining messages for custom menu

When creating a menu item, you can define its type as "Sending message." When a user clicks it, your A.I. brain may send a pre-defined message to him or her.

WeChatEvent click [key]

The [key] above is what you provide for Key/URL field when you define a menu item.

Note: Punctuation points are not allowed for [key].

Troubleshooting

I set up my WeChat public account as above but the robot doesn't respond.

You need to wait for a while, up to an hour, before WeChat settings go into effect.

I've modified the custom menu but the old one remains.

WeChat client stores menu in your smartphone cache. The cache might persist up to one day.

To clear the cache: