Build your WeChat chatbot

David Yu
David Yu
Jul 7, 2018 · 3 min read
Image for post
Image for post
Photo by BENCE BOROS on Unsplash

Just in case your company decides to interact with the 1 billion monthly active users on WeChat.

While most people are quite familiar with Facebook chatbot.

The thought of doing something with WeChat can seem kind of daunting,

Because it’s a Chinese software and you can’t just Google your way out if you’re stuck.

Even if you Baidu, you will likely end up at Segmentfault(Chinese version of Stack overflow).

So this article’s purpose is to get your feet wet with WeChat Public Platform.


Basic knowledge of NodeJS

Basic knowledge of Javascript

WeChat App

Get a WeChat Developer Sandbox Account

Go to this link.

Scan the QR code with WeChat app.

You can use chrome’s translation plugin to translate the page.

Image for post
Image for post
WeChat Sandbox Console

appID, URL, Token are the only fields we need to worry about for this chatbot.

Setup up NodeJS server

git clone
cd wechat-chatbot

Or do npm install instead of yarn if you’re allergic to yarn.

Setup up Environment

Create a file called .env at the project’s root folder.


Run It

yarn start

If no errors pop up, feel good about yourself.

Use Ngrok to quickly test your server

npm install ngrok -g

Ngrok enables WeChat server to talk to your server without having to put your code on ☁️. (Heroku, AWS, …)

With your NodeJS server running, run ngrok http 3000

Image for post
Image for post

Once ngrok is online, copy the url from your terminal. Put it in URL field in the sandbox account dashboard.

Make sure you add /wechat at the end of the url.

Put the token from .env file to Token field

If something green pop up at the top, it means that WeChat has successfully bind your url to the sandbox account.

Image for post
Image for post

Scan QR code of your sandbox account

If you scroll down on your sandbox account dashboard, you will see a QR code.

Scan it and begin sending it random things. Start to mess around with the code.

How it works?

Image for post
Image for post
Your NodeJS server is the User business logic

Tencent server sends request to the URL to confirm if the token matches.

If it matches, it will pass along the messages that users send to the account to the NodeJS server in XML

Tencent server expects a XML format of the user’s OpenID and the content of the message.

OpenID is WeChat user’s ID related to the Public Platform.

WeChat notifies the user that the service is unavailable after three tries.

Thanks to library by Jackson Tian.

His library takes care of the logic that authenticate the token and handle XML.

Official Documents:

Code Links:

Thanks for reading

If you think this article will be useful for your friend, please share and smash the 👏button to help other developers to discover this.

Call to Action

To learn more about WeChat development, click here to download a free glossary.

China Software Development

Sharing software development required in China

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store