-
Notifications
You must be signed in to change notification settings - Fork 918
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from zhayujie/feature-wechat-mp
feat: add wechat company service account
- Loading branch information
Showing
12 changed files
with
249 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import werobot | ||
from config import channel_conf | ||
from common import const | ||
from common.log import logger | ||
from channel.channel import Channel | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
robot = werobot.WeRoBot(token=channel_conf(const.WECHAT_MP).get('token')) | ||
thread_pool = ThreadPoolExecutor(max_workers=8) | ||
|
||
@robot.text | ||
def hello_world(msg): | ||
logger.info('[WX_Public] receive public msg: {}, userId: {}'.format(msg.content, msg.source)) | ||
return WechatServiceAccount().handle(msg) | ||
|
||
|
||
class WechatServiceAccount(Channel): | ||
def startup(self): | ||
logger.info('[WX_Public] Wechat Public account service start!') | ||
robot.config['PORT'] = channel_conf(const.WECHAT_MP).get('port') | ||
robot.config["APP_ID"] = "YOUR APP ID" | ||
robot.config["APP_SECRET"] = "YOUR APP SECRET" | ||
robot.run() | ||
|
||
def handle(self, msg, count=0): | ||
context = {} | ||
context['from_user_id'] = msg.source | ||
thread_pool.submit(self._do_send, msg.content, context) | ||
return "正在思考中..." | ||
|
||
|
||
def _do_send(self, query, context): | ||
reply_text = super().build_reply_content(query, context) | ||
logger.info('[WX_Public] reply content: {}'.format(reply_text)) | ||
client = robot.client | ||
client.send_text_message(context['from_user_id'], reply_text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# channel | ||
WECHAT = "wechat" | ||
WECHAT_MP = "wechat_mp" | ||
WECHAT_MP_SERVICE = "wechat_mp_service" | ||
|
||
# model | ||
OPEN_AI = "openai" |
Oops, something went wrong.