Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 5534a3d

Browse files
committed
Improve documentation.
1 parent f79fb33 commit 5534a3d

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

README.md

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ A WeChat (and Weixin) chatbot skeleton in Python with queue/delayed messages sup
66

77
This application was written following up on the [**Building Chatbots For WeChat — Part #1**](https://chatbotsmagazine.com/building-chatbots-for-wechat-part-1-dba8f160349) article and in anticipation of Part #2.
88

9+
## Configuration
10+
11+
In order to successfully run this application, the following environment variables must be set:
12+
13+
| Variable name | Description |
14+
|--------------------|----------------------------------------------------------------------------------|
15+
| `REDIS_URL` | A Redis connection string. |
16+
| `WECHAT_TOKEN` | See: [WeChat docs](http://admin.wechat.com/wiki/index.php?title=Getting_Started) |
17+
| `WECHAT_APPID` | Provided by the WeChat admin console. |
18+
| `WECHAT_APPSECRET` | Provided by the WeChat admin console. |
19+
20+
When running the application on the local machine for testing, a `.env` can be used instead of environment variables. See **Running locally** for details.
21+
922
## Running locally
1023

24+
Ensure that a working instance of Redis is available, either on the local machine or on a remote server.
25+
1126
Clone the repository and enter the directory:
1227

1328
Install the required dependencies running the following command from the project root:
@@ -16,25 +31,51 @@ Install the required dependencies running the following command from the project
1631
$ pip install -r requirements.txt
1732
```
1833

34+
Rename the `.env.template` file to `.env`, edit it and set the required parameters.
35+
Alternatively, set the environment variables listed in `.env.template`.
36+
The `.gitignore` file is already configured to ignore the `.env` file upon commits and pushes.
37+
1938
Run the bot:
2039

2140
```
2241
$ gunicorn -b 127.0.0.1:8000 src.bot
2342
```
2443

25-
Read the [**Building Chatbots For WeChat — Part #1**](https://chatbotsmagazine.com/building-chatbots-for-wechat-part-1-dba8f160349) article to learn how to setup the bot on WeChat and use tunneling tools such as [`ngrok`](https://ngrok.com) in case you don't have a public IP address.
44+
then configure WeChat to forward messages to it. The [**Building Chatbots For WeChat — Part #1**](https://chatbotsmagazine.com/building-chatbots-for-wechat-part-1-dba8f160349) article contains information on how to setup the bot on WeChat and use tunneling tools such as [`ngrok`](https://ngrok.com) in case a public IP address to connect the server to the local machine is not available.
2645

27-
Run the queue worker:
46+
Set up a cron job to run the queue worker automatically, or do it manually when needed during development and testing:
2847

2948
```
3049
$ python src/worker.py
3150
```
3251

33-
## Deploying on Heroku
52+
## Deploying to Heroku
53+
54+
*In case you are not familiar with the Heroku platform, please read the [Getting Started on Heroku with Python](https://devcenter.heroku.com/articles/getting-started-with-python) article first.*
3455

35-
In case you are not familiar with the Heroku platform, please read the [Getting Started on Heroku with Python](https://devcenter.heroku.com/articles/getting-started-with-python) article first.
56+
Ensure that the [`Heroku CLI`](https://devcenter.heroku.com/articles/heroku-cli) is installed and configured with the proper credentials, then create a new app on Heroku to host the bot code.
3657

37-
Add a new `git` remote pointing to the Heroku repository:
58+
Provision the required [`Heroku Redis`](https://elements.heroku.com/addons/heroku-redis) and [`Heroku Scheduler`](https://elements.heroku.com/addons/scheduler) add-on elements:
59+
60+
```
61+
$ heroku addons:create heroku-redis:hobby-dev -a {HEROKU_APP_NAME}
62+
$ heroku addons:create scheduler:standard -a {HEROKU_APP_NAME}
63+
```
64+
65+
This applications has been also tested with [`Redis Cloud`](https://elements.heroku.com/addons/rediscloud).
66+
67+
Set all the required environment variables:
68+
69+
```
70+
$ heroku config:set REDIS_URL="redis://{USERNAME}:{PASSWORD}@{HOST}:{PORT"" -a {HEROKU_APP_NAME}
71+
$ heroku config:set WECHAT_TOKEN={WECHAT_SHARED_TOKEN} -a {HEROKU_APP_NAME}
72+
$ heroku config:set WECHAT_APPID={WECHAT_APP_ID} -a {HEROKU_APP_NAME}
73+
$ heroku config:set WECHAT_APPSECRET={WECHAT_APP_SECRET} -a {HEROKU_APP_NAME}
74+
```
75+
76+
`Heroku Redis` automatically sets the `REDIS_URL` variable, it might be necessary to set it when using different Redis add-ons.
77+
78+
Enter the project root and add a new `git` remote pointing to the Heroku repository (see also: [Creating a Heroku remote](https://devcenter.heroku.com/articles/git#creating-a-heroku-remote)):
3879

3980
```
4081
$ heroku git:remote -r heroku -a {HEROKU_APP_NAME}
@@ -46,8 +87,12 @@ Push the code repository to Heroku:
4687
$ git push heroku master
4788
```
4889

90+
*For more information about deplyoing to Heroku with Git, see: [Deploying with Git](https://devcenter.heroku.com/articles/git)*
91+
4992
Get the app URL:
5093

5194
```
5295
$ heroku info -a {HEROKU_APP_NAME}
5396
```
97+
98+
then configure WeChat to forward messages to it as described in **Running locally**.

0 commit comments

Comments
 (0)