From 148b46f322c9e9cca0e427fa165bdd37c3dfa729 Mon Sep 17 00:00:00 2001 From: KagurazakaNyaa Date: Thu, 21 Jan 2021 17:10:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 2 ++ app.py | 32 +++++++++++--------------------- example.env | 2 ++ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index ec426bd..85be8ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,9 @@ ADD app.py requirements.txt /app/ ENV SLACK_SIGNING_SECRET=*** ENV SLACK_BOT_TOKEN=xoxb-*** ENV DINGTALK_WEBHOOK='https://oapi.dingtalk.com/robot/send?access_token=这里填写自己钉钉群自定义机器人的token' +ENV PORT=3000 WORKDIR /app RUN pip install -r requirements.txt RUN chmod +x app.py +EXPOSE 3000 ENTRYPOINT [ "python", "app.py" ] \ No newline at end of file diff --git a/app.py b/app.py index 7ee1852..b089032 100755 --- a/app.py +++ b/app.py @@ -1,54 +1,44 @@ from dingtalkchatbot.chatbot import DingtalkChatbot -from slack_bolt.async_app import AsyncApp -from slack_bolt.authorization import AuthorizeResult -from slack_sdk.web.async_client import AsyncWebClient +from slack_bolt import App import os import logging logging.basicConfig(level=logging.DEBUG) -# Import the async app instead of the regular one - - -async def authorize(enterprise_id, team_id, user_id, client: AsyncWebClient, logger): - logger.info(f"{enterprise_id},{team_id},{user_id}") - # You can implement your own logic here - token = os.environ["SLACK_BOT_TOKEN"] - return AuthorizeResult.from_auth_test_response( - auth_test_response=await client.auth_test(token=token), - bot_token=token, - ) # WebHook地址 dingtalk_webhook = os.environ["DINGTALK_WEBHOOK"] dingtalkbot = DingtalkChatbot(dingtalk_webhook) -app = AsyncApp( - signing_secret=os.environ["SLACK_SIGNING_SECRET"], authorize=authorize) +app = App( + token=os.environ.get("SLACK_BOT_TOKEN"), + signing_secret=os.environ.get("SLACK_SIGNING_SECRET") +) @app.event("app_mention") -async def event_test(body, say, logger): +def event_test(body, say, logger): logger.info(body) await say("What's up?") @app.command("/hello-bolt-python") -async def command(ack, body, respond): +def command(ack, body, respond): await ack() await respond(f"Hi <@{body['user_id']}>!") @app.message("Heads Up!*") -async def redirect(body, logger): +def redirect(body, logger): logger.info(body) + dingtalkbot.send_text(body) @app.message("") -async def logall(body, logger): +def logall(body, logger): logger.debug(body) dingtalkbot.send_text(body) # 启动slack监听 if __name__ == "__main__": - app.start(3000) + app.start(os.environ.get("PORT", 3000)) diff --git a/example.env b/example.env index 1c70011..6b7a9fc 100644 --- a/example.env +++ b/example.env @@ -2,3 +2,5 @@ export SLACK_SIGNING_SECRET=*** export SLACK_BOT_TOKEN=xoxb-*** export DINGTALK_WEBHOOK='https://oapi.dingtalk.com/robot/send?access_token=这里填写自己钉钉群自定义机器人的token' + +export PORT=3000