You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 12, 2026. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+50-5Lines changed: 50 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,23 @@ A WeChat (and Weixin) chatbot skeleton in Python with queue/delayed messages sup
6
6
7
7
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.
8
8
9
+
## Configuration
10
+
11
+
In order to successfully run this application, the following environment variables must be set:
|`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
+
9
22
## Running locally
10
23
24
+
Ensure that a working instance of Redis is available, either on the local machine or on a remote server.
25
+
11
26
Clone the repository and enter the directory:
12
27
13
28
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
16
31
$ pip install -r requirements.txt
17
32
```
18
33
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
+
19
38
Run the bot:
20
39
21
40
```
22
41
$ gunicorn -b 127.0.0.1:8000 src.bot
23
42
```
24
43
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.
26
45
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:
28
47
29
48
```
30
49
$ python src/worker.py
31
50
```
32
51
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.*
34
55
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.
36
57
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)):
38
79
39
80
```
40
81
$ heroku git:remote -r heroku -a {HEROKU_APP_NAME}
@@ -46,8 +87,12 @@ Push the code repository to Heroku:
46
87
$ git push heroku master
47
88
```
48
89
90
+
*For more information about deplyoing to Heroku with Git, see: [Deploying with Git](https://devcenter.heroku.com/articles/git)*
91
+
49
92
Get the app URL:
50
93
51
94
```
52
95
$ heroku info -a {HEROKU_APP_NAME}
53
96
```
97
+
98
+
then configure WeChat to forward messages to it as described in **Running locally**.
0 commit comments